A. Opening Hours

51 cases Time limit 1000 ms total Memory 256 MB

A café keeps a record of its staff shifts. Each shift is a pair [start, end], and the person works the hours starting at start, start + 1, …, end - 1. So [9, 12] covers the hours starting at 9, 10 and 11.

Shifts can overlap. Given the list of shifts, return how many different hours have at least one person working.

Constraints:

  • 0 ≤ number of shifts ≤ 8
  • 0 ≤ start < end ≤ 24

Examples:

f([[9, 12], [11, 14], [16, 17]]) returns 6 (hours 9, 10, 11, 12, 13 and 16)

f([[9, 12], [12, 15]]) returns 6

f([[10, 11], [10, 11]]) returns 1

f([]) returns 0

0 bytes Contest has ended