1. Every inner brace should increase one indentation to the following lines.
2. Every close brace should decrease one indentation to the same line and the following lines.
3. Every ‘,’ will mean a separate line.
4. The indents can be increased with an additional 4 spaces or ‘/t’.
Let the input be: "{A:"B",C:{D:"E",F:{G:"H",I:"J"}}}"
Then we return the following array of strings:
{
A:"B",
C:
{
D:"E",
F:
{
G:"H",
I:"J"
}
}
}
Note that for every new brace we are putting an additional 4 spaces or \t.
1. [] and {} are only acceptable braces in this case.
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test cases follow.
The first line of each test case contains the string ‘STR’.
For each test case, return an array of strings containing the indented JSON file.
Output for each test case will be printed in a new line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N <= 2*10^3
Where 'N' denotes the length of the string.
Time limit: 1 sec
The key idea in solving this problem is to simply iterate through the given string and construct our array of strings. We need to take care of the following points:
Below is the detailed algorithm:
Do check your code for the following corner cases:
Divisible Substrings
Ninja and Numbers
Longest Palindromic Substring
Cakes
1-3 Palindrome