Idea
- The idea here is to maintain 2 Stack, one for lowercase, one for uppercase. The stack keeps track the index of the elements that aren’t
b
orB
- When we see a
b
orB
, we just delete the first element from the corresponding stack by replacing the element at that index with eitherb
orB
- Then we loop the original string, add characters that aren’t
b
andB
to form a new string which is the final answer
Space & Time Analysis
The analysis method we are using is Algorithm Complexity Analysis
Space - O(n)
- Ignore input size & language dependent space
- We are maintaining 2 Stack
Time - O(n)
- One loop to serialise the given string
- One loop to form the final answer string
Codes
1st Attempt (Java)
Personal Reflection
- Why it takes so long to solve: NIL
- What you could have done better: NIL
- What you missed: NIL
- Ideas you’ve seen before: Stack, last in first out property
- Ideas you found here that could help you later: Understand the properties of Data Structure well
- Ideas that didn’t work and why: NIL