Leetcode Problem 1604. Alert Using Same Key-Card Three or More Times in a One Hour Period

1604. Alert Using Same Key-Card Three or More Times in a One Hour Period

Leetcode Solutions

HashMap with Sorting and Sliding Window

  1. Initialize a HashMap to store worker names as keys and a list of their access times as values.
  2. Convert each access time from 'HH:MM' format to minutes since midnight and store them in the HashMap.
  3. Iterate over the HashMap entries and sort the list of times for each worker.
  4. For each worker, use a sliding window of size 3 to check if any three consecutive access times are within a one-hour period.
  5. If the condition is met, add the worker's name to the result list.
  6. Sort the result list alphabetically.
  7. Return the result list.
UML Thumbnail

Brute Force with Time Conversion and Sorting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...