Back to problems

Validate Properly Nested Brackets

Algorithm · Amazon · Medium

Given a string s made up of only '(', ')', '{', '}', '[', and ']', determine whether the bracket sequence is valid. A sequence is valid when: every opening bracket is eventually closed by a bracket of the same type; brackets close in reverse order from how they were opened, so the most recently opened unmatched bracket must close first; the empty string is considered valid. Example 1: Explanation: The closers appear in the order }, ), ], which reverses the opener order [, (,…

Checking your access…