Dsa
Binary Search
Easy
Speedy Delivery
In a delivery service, you have a list of delivery times and a specific time target. Your goal is to find the delivery time that is closest to the target but does not exceed it.
Input:
- The first line contains the integer D (1 ≤ D ≤ 10^5), the number of delivery times.
- The second line contains D space-separated integers representing the delivery times.
- The third line contains an integer T (0 ≤ T ≤ 10^9), the target delivery time.
Output:
- Print a single integer representing the delivery time closest to the target without exceeding it, or -1 if no delivery time is available below the target.
Example:
Input:
4
15 20 30 40
25
Output:
20
Key concepts
binary_searchintervalsarrays
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now