For this challenge, a list is considered valid if and only if it consists entirely of integers and valid lists (recursive definitions \o/). For this challenge, given a valid list and an integer, return a list of all depths at which the integer can be found.
Example
Let's consider list [1, [2, [3, [1, 2, 3], 4], 1], 1]
and integer 1
. Then, we can draw out the list like this:
Depth 0 1 2 3
Num 1
2
3
1
2
3
4
1
1
You'll notice that 1
shows up at depths 0, 1, 3
. Thus, your output should be 0, 1, 3
in some reasonable format (order does not matter).
The depth may be either 0- or 1-indexed, but please specify in your submission which one it is.
Test Cases (0-indexed)
For list [1,[2,[3,4],5,[6,7],1],[[[[5,2],4,[5,2]]],6],3]
:
1 -> [0, 1]
2 -> [1, 4]
3 -> [0, 2]
4 -> [2, 3]
5 -> [1, 4]
6 -> [1, 2]
7 -> [2]
For list [[[[[1],0],1],0],1]
:
0 -> 1, 3
1 -> 0, 2, 4
For list [11,22,[33,44]]
:
11 -> [0]
22 -> [0]
33 -> [1]
44 -> [1]
Return an empty list if the search term does not exist in the list anywhere.
Negative and zero values are valid in the input list and term.