Skip to interview prep
Apexed

7. Valid Parentheses

EasyStack

Given a string containing only ()[]{}, return true if every opening bracket is closed by the same type of bracket in the correct order.

Example 1

Input: s = "()[]{}"
Output: true

Example 2

Input: s = "(]"
Output: false

Example 3

Input: s = "([)]"
Output: false

Constraints

  • 1 ≤ s.length ≤ 10⁴

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 6 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Valid Parentheses — coding interview practice — Apexed