PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question evaluates a candidate's competency in string processing and bracket-matching concepts, testing familiarity with linear-time algorithms and simple data structures for recognizing correct nesting and matching of parentheses, brackets, and braces.

  • medium
  • Walmart Labs
  • Coding & Algorithms
  • Software Engineer

Check whether brackets are balanced

Company: Walmart Labs

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem Given a string `s` that may contain bracket characters, determine whether the brackets are **properly balanced**. Treat the following as brackets: - Parentheses: `(` and `)` - Square brackets: `[` and `]` - Curly braces: `{` and `}` All other characters (letters, digits, spaces, punctuation) should be ignored. A string is balanced if: 1. Every opening bracket is closed by the **same type** of bracket. 2. Brackets are closed in the **correct order** (proper nesting). ## Input/Output - **Input:** string `s` - **Output:** boolean `true` if balanced, otherwise `false` ## Examples - `"(a[b]{c})"` → `true` - `"([)]"` → `false` - `"(("` → `false` - `""` → `true` ## Constraints (assume) - `0 ≤ len(s) ≤ 2 * 10^5`

Quick Answer: This question evaluates a candidate's competency in string processing and bracket-matching concepts, testing familiarity with linear-time algorithms and simple data structures for recognizing correct nesting and matching of parentheses, brackets, and braces.

Given a string `s`, determine whether its bracket characters are properly balanced. Consider only these bracket types: parentheses `()` , square brackets `[]` , and curly braces `{}`. Ignore all other characters such as letters, digits, spaces, and punctuation. A string is balanced if every opening bracket is closed by the same type of bracket and brackets are closed in the correct order.

Constraints

  • 0 <= len(s) <= 2 * 10^5
  • The string may contain any characters
  • Only the characters (), [], and {} are treated as brackets

Examples

Input: "(a[b]{c})"

Expected Output: True

Explanation: Ignoring letters, the bracket sequence is properly nested: ( [ ] { } ).

Input: "([)]"

Expected Output: False

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

Input: "(("

Expected Output: False

Explanation: There are opening parentheses left unmatched at the end.

Input: ""

Expected Output: True

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

Input: "abc123"

Expected Output: True

Explanation: There are no bracket characters, so nothing is unbalanced.

Input: "{[()]}!"

Expected Output: True

Explanation: The exclamation mark is ignored, and the brackets are correctly nested.

Input: "]"

Expected Output: False

Explanation: A closing bracket appears before any matching opening bracket.

Hints

  1. A stack is useful for tracking the most recent unmatched opening bracket.
  2. When you see a closing bracket, it must match the latest opening bracket that has not been closed yet.
Last updated: May 12, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ 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

  • Implement lexicographically smallest Two Sum - Walmart Labs (medium)
  • Compute days until plants stop dying - Walmart Labs (medium)
  • Count ways to make change (DP) - Walmart Labs (medium)
  • Find shared courses between student pairs - Walmart Labs (medium)
  • Merge two sorted arrays in-place - Walmart Labs (easy)