Users with a Short Sign-In Session
Problem statement
logs are globally sorted by increasing integer timestamp. Each entry is timestamp user SIGNIN or timestamp user SIGNOUT. Per user, sessions are well formed and non-overlapping.
Return sorted user ids that have at least one session with duration at most maxTime, where duration is signout timestamp minus its paired signin timestamp.
Function
usersWithShortSession(logs: String[], maxTime: int) → String[]Examples
Example 1
logs = ["1 alice SIGNIN","2 bob SIGNIN","5 alice SIGNOUT","12 bob SIGNOUT"]maxTime = 5return = ["alice"]Alice's duration is 4; Bob's is 10.
Example 2
logs = ["0 a SIGNIN","3 a SIGNOUT","10 a SIGNIN","20 a SIGNOUT"]maxTime = 3return = ["a"]At least one qualifying session is sufficient.
Example 3
logs = ["1 z SIGNIN","9 z SIGNOUT"]maxTime = 7return = []The only duration is 8.
Constraints
0 <= logs.length <= 2 * 10^5.- Timestamps are strictly increasing nonnegative integers.
- User ids have no spaces and each user's events alternate SIGNIN, SIGNOUT.