Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Scan characters left to right and use a stack for opening brackets. For each closing bracket, pop from the stack and verify the pair matches. At the end, the stack must be empty for the string to be valid.
The most recent unmatched opening bracket must be matched first, which is exactly LIFO order. Any mismatch or leftover opening bracket means invalid nesting.
Updated Feb 2026