PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Bytedance

Compute Minimum Parentheses Additions

Last updated: May 3, 2026

Quick Overview

This question evaluates proficiency in string processing and algorithmic reasoning for balancing parentheses, testing understanding of invariants and edge-case handling.

  • medium
  • Bytedance
  • Coding & Algorithms
  • Data Scientist

Compute Minimum Parentheses Additions

Company: Bytedance

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given a string `s` consisting only of the characters `'('` and `')'`, compute the minimum number of parentheses that must be inserted anywhere in the string so that the resulting string is a valid parentheses string. A valid parentheses string is one where every opening parenthesis has a matching closing parenthesis, every closing parenthesis matches a previous unmatched opening parenthesis, and the pairs are properly nested. Return a single integer: the minimum number of insertions required. Example: ```text Input: s = "()))((" Output: 4 ``` Explain your approach and analyze its time and space complexity.

Quick Answer: This question evaluates proficiency in string processing and algorithmic reasoning for balancing parentheses, testing understanding of invariants and edge-case handling.

Related Interview Questions

  • Minimize Increments to Equalize Path Costs - Bytedance (medium)
  • Implement Sorted Search and Array Updates - Bytedance (medium)
  • Find Maximum Candies With Two Types - Bytedance (medium)
  • Place Non-Attacking Queens - Bytedance (hard)
  • Solve String Addition and Expression Evaluation - Bytedance (medium)
Bytedance logo
Bytedance
Apr 19, 2026, 12:00 AM
Data Scientist
Technical Screen
Coding & Algorithms
1
0

Given a string s consisting only of the characters '(' and ')', compute the minimum number of parentheses that must be inserted anywhere in the string so that the resulting string is a valid parentheses string.

A valid parentheses string is one where every opening parenthesis has a matching closing parenthesis, every closing parenthesis matches a previous unmatched opening parenthesis, and the pairs are properly nested.

Return a single integer: the minimum number of insertions required.

Example:

Input: s = "()))(("
Output: 4

Explain your approach and analyze its time and space complexity.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Bytedance•More Data Scientist•Bytedance Data Scientist•Bytedance Coding & Algorithms•Data Scientist 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.