I have been asked the BracketValidator interview question twice now; It’s comparatively easy to formulate a Python/Java solution using the fancy data structures and built-in methods that Python/Java offers. So, I tried my hand solving this using Objective-C.
TL;DR: Solution can be found here.
Problem:
In short, given a string containing brackets and parenthesis, every bracket opened i.e. ‘{‘, ‘(‘, ‘[‘ should have a corresponding closing bracket i.e. ‘}’, ‘)’, ‘]’. Note, the position of the closing bracket is important.
The following string will be valid:
{([()])}
But, the following won’t be correct:
{[}]
A more apt description of the BracketValidator can be found here.