Shift hours
EasyOnline Assessment
Total each employee's worked time from a list of shift records and rank the employees by it.
Each record is a string "name HH:MM-HH:MM": an employee name, one space, then the start and end time of one shift on a 24-hour clock. If the end time is earlier than the start time, the shift ends on the following day (it crosses midnight). If the end time equals the start time the shift is empty and counts as 0 minutes. A shift is never longer than 24 hours.
Names are case-insensitive: Ana and ana are the same employee, and employees are reported in lowercase. Add up the minutes of all of an employee's shifts.
Input: records, a list of strings in the format above.
Output: a list of strings "name H:MM", one per employee whose total is greater than 0. H is the total hours written without padding (it can exceed 23) and MM is the remaining minutes always written with two digits, for example "ana 9:05". Sort by total minutes descending; employees with equal totals are ordered by name in ascending lexicographic order. If nobody has worked any time, return [].
Example 1
- Input:
- [["Ana 09:00-17:30","bo 22:00-06:00","ana 12:00-12:30"]]
- Output:
- ["ana 9:00","bo 8:00"]
- Explanation
- "Ana" and "ana" are the same employee: 09:00-17:30 is 8:30 and 12:00-12:30 is 0:30, so 9:00 in total. "bo" works 22:00-06:00, which crosses midnight, so that is 8:00. Sorted by total descending: ana, then bo.
Example 2
- Input:
- [["Cy 08:00-08:00","Di 10:15-10:20","di 23:50-00:05","Ed 10:00-10:20"]]
- Output:
- ["di 0:20","ed 0:20"]
- Explanation
- "cy" has an empty shift (start equals end) so the total is 0 and cy is left out. "di" works 5 minutes plus 23:50-00:05 (15 minutes across midnight) for 0:20, and "ed" works 0:20 as well. The totals tie, so they are ordered by name: di before ed.
Example 3
- Input:
- [["Zed 00:00-23:59","zed 00:00-23:59","Amy 06:00-05:59"]]
- Output:
- ["zed 47:58","amy 23:59"]
- Explanation
- Both of zed's shifts last 23 hours 59 minutes, so zed totals 47:58; hours can exceed 23. "Amy" starts at 06:00 and ends at 05:59 the next day: 23:59. zed is first because the total is larger.
Constraints
0 <= records.length <= 2,000- Each record is
"name HH:MM-HH:MM"with a name of 1 to 10 ASCII letters and times from00:00to23:59 - The same employee may appear in many records, with any mix of upper and lower case