β back to unit
Challenge
# searching advanced
Find the Largest Number At Most X
The crane can lift at most x kilograms β pick the heaviest crate it can still handle. ποΈ
You get a SORTED list of crate weights and the limit x. Print the largest weight that is x or less, or none if even the lightest crate is too heavy.
Example:
Input: weights = [100, 250, 400, 800], x = 500
Output: 400
The boundary search finds the first weight greater than 500 (800, at position 3), so the answer sits just before it, at 400.
π‘ need a hint?
srch-floor.pyπ given lines are locked β write your code in between
loading...