Trains the technique from
LeetCode 35Search Insert PositionThis 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.
An alerting service keeps its trigger levels in thresholds, an array of distinct integers held in increasing order. Slots are numbered from 0.
An operator wants to add the trigger level level. Report where it belongs:
level is already one of the stored trigger levels, report the slot it currently occupies;level would occupy after being inserted, with every later trigger level shifting one slot along so the array stays in increasing order. A level above every stored trigger level therefore belongs at slot thresholds.length.Scanning the array end to end is too slow for the service. Your routine has to finish in time logarithmic in the length of thresholds.
Example 1
The level 18 is already stored at slot 3, so that slot is reported.
Example 2
Inserting 6 pushes 18 and 63 one slot along, so 6 lands at slot 3.
Example 3
Every stored level is below 90, so it is appended one past the last slot.
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 insert_slot(thresholds: list[int], level: int) -> int:public int insertSlot(int[] thresholds, int level)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.