Where does this order slot in?
You keep a sorted array levels of distinct price levels on a book. A new order arrives at price target. You want the index where target belongs so the array stays sorted: the position of the first level that is greater than or equal to target (if target is already present, return that index; if it belongs at the end, return len(levels)).
levels = [101, 103, 105, 106], target = 105 -> 2
levels = [101, 103, 105, 106], target = 104 -> 2
levels = [101, 103, 105, 106], target = 107 -> 4
Find the insert index using comparisons.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.