Challenge
Your challenge is simple, calculate the depth of each matching brackets in the given input e.g. (()()(()))
->[[1,1,[1]]]
, and output it in the form of a list/array/string representation
Explanation:
For every bracket in the input, you have to count how many nested brackets there are for that part of the input e.g. ()
has 1 depth
Although if find a bracket of depth 2 e.g. (())
, a list []
is formed from the 1st bracket ( )
has to be added to the output with the 2nd bracket, ()
of depth 1 inside that list
Test cases:
() -> [1]
[[][]] -> [[1,1]]
{}{}{{}}{{{}}} -> [1,1,[1],[[1]]
Others
You may assume that there are only lists and 1
's will be in the required output
For the output, you are allowed to output the depth as a list/array, or as a string representation e.g. 1 1 [1]
for ()()(())
You can output it in other ways, but the depth of the brackets must be distinguishable from each other.
Your answer should be able to handle one type of bracket (one of ()
, []
, or {}
), at your choice.
You may assume that input is balanced and only uses the type of bracket you chose.
1
, then add some (unspecified?) separators. \$\endgroup\$[]
()
{}
all the valid brackets, or might there be others (i.e.<>
)? Can we assume the input will be balanced? \$\endgroup\$