![]() |
VOOZH | about |
Given a string S containing letters and '#'. The '#" represents a backspace. The task is to print the new string without '#'.
Examples:
Input : S = "abc#de#f#ghi#jklmn#op#" Output : abdghjklmo Input : S = "##geeks##for##geeks#" Output : geefgeek
Approach: A simple approach to this problem by using deque is as follows:
- Traverse the string S.
- If any character except '#' is found push it at back in deque.
- if the character '#' is found pop a character from back of deque.
- Finally pop all elements from front of deque to make new string.
Below is the implementation of above approach:
geefgeek
Complexity Analysis: