Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Stacks & queues

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Stacks & queues

Valid Parentheses

beginnerlayer B8 · Stacks & queues5 tests

A string made only of (), [] and {} is balanced when every opening bracket is closed by the matching kind, in the right order. Write isValid(s).

  • Brackets may nest, e.g. {[()]} is balanced
  • They may not cross, e.g. ([)] is not
  • A closing bracket with nothing open, or an opening bracket never closed, both fail
  • The empty string is balanced

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen