Bracket substrings matching any pattern | Uber Interview Question