Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

s =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Use a stack to ensure brackets close in the correct order.

Approach

Push opening brackets. For a closing bracket, check the top of the stack matches the corresponding opener; otherwise invalid.

Why it works

The most recent unmatched opening bracket must be closed first (LIFO).

Code
Loading...
Complexity
Time: O(n)
Space: O(n)
Solution
Updated: 2026-02-23

Idea

Use a stack to ensure brackets close in the correct order.

Approach

Push opening brackets. For a closing bracket, check the top of the stack matches the corresponding opener; otherwise invalid.

Why it works

The most recent unmatched opening bracket must be closed first (LIFO).

Code
Loading...
Complexity
Time: O(n)
Space: O(n)