index | submit | rank | book

timetable – Timetable conflicts

Write a program that checks whether two time intervals overlap. This is a common problem solved by scheduling systems, as for example you cannot be enrolled in two classes that happen at the same time or be in two meetings that happen at the same time.

Two example timetables

Input and Output

Each line of input will consist of four points in time t₀, t₁, t₂ and t₃ separated by a single space. The first time interval starts at t₀ and ends at t₁ and the second time interval starts at t₂ and ends at t₃. The four points t₀, t₁, t₂ and t₃ are in the format HH:MM where HH indicates the hour and MM indicate the minutes.

For each line of input, your program should produce a line of output with either ok or conflict indicating whether there is an overlap between the intervals t₀-t₁ and t₂-t₃.

Input is given so that:

HH values are guaranteed to be between 00 and 23 (inclusive). MM values are guaranteed to be between 00 and 59 (inclusive). Time intervals do not roll over midnight.

Example Input

13:37 15:59 16:00 17:00
14:00 15:00 14:30 15:30

Example Output

ok
conflict

Scoring

Hints

  1. You can more easily compare the timestamps by converting them to a single integer indicating the number of minutes since midnight.

  2. To read the hour and minutes of each timestamp you will need to split at the colon :.

    • In Python, you can split a string s at the : by using s.split(':');
    • In C, you can read a single timestamp by using scanf(" %d:%d", &h, &m);
    • In Haskell, you can split a string hhmm at the : by using the function break in a let or where with (hh,':':mm) = break (==':') hhmm.
  3. When testing your program locally, try to think on the several ways in which two time intervals may or may not overlap. Try to come up with different test cases exercising each different way.

try first: bool-not bool-and-or order

try also: discount

try next: bool-calc intersect

index | submit | rank | book

Copyright © 2020-2023 Rudy Matela
All rights reserved