Code RoomBorehole sample cutoff
EasyPrep Room Coding #4731

Borehole sample cutoff

CodingAlgorithms & data structuresEntry–Mid~12 min

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.

Implement
first_sample_at_depth(depths: list[int], cutoff_cm: int) → int
Examples
in[[0,40,40,120,300],40]out1
in[[10,20,30],35]out3
in[[5,15,25],0]out0
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 12 min
InputExpectedGot
[[0,40,40,120,300],40]1not run yetsample
[[10,20,30],35]3not run yetsample
[[5,15,25],0]0not run yetsample