Dsa
Binary Search
Medium
Job Scheduling
You are given a list of job start and end times (as pairs of integers) and a target duration. Write a function to determine if there is a job whose duration (end time - start time) is exactly equal to the target duration. Return the index of the first job that meets this condition, or -1 if none exists.
Input Format:
A single line containing space-separated pairs of integers (start and end times). The last integer will be the target duration. Each job is represented by two integers: start time and end time.
Output Format:
The index of the job that matches the target duration, or -1 if no such job exists.
Example:
Input:
0 3 2 5 4 7 8 10 12 17
4
Output:
2
Key concepts
binary_searchschedulinggreedy
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