I am not able to understand how to do this problem. Hints/solution would be appreciated. The problem has a tag of stack if it helps.
Geek wants to send an encrypted message in the form of string S to his friend Keeg along with instructions on how to decipher the message. To decipher the message, his friend needs to iterate over the message string from left to right, if he finds a ‘*’, he must remove it and add all the letters read so far to the string. He must keep on doing this till he gets rid of all the ‘*’.
Can you help Geek encrypt his message string S?
Note: If the string can be encrypted in multiple ways, find the smallest encrypted string.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
1 ≤ |S| ≤ 10^5
Input : mnmmnmnmmnmnmmnmnmmnmnm
Input : hxhxhxhxhxhxhxhxhxhxhxhxhxhxhxhx