Find the Bracket Error
Medium · Parsing
Write a function firstBracketError that checks the brackets (), [] and {} in a string and tells where the first problem is. All other characters are ignored.
- If all brackets are correctly matched and nested, return -1.
- If a closing bracket does not match the most recent unclosed opening bracket (or there is none), return the index of that closing bracket.
- If the string ends while some opening brackets are still unclosed, return the index of the earliest unclosed opening bracket.
Next: Valid Sudoku Board