Your input is a ragged list of positive integers and a positive integer. Your task is to find that positive integer and return it's index, or if the positive integer doesn't exist, indicate it's nonexistence.
How are indices in ragged lists defined? They are simply lists of indices that when used consecutively to index the ragged list, return the desired element. For example, if the ragged list is [1,[2,3],[[4,5]],[]]
then the index of 2
is [1,0]
and the index of 5
is [2,0,1]
.
If there are multiple integers, return the index of the first one. That is, the one whose index is the smallest when compared lexicographically.
Rules
You can choose between 0 and 1 based indexing and also the order of the returned index.
You must indicate the non-existance of a solution in some easily identified manner. Here are some examples:
Ok
- Return a value that is not a list. For example, -1 or None
- Return an empty list
- Error in some way
- Exit the program
Not ok
- Infinite loop/recursion (if you want to use a resource exhaustion error, be sure to read this)
- Undefined behavior
- A list of integers, even if those integers are out of bounds or negative.
An exception to the last point. You may use a single consistent value that can never be the output to indicate nonexistence. For example, a program that returns [-1]
whenever there is no solution is allowed, but a program that returns [-1]
or [-2]
when there isn't a solution is not allowed.
Finally, you can also return a list of all solutions in sorted order. If you use this IO format, you must return an empty list if there are no solutions.
Test cases
[], 1 -> None
[[[40]]], 40 -> [0,0,0]
[[1,[]],[[3]],3,[3]], 3 -> [1,0,0]
[5], 5 -> [0]
[[],[[],[]]], 5 -> None
0
orfalse
if there's no solution? \$\endgroup\$