#613 · Sorting and searching · Advanced · Review the AI's code · 115 XP · about 15 min
Someone asked an AI assistant: "Write a function that takes a list of meetings as (start, end) minute pairs and returns how many minutes are covered by at least one meeting. Meetings can overlap." This is its answer. It looks right, but it has a bug.
busy_minutes(meetings) gets a list of (start, end) pairs of whole minutes since midnight, with start < end, in any order. A meeting covers the time from start to end, so (60, 90) covers 30 minutes. It should return how many minutes are covered by at least one meeting: time covered by two overlapping meetings counts once. Meetings that only touch, such as (60, 90) and (90, 120), together cover 60 minutes.
busy_minutes([(60, 90), (75, 120)]) # returns 60 busy_minutes([(0, 30), (100, 130)]) # returns 60 busy_minutes([(0, 300), (60, 90)]) # returns 300 busy_minutes([]) # returns 0
In the first example the two meetings overlap from minute 75 to 90, so together they cover minutes 60 to 120.
meetings has 0 to 10,000 pairs; 0 <= start < end <= 1440.First solves only, ranked by stars and then time.