Grokking Data Structures & Algorithms for Coding Interviews
0% completed
Solution: Minimum Add to Make Parentheses Valid
.....
.....
.....
Like the course? Get enrolled and start learning!
A
Anonymous
· 2 years ago
I am not completely sure how this problem employs a greedy strategy, but here is my understanding. As soon as the number of closed brackets exceeds the number of open brackets, we plan to handle it. Even if there is only one mismatch, we increase the counter and reduce the balance. This approach works for this problem because traversing from the beginning ensures we have all the information about the preceding brackets, which is sufficient to obtain the solution at the current position.
Let me know if I am thinking wrong here. Thanks!
Show 1 reply
Reading Progress
0%