Your question is Validating Brackets with Stack. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Micro1's assessment platform receives bracket sequences that must be checked before further parsing. Given a string containing only (, ), {, }, [, and ], determine whether the sequence is valid using a stack.
A string is valid when every opening bracket is closed by the matching bracket type, brackets close in the correct last-in, first-out order, and no closing bracket appears without a corresponding opening bracket.
Implement is_valid(s), where s is a string. Return True if the bracket sequence is valid, otherwise return False.
The empty string is considered valid.
def is_valid(s):