Question bank › Stack
Dsa Stack Hard

Bracket Validator with Minimum Modifications

You are given a string containing various types of brackets: '(', ')', '{', '}', '[' and ']'. Your task is to determine the minimum number of bracket modifications required to make the string valid. A valid string has matching brackets that are properly nested. For example, '([]{})' is valid while '([)' is not. You can either add a bracket or remove one to achieve a valid string. Please write a program that takes a string of brackets as input and outputs the minimum number of modifications needed. Input Format: A single line of text containing brackets. Output Format: An integer representing the minimum number of modifications required. Example: Input: {[()]} Output: 0

Key concepts

stackbracketsmodification

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.