Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
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
Comments
L
Lemon Ruan3 years ago

what is the reason behind the condition and can we do if i1

G
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

B
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

B
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 Vora
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