PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of bracket matching and string parsing, testing competency with basic data structures and algorithmic reasoning such as stack-based matching and correct handling of nested delimiters.

  • easy
  • Intuit
  • Coding & Algorithms
  • Software Engineer

Validate bracket sequence

Company: Intuit

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

Given a string `s` containing only the characters `(`, `)`, `[`, `]`, `{`, and `}`, determine whether the brackets are properly matched. A string is valid if: - Every opening bracket is closed by a bracket of the same type. - Brackets are closed in the correct order. - No closing bracket appears without a matching earlier opening bracket. Return `true` if the string is valid and `false` otherwise. Example 1: - Input: `s = "()[]{}"` - Output: `true` Example 2: - Input: `s = "([)]"` - Output: `false` Example 3: - Input: `s = "{[]}"` - Output: `true` Be prepared to write and run a few test cases, including edge cases such as the empty string.

Quick Answer: This question evaluates understanding of bracket matching and string parsing, testing competency with basic data structures and algorithmic reasoning such as stack-based matching and correct handling of nested delimiters.

Given a string `s` containing only the characters `(`, `)`, `[`, `]`, `{`, and `}`, determine whether the bracket sequence is valid. A string is valid if: - Every opening bracket is closed by a bracket of the same type. - Brackets are closed in the correct order. - No closing bracket appears without a matching earlier opening bracket. Return `True` if the string is valid and `False` otherwise.

Constraints

  • 0 <= len(s) <= 100000
  • s contains only the characters '(', ')', '[', ']', '{', and '}'

Examples

Input: "()[]{}"

Expected Output: True

Explanation: Each bracket is properly opened and closed in the correct order.

Input: "([)]"

Expected Output: False

Explanation: The ')' tries to close '(' while '[' is still open, so the order is invalid.

Input: "{[]}"

Expected Output: True

Explanation: The nested brackets are correctly matched: '[' closes before '{' closes.

Input: ""

Expected Output: True

Explanation: An empty string has no unmatched brackets, so it is valid.

Input: "]"

Expected Output: False

Explanation: A closing bracket appears without any earlier matching opening bracket.

Input: "((("

Expected Output: False

Explanation: There are opening brackets left unmatched at the end of the string.

Hints

  1. Use a stack to keep track of opening brackets as you scan the string from left to right.
  2. When you see a closing bracket, it must match the most recent unmatched opening bracket.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Add One to Digit Array - Intuit (easy)
  • Find Business Degrees of Separation - Intuit (hard)
  • Produce valid student lineup from parent array - Intuit (medium)
  • Find largest filename from ls -l output - Intuit (medium)
  • Sum palindrome-change costs over all substrings - Intuit (medium)