interviewmind

Practice room

Call time 00:00Get the app
D
Dana · Interviewer
You
You
Captions

Press Play and Dana asks the question out loud.

Questions6/17

CodingEasy

Valid Parentheses

You’re given a string s that holds only the characters (, ), [, ], { and }. Return true if its brackets are balanced, and false otherwise.

Balanced means every opening bracket is closed by one of the same kind, brackets close in the reverse of the order they opened, and no closing bracket shows up without an open one to match.

Example 1

Inputs = "()[]{}"Outputtrue

Example 2

Inputs = "([{}])"Outputtrue

Each bracket closes after everything opened inside it.

Example 3

Inputs = "(]"Outputfalse

A round bracket can’t be closed by a square one.

Example 4

Inputs = "([)]"Outputfalse

The square bracket opened last, so it has to close before the round one.

Constraints

  • 1 ≤ s.length ≤ 10⁴
  • s holds only the characters ()[]{}

Tab indents. Press Escape, then Tab, to move focus out of the editor.

TypeScriptLn 1, Col 1
Practice room — InterviewMind