PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Bloomberg

Validate whether brackets are properly nested

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in sequence validation, paired-token matching, and the use of data structures to manage nested elements within strings.

  • medium
  • Bloomberg
  • Coding & Algorithms
  • Software Engineer

Validate whether brackets are properly nested

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem: Validate a bracket sequence Given a string `s` consisting only of the characters `'('`, `')'`, `'{'`, `'}'`, `'['`, `']'`, determine whether the string is **valid**. A string is valid if: - Every opening bracket has a corresponding closing bracket of the **same type**. - Brackets are closed in the **correct order** (properly nested). - An empty string is considered valid. ### Input - A string `s` (length `0..10^5`) containing only the six bracket characters. ### Output - Return `true` if `s` is valid, otherwise return `false`. ### Examples - `s = "()"` → `true` - `s = "()[]{}"` → `true` - `s = "(]"` → `false` - `s = "([)]"` → `false` - `s = "{[]}"` → `true` ### Follow-up discussion prompts (as in interview) - What is the time and space complexity? - Can you optimize for space or early termination? - What edge cases would you test?

Quick Answer: This question evaluates proficiency in sequence validation, paired-token matching, and the use of data structures to manage nested elements within strings.

Related Interview Questions

  • Solve meeting and tree problems - Bloomberg (easy)
  • Minimize travel cost with two cities - Bloomberg (easy)
  • Check connectivity between two subway stations - Bloomberg (easy)
  • Design a data structure for dynamic top‑K frequency - Bloomberg (hard)
  • Find tree root and bucket numbers - Bloomberg (hard)
Bloomberg logo
Bloomberg
Jan 6, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
8
0
Loading...

Problem: Validate a bracket sequence

Given a string s consisting only of the characters '(', ')', '{', '}', '[', ']', determine whether the string is valid.

A string is valid if:

  • Every opening bracket has a corresponding closing bracket of the same type .
  • Brackets are closed in the correct order (properly nested).
  • An empty string is considered valid.

Input

  • A string s (length 0..10^5 ) containing only the six bracket characters.

Output

  • Return true if s is valid, otherwise return false .

Examples

  • s = "()" → true
  • s = "()[]{}" → true
  • s = "(]" → false
  • s = "([)]" → false
  • s = "{[]}" → true

Follow-up discussion prompts (as in interview)

  • What is the time and space complexity?
  • Can you optimize for space or early termination?
  • What edge cases would you test?

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Bloomberg•More Software Engineer•Bloomberg Software Engineer•Bloomberg Coding & Algorithms•Software Engineer Coding & Algorithms
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.