
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.


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

Top DE Shaw Technology Developer interview questions & answers
Reviews
Interviews
Salaries
Users/Month