Skip to content

Resource · Guide or article

Valid Parentheses Problem

Explains the bracket-matching problem for strings made of (), {} and [], and calls it a common interview question that shows how a stack solves matching problems.

Reviewed

Open the original: Valid Parentheses Problem (opens the original site in a new tab)

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Every close bracket has a corresponding open bracket of the same type. This is actually a very common interview question and a very good example of how to use a stack data structure to solve problems.

PrepKit overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Lesson

What it covers

  • States the three validity rules and gives three input and output examples
  • Describes a brute-force removal approach and gives it O(n^2) time
  • Walks through the stack approach using a hash table of opening to closing brackets, with O(n) time and space
  • Points out the final empty-stack check

How to use it

PrepKit study advice, not a claim made by the source.

Code the stack version without looking, then test it on the README's three examples plus an input that is only opening brackets. You should be able to say why the empty-stack check is needed.

Scope and limitations

Prose only on this page, with no code listing or extra practice inputs. The single reference is the LeetCode problem page.

Access and format

README on GitHub in the MIT-licensed trekhleb/javascript-algorithms repository. English, free to read.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/algorithms/stack/valid-parentheses/README.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email