Valid Parentheses

Easy · Stack & Strings · String · Stack

Problem

Given a string s containing only the characters ()[]{}, decide whether the brackets are balanced.

A string is valid when every opening bracket is closed by the same type of bracket, and brackets close in the right order — so ([)] is invalid even though the counts match.

Examples

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

Correct counts, wrong nesting order.

Input: s = "{[]}"
Output: True

Properly nested.

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…