PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/LinkedIn

Validate parentheses with one or three bracket types

Last updated: Jun 21, 2026

Quick Overview

This question evaluates understanding of string parsing and abstract data structures—particularly stack behavior—and the ability to reason about matching and nesting of brackets within the Coding & Algorithms domain.

  • medium
  • LinkedIn
  • Coding & Algorithms
  • Software Engineer

Validate parentheses with one or three bracket types

Company: LinkedIn

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem Given a string `s` consisting only of bracket characters, determine whether it 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. ### Part A (initial version) `s` contains only `'('` and `')'`. ### Part B (follow-up) `s` may contain three types of brackets: `'()'`, `'[]'`, `'{}'`. ## Input / Output - **Input:** `s` (string) - **Output:** `true` if `s` is valid, otherwise `false` ## Constraints (typical) - `0 <= |s| <= 2 * 10^5` ## Examples - `s = "()"` → `true` - `s = "(()"` → `false` - `s = "([{}])"` → `true` - `s = "([)]"` → `false` ## Discussion prompts - Compare using a **stack** vs using a **counter** (for Part A only). When is a counter sufficient, and why does it fail for Part B?

Quick Answer: This question evaluates understanding of string parsing and abstract data structures—particularly stack behavior—and the ability to reason about matching and nesting of brackets within the Coding & Algorithms domain.

Related Interview Questions

  • Count Trips From Vehicle Logs - LinkedIn (easy)
  • Design O(1) Randomized Multiset - LinkedIn (easy)
  • Process Mutable Matrix Sum Queries - LinkedIn (medium)
  • Design a Randomized Multiset - LinkedIn (medium)
  • Can You Place N Objects? - LinkedIn (medium)
LinkedIn logo
LinkedIn
Oct 20, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0
Practice Read

Problem

Given a string s consisting only of bracket characters, determine whether it 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.

Part A (initial version)

s contains only '(' and ')'.

Part B (follow-up)

s may contain three types of brackets: '()', '[]', '{}'.

Input / Output

  • Input: s (string)
  • Output: true if s is valid, otherwise false

Constraints (typical)

  • 0 <= |s| <= 2 * 10^5

Examples

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

Discussion prompts

  • Compare using a stack vs using a counter (for Part A only). When is a counter sufficient, and why does it fail for Part B?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

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