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.
Be the first one to answer
Add answer anonymously...
Top DE Shaw Technology Developer interview questions & answers
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app