PracHub
QuestionsPremiumLearningGuidesInterview PrepCoaches

Quick Overview

This two-part question evaluates proficiency with core data structures and string/array algorithms—specifically stack-based delimiter matching and cumulative character shifting using modular arithmetic—and is commonly asked to assess correctness under ordering constraints, boundary handling, and efficiency.

  • medium
  • Bytedance
  • Coding & Algorithms
  • Site Reliability Engineer

Solve Stack and String Shift Problems

Company: Bytedance

Role: Site Reliability Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are asked to solve two independent coding problems. ### Problem 1: Validate Delimiter Pairs Given a string `s` containing only the characters `(`, `)`, `{`, `}`, `[` and `]`, determine whether the string is valid. A string is valid if: 1. Every opening bracket is closed by the same type of bracket. 2. Brackets are closed in the correct order. 3. Every closing bracket has a corresponding unmatched opening bracket before it. Return `true` if `s` is valid, otherwise return `false`. **Examples:** - Input: `s = "()[]{}"` → Output: `true` - Input: `s = "(]"` → Output: `false` - Input: `s = "([{}])"` → Output: `true` ### Problem 2: Apply Cumulative Letter Shifts You are given a lowercase English string `s` and an integer array `shifts` of the same length. For each index `i`, shift the first `i + 1` characters of `s` forward in the alphabet by `shifts[i]` positions. Shifts wrap around, so shifting `'z'` forward by one becomes `'a'`. Return the final string after applying all shifts. **Example:** - Input: `s = "abc"`, `shifts = [3, 5, 9]` - Explanation: - Shift first 1 character by 3: `"dbc"` - Shift first 2 characters by 5: `"igc"` - Shift first 3 characters by 9: `"rpl"` - Output: `"rpl"` Design efficient solutions and be prepared to run them against test cases during the interview.

Quick Answer: This two-part question evaluates proficiency with core data structures and string/array algorithms—specifically stack-based delimiter matching and cumulative character shifting using modular arithmetic—and is commonly asked to assess correctness under ordering constraints, boundary handling, and efficiency.

Part 1: Validate Delimiter Pairs

Given a string `s` containing only the characters `(`, `)`, `{`, `}`, `[` and `]`, determine whether the string is valid. A string is valid if: 1. Every opening bracket is closed by the same type of bracket. 2. Brackets are closed in the correct order. 3. Every closing bracket has a corresponding unmatched opening bracket before it. Return `True` if the string is valid, otherwise return `False`.

Constraints

  • 0 <= len(s) <= 100000
  • s contains only the characters '(', ')', '{', '}', '[' and ']'
  • An empty string is considered valid

Examples

Input: "()[]{}"

Expected Output: True

Explanation: Each bracket is correctly matched and closed in order.

Input: "(]"

Expected Output: False

Explanation: The closing bracket ']' does not match the opening bracket '('.

Input: "([{}])"

Expected Output: True

Explanation: Nested brackets are all matched in the correct order.

Input: ""

Expected Output: True

Explanation: Edge case: an empty string has no mismatched brackets.

Input: "]"

Expected Output: False

Explanation: Edge case: a closing bracket appears before any opening bracket.

Hints

  1. Use a stack to keep track of opening brackets you have not matched yet.
  2. When you see a closing bracket, it must match the most recent unmatched opening bracket.

Part 2: Apply Cumulative Letter Shifts

You are given a lowercase English string `s` and an integer array `shifts` of the same length. For each index `i`, shift the first `i + 1` characters of `s` forward in the alphabet by `shifts[i]` positions. Shifts wrap around, so shifting `'z'` forward by one becomes `'a'`. Return the final string after applying all shifts. An efficient solution is expected.

Constraints

  • 0 <= len(s) <= 200000
  • len(shifts) == len(s)
  • s contains only lowercase English letters
  • 0 <= shifts[i] <= 1000000000

Examples

Input: ("abc", [3, 5, 9])

Expected Output: "rpl"

Explanation: This is the example case. The cumulative effect on the characters produces 'rpl'.

Input: ("z", [1])

Expected Output: "a"

Explanation: Edge case: shifting 'z' by 1 wraps around to 'a'.

Input: ("abc", [0, 0, 0])

Expected Output: "abc"

Explanation: No shifts are applied, so the string stays the same.

Input: ("", [])

Expected Output: ""

Explanation: Edge case: empty input produces an empty output.

Input: ("aaa", [1, 2, 3])

Expected Output: "gfd"

Explanation: The total shifts received by positions 0, 1, and 2 are 6, 5, and 3 respectively.

Hints

  1. A shift at index `i` affects every character from `0` to `i`, so think about how many total shifts each character receives.
  2. Process from right to left and keep a running suffix sum modulo 26.
Last updated: May 30, 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

  • Find LCA With Parent Pointers - Bytedance (medium)
  • Count Target-Sum Paths in an N-ary Tree - Bytedance (hard)
  • Minimize Increments to Equalize Path Costs - Bytedance (medium)
  • Implement Sorted Search and Array Updates - Bytedance (medium)
  • Find Maximum Candies With Two Types - Bytedance (medium)