All practice tasks

Coding (Algo)

Balanced Delimiters

Stack · Easy

A small editor checks bracket structure before offering an expression preview. Input contains only delimiters, not JavaScript source.

Return whether (), [] and {} are correctly paired and nested.

Input

Call

  • Implement solve(input) and return its result. Do not print from solve.

Input object

{ text: string }. text contains only the six bracket characters

What each field means

  • text — a string containing only (, ), [, ], { and }.

Output

Return value and rules

  • Return true only if every opening bracket has the correct closing bracket and nesting order.
  • Return false for an unmatched bracket or incorrect nesting.
  • The empty string returns true.

Constraints

  • 0 <= text.length <= 100000
  • Do not parse quotes, comments or HTML; those are outside this contract.

Examples

Example 1

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

Returns

true

Example 2

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

Returns

false

Required complexity

O(n) time and O(n) space

What this task practices

Balanced Delimiters 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.