Ctrl K

Frequent Badge Swipes

Medium
An office turnstile logs every badge swipe. One day's log is the array swipes, where swipes[i] = [name, time]: name is the employee's name and time is the moment of the swipe in four-digit 24-hour format, such as "0745" or "2310". An employee is *frequent* if they have at least three swipes that fit into one hour, meaning the gap between the earliest and the latest of them is strictly less than 60 minutes. Swipes at "0815" and "0915" are already too far apart. All records belong to a single day, so "2355" and "0005" do not fall into the same hour either. Return the names of all frequent employees in any order.
Example 1
swipes=[["anna", "0910"], ["boris", "0915"], ["anna", "0955"], ["boris", "1020"], ["anna", "0930"], ["boris", "1100"]] → ['anna']

anna swiped at 09:10, 09:30 and 09:55, all within one hour. boris swiped at 09:15, 10:20 and 11:00, and no three of them fit in an hour.

Example 2
swipes=[["kim", "1400"], ["kim", "1430"], ["kim", "1500"]] → []

14:00 and 15:00 are exactly one hour apart, which no longer counts as the same window, so kim is not in the answer.

Example 3
swipes=[["lee", "2350"], ["lee", "2359"], ["lee", "0005"], ["max", "0800"]] → []

All swipes belong to the same day: 00:05 is the start of the day, not a continuation of 23:59, so lee has no busy window.

Constraints
  • 1 ≤ len(swipes) ≤ 100
  • 1 ≤ len(name) ≤ 10, names consist of lowercase English letters
  • time is four digits forming a valid time from "0000" to "2359"
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAnagram Buckets MediumA Subsequence of One Word Only MediumMost Searched Words MediumWord Grown Letter by Letter MediumMerge Contact Cards Medium
loading Python…
Input
swipes=[["anna", "0910"], ["boris", "0915"], ["anna", "0955"], ["boris", "1020"], ["anna", "0930"], ["boris", "1100"]]
Expected
['anna']

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