Pretty JSON Formatting Problem

You're provided with a string 'STR' that represents a JSON object. Your task is to return an array of strings representing JSON objects, formatted with proper indentation based on specific rules.

Rules for Proper Indentation:

1. Each inner opening brace increases the indentation on the following lines by one level. 2. Each closing brace decreases the indentation on the same and following lines by one level. 3. Each comma represents a new line. 4. Indentation can be represented as four spaces or a tab ('\t').

Input:

T (integer denoting number of test cases)
STR (string representing JSON object for each test case)

Output:

An array of strings for each test case, containing the indented JSON object.

Example:

Input:
{A:"B",C:{D:"E",F:{G:"H",I:"J"}}}
Output:
{
    A:"B",
    C:
    {
        D:"E",
        F:
        {
            G:"H",
            I:"J"
        }
    }
}
Explanation:

The output demonstrates the use of indents where every new brace adds an additional four spaces, creating a structured format.

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 2*10^3

Where 'N' is the length of the string. Assume a time limit of 1 second.

Note:

Ensure you only handle the acceptable braces {'{', '}'} and ['[', ']'] in this formatting context. No need to print anything as handling output is already managed.

AnswerBot
4mo

The task is to format a JSON object string with proper indentation based on specific rules.

  • Iterate through the string character by character and keep track of the indentation level.

  • Use a stack to keep...read more

Help your peers!
Select
Add answer anonymously...

DE Shaw Technology Developer interview questions & answers

A Technology Developer was asked Q. Pretty JSON Formatting Problem You're provided with a string 'STR' that represen...read more
A Technology Developer was asked Q. Minimum Sum in Matrix Problem Statement You are given a 2D matrix 'ARR' of size ...read more
A Technology Developer was asked Q. Buy and Sell Stock Problem Statement Imagine you are Harshad Mehta's friend, and...read more

Popular interview questions of Technology Developer

A Technology Developer was asked Q1. Pretty JSON Formatting Problem You're provided with a string 'STR' that represen...read more
A Technology Developer was asked Q2. Minimum Sum in Matrix Problem Statement You are given a 2D matrix 'ARR' of size ...read more
A Technology Developer was asked Q3. Buy and Sell Stock Problem Statement Imagine you are Harshad Mehta's friend, and...read more
DE Shaw Technology Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits