Trains the technique from
LeetCode 700Search in a Binary Search TreeThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A depot keeps its part codes in an ordered index. The index has a head entry, every entry hangs at most two entries below it - one on its low side and one on its high side - and the ordering is strict: every code anywhere below an entry's low side is smaller than that entry's code, and every code anywhere below its high side is larger. No code appears twice.
The index arrives as the array index, written out level by level. index[0] is the head entry's code. The entries after it come in pairs, giving the low side and then the high side of each entry already written out, taken in the same order those entries were written. A side with nothing hanging on it is written null, and a null never claims a pair of its own. Trailing null entries are left off the end.
Return the branch headed by the entry whose code is code, written out in exactly that same convention: the matched code first, then the pairs for the entries of the branch in the order they are written, null for an empty side, and no trailing null entries. Return an empty list if no entry carries code.
Use the ordering to find the entry: the walk down should touch one entry per level, not the whole index.
Example 1
The entry holding 22 has 9 on its low side and 35 on its high side; 9 hangs nothing, and 35 carries 30 on its low side and nothing on its high side.
Example 2
The entry holding 90 carries 82 on its low side and nothing on its high side, and the blank for that empty high side falls at the end of the listing so it is left off.
Example 3
No entry in the index holds 47.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def index_branch(index: list, code: int) -> list:public List<Integer> indexBranch(Integer[] index, int code)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.