Loading
Loading
A sorted list of distinct sensor thresholds must stay sorted when a new threshold is added.
Return the index at which the new value should be inserted. If it already exists, return its index.
thresholds = [1, 3, 5, 6], value = 5lo=0 hi=4 mid=2 → 55 is not less than 5, keep as candidatelo=0 hi=2 mid=1 → 33 < 5, discardlo=2 hi=2answer 22Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(log n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
Example 2
2 belongs between 1 and 3.
Example 3
Larger than everything, so it goes at the end.