Trains the technique from
LeetCode 704Binary SearchThis 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 survey crew filed one elevation per marker along a ridge trail, and the office sorted the file from the deepest reading up to the highest. That sorted file reaches you as nums; no two markers share an elevation, and readings below sea level show up as negatives.
An engineer names an elevation target and wants the position of the marker holding it, counting positions from 0. If the file has no marker at that elevation, report -1.
The file can be enormous and the office runs this query constantly, so your routine must halve the range it is still considering on each step rather than reading through the markers one by one.
Example 1
The highest marker in the file carries elevation 11 and sits at position 4.
Example 2
Elevation 5 falls between two filed markers, so no position holds it.
Example 3
Readings under sea level are filed the same way, and this one closes out the file at position 2.
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 search(nums: list[int], target: int) -> int:public int search(int[] nums, int target)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.