Grokking the Coding Interview: Patterns for Coding Questions
Vote

0% completed

​

Solution: Problem Challenge 2: Comparing Strings containing Backspaces

.....

.....

.....

Like the course? Get enrolled and start learning!
A

Anonymous

· 3 years ago

I'm confused by the last result , the input is "#a#c" "abc###" and the expected is True. Wouldn't they reduce to "c" and "" , which are not equal?

Show 3 replies
A

Anonymous

· 3 years ago

class Solution: def ApplyBackspaces(self, string): stack = [] for c in string: if c == '#': if len(stack) > 0: stack.pop() else: stack.append(c) return ''.join(stack) def compare(self, string1, string2): return self.ApplyBackspaces(string1) == self.ApplyBackspaces(string2)
A

Anonymous

· 4 years ago

Couldn't this be done in O(N) where N is the length of the bigger string?

Show 1 reply
A

Anonymous

· 4 years ago

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

Show 5 replies

Reading Progress

0%


Vote for new content