Guest

Untitled 1554

Apr 24th, 2026
10
0
Never
Not a member of GistPad yet? Sign Up, it unlocks many cool features!
None 1.60 KB | None | 0 0
  1. def check_schedule(schedule: list[tuple[str, int, int]]) -> bool:
  2. # 1. Проверяем, что в каждом кортеже start < end
  3. for _, start, end in schedule:
  4. if start >= end:
  5. return False
  6.  
  7. # 2. Сортируем расписание по времени начала для проверки перекрытий
  8. sorted_schedule = sorted(schedule, key=lambda x: x[1])
  9.  
  10. # 3. Проверяем, не заканчивается ли текущая пара позже, чем начинается следующая
  11. for i in range(len(sorted_schedule) - 1):
  12. current_end = sorted_schedule[i][2]
  13. next_start = sorted_schedule[i+1][1]
  14.  
  15. if current_end > next_start:
  16. return False
  17.  
  18. return True
RAW Paste Data Copied