0% completed
regarding this line of code "if i1 < 0 and i2 < 0: # reached the end of both th...
Lemon Ruan
Jul 14, 2022
regarding this line of code "if i1 < 0 and i2 < 0: # reached the end of both the strings return True" why is the condition i1
0
0
Comments
Lemon Ruan3 years ago
what is the reason behind the condition and can we do if i1
gorgeous 3 years ago
Wouldnt using a stack and popping off the top element as and when a backspace is encountered and then checking stack contents be easier, though it consumes extra space
Belal Mohammed3 years ago
I don't think a stack would work as you might have # within the string not only by the end of it
Belal Mohammed3 years ago
After thinking for a while for what you said, I found it can actually be easily achievable by a stack. That's true
Shubham Voraa year ago
The condition i1 < 0 && i2 < 0 in the code checks if both pointers have reached the end of their respective strings. This indicates that both strings have been fully processed and are equal after accounting for backspaces.
Here’s why this condition is important:
...
On this page