Borehole sample cutoff

Write codeEasy12 min

Your task

A geothermal survey crew lowers a probe down a borehole and logs the depth in centimeters at which every sample was taken, so depths arrives sorted ascending. Two samples can come from the same depth, so repeats are possible. The lab now wants to reprocess the run from a chosen depth downward. Given depths and cutoff_cm, return the index of the first sample taken at cutoff_cm or deeper. If several samples sit exactly at the cutoff, return the earliest of them. If every sample in the log is shallower than the cutoff, return the length of depths, the slot where such a sample would belong. An empty log returns 0 under that same rule. Depths are non-negative, and a survey can hold millions of samples, so walking the log one entry at a time is too slow.

Examples

first_sample_at_depth(depths: list[int], cutoff_cm: int) -> int
Example 1
Inputfirst_sample_at_depth([0, 40, 40, 120, 300], 40)
Output1
Example 2
Inputfirst_sample_at_depth([10, 20, 30], 35)
Output3
Example 3
Inputfirst_sample_at_depth([5, 15, 25], 0)
Output0