Trains the technique from
LeetCode 501Find Mode in 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 calibration bench measures an integer offset, in tenths of a micron, for every gauge block it checks, and files each offset into an ordered tree. Repeats are kept, so the same offset can be filed many times over. The order rule is: for any filed offset, every offset in the branch to its left is less than or equal to it, and every offset in the branch to its right is greater than or equal to it.
The tree arrives as gauge, a level-order listing. Its first entry is the offset at the top of the tree. After that, the listing gives the left branch then the right branch of each offset already listed, in the order those offsets appear, writing null where a branch is empty. Slots below a null are never written down, and the trailing run of null entries is left off.
Work out how many times each distinct offset was filed. Return every offset whose count equals the highest count reached by any offset, listed in ascending order. Several offsets may be tied on the highest count, in which case all of them belong in the answer.
Example 1
The tree holds the offsets 2, 2, 4, 7 and 7. Both 2 and 7 were filed twice while 4 was filed once, so the highest count is 2 and both offsets that reach it come back in ascending order.
Example 2
All four filed offsets are 6, so 6 has a count of 4 and nothing else was filed at all.
Example 3
The tree holds -9, -7, -5, -3, -3 and -3. The offset -3 was filed three times and every other offset once, so -3 is the only one at the highest count.
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 most_common_offsets(gauge: list[int | None]) -> list[int]:public int[] mostCommonOffsets(Integer[] gauge)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.