Jobs
Interviews

Solve Format Nested Braces using Python Language

Solve Format Nested Braces using Python to enhance your skills with python coding practice , master coding concepts, and prepare for interviews with practical exercises and detailed solutions.

Format Nested Braces

Difficulty : Easy

Categories :

  • Strings

Given a string s representing a JSON-like nested structure using only curly braces {}, create the minimal formatted version of the string with proper indentation. Rules:

  • Use 2 spaces for each level of indentation
  • Opening brace { should be on the same line as the previous content
  • Closing brace } should be on its own line at the appropriate indentation level
  • Empty {} should be on a single line with no spaces between braces

Constraints:

  • 1 ≤ s.length ≤ 10^4
  • s consists of curly braces {} only
  • s is a valid nested structure

Examples:

Input: s = "{{}{}}"
Output: "{
  {}
  {}
}"
Explanation: Each nested structure is indented with 2 spaces
Input: s = "{{{}}}"
Output: "{
  {
    {}
  }
}"
Explanation: Three levels of nesting with proper indentation

Coding works best on a laptop or desktop, with a keyboard and a wider editor. You can read the problem here and solve it there.

Problem Solving

Input

What You'll Find Here

Interactive Exercises Practice coding with problems designed for beginners and experts.

Step-by-Step Solutions Understand every step of the solution process.

Real-World Scenarios Apply your skills to real-world problems and boost your confidence.

Choose from the following categories