All practice tasks

Coding (Algo)

Validate Nested Brackets

Stack · Easy

An expression editor checks delimiter structure before enabling a preview. The caller has already removed all non-bracket text. Your function only checks pairing and nesting; it does not evaluate an expression.

Return whether every opening bracket has a closing bracket of the same type in the correct nested order.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

A JSON object { "s": string }.

Fields

  • s contains only (, ), [, ], { and }.

Output

Return value

  • Return true or false.
  • Closing a different type or closing before an opener is invalid.
  • All openers must be closed when the input ends. The empty string is valid.

Constraints

  • 0 <= s.length <= 100000.
  • Quotes, escaping, comments and expression syntax are not part of the input.

Examples

Example 1

{
  "s": "([]){}"
}

Returns

true

Nested and adjacent pairs are allowed.

Example 2

{
  "s": "([)]"
}

Returns

false

Equal counts do not make crossing pairs valid.

Required complexity

O(n) time and O(n) extra space

What this task practices

Validate Nested Brackets is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.