BugForge
DSA

Validate Template Brackets

Easystack 00:00

A template string contains only ()[]{}. Return true if every bracket is closed by the same type in the correct order.

Signature

isValid(s: string) → bool
Example 1
s = "()[]{}"
output = true
Example 2
s = "([)]"
output = false
closes in the wrong order
Example 3
s = "{[]}"
output = true

Constraints

  • 1 ≤ |s| ≤ 10^4
Run checks the examples. Submit runs every hidden test (17, including large inputs that catch slow solutions).