Ctrl K

Duty Days With No Gaps

Easy
Office duty is scheduled as ranges of days: shifts[i] = [a, b] means someone is on duty every day from a through b inclusive. Ranges may overlap. Given first and last, return True if **every** day from first through last inclusive is covered by at least one shift, and False if some day has nobody on duty.
Example 1
shifts=[[1, 4], [5, 8], [8, 12]], first=3, last=10 → True

Days 3–4 fall in the first shift, 5–8 in the second, 9–10 in the third.

Example 2
shifts=[[2, 5], [7, 9]], first=4, last=8 → False

Day 6 is not in any shift.

Example 3
shifts=[[10, 10]], first=10, last=10 → True

Only day 10 must be covered, and there is a shift for exactly that day.

Constraints
  • 1 ≤ len(shifts) ≤ 50
  • 1 ≤ a ≤ b ≤ 50 for each shifts[i] = [a, b]
  • 1 ≤ first ≤ last ≤ 50
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSpots Under the Stalls EasyLongest Run with a Given Sum MediumA Stretch Divisible by k MediumAs Many Heads as Tails MediumFour Equal Pieces Hard
loading Python…
Input
shifts=[[1, 4], [5, 8], [8, 12]], first=3, last=10
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 108 tests on the server, hidden ones included.