Given a log of login and logout times, find the user who spent the most cumulative time on the platform in a single day.
Each log entry is [user_id, date, login_time, logout_time], where login_time and logout_time are minutes from midnight (0 to 1440). A user may have multiple sessions on the same day, and their total time for that day is the sum of all their session durations on it.
Return the user_id with the highest total time on the platform in any single day. If there is a tie, return the lexicographically smallest user ID.
Function Signature
def highest_spending_user(logs: list[list[str]]) -> str:
Rules
-
Every field of a log entry is a string.
login_time
and
logout_time
are decimal integers written as strings, such as
"120"
.
-
A session lasts
logout_time - login_time
minutes. A user's total for a date is the plain sum of the durations of all their sessions on that date.
-
Totals are per (user, date) pair. Time on different dates is never added together.
-
If several users reach the highest single-day total, return the lexicographically smallest of their IDs.
Constraints
-
1 <= len(logs) <= 10^5
-
user_id
is a non-empty string of lowercase letters
-
date
is a string in
YYYY-MM-DD
format
-
0 <= login_time < logout_time <= 1440
Examples
Input: logs = [["alice", "2024-01-01", "0", "120"],
["bob", "2024-01-01", "60", "300"],
["alice", "2024-01-01", "200", "400"],
["bob", "2024-01-02", "0", "100"]]
Output: "alice"
Alice has (120 - 0) + (400 - 200) = 320 minutes on 2024-01-01. Bob has 240 minutes on 2024-01-01 and 100 on 2024-01-02, so Alice's 320 is the highest single-day total.
Input: logs = [["alice", "2024-01-01", "0", "60"],
["bob", "2024-01-01", "0", "60"]]
Output: "alice"
Both users spent 60 minutes on 2024-01-01. The tie goes to the lexicographically smaller ID, "alice".
Input: logs = [["bob", "2024-03-01", "0", "200"],
["bob", "2024-03-02", "100", "300"],
["carol", "2024-03-01", "500", "800"]]
Output: "carol"
Bob has 200 minutes on each of two days and Carol has 300 minutes on one day. Bob's 400 minutes across both days do not count as one total, so Carol's 300 is the best single day.