DEV Community

Paolo Ventura
Paolo Ventura

Posted on

100 algos in 100 days (Day 28)

Question

Parenthesis Matching

e.g. given the string:
"Sometimes (when I nest them (my parentheticals) too much (like this (and this))) they get confusing."

given an index of an opening bracket:
e.g. 10

Find the closing bracket.

I quite the method I used to solve this. I started visualizing a very simple example.
(...) - Just the last one
()() - Find first closing
(()) - If there is another opening bracket, ignore the first closing bracket.

This was similar to TDD but just doing it in with examples and coming to a potential algorithm quite quickly.

Top comments (0)