First and Last Access Time per User
Problem statement
Each entry in logs has the form userId,resourceId,timestamp and records a user accessing a resource. For each user, return the minimum and maximum timestamp across all resources.
Return rows [userId,firstTimestamp,lastTimestamp], with timestamps written as decimal strings.
For this exercise, assume records have exactly three comma-separated fields without spaces, identifiers are nonempty case-sensitive alphanumeric strings, and timestamps are nonnegative integer seconds.
For this exercise, assume rows are ordered lexicographically by user identifier and an empty log produces an empty result.
Function
accessRanges(logs: String[]) → String[][]Examples
Example 1
logs = ["bob,r1,10","amy,r2,20","bob,r3,2","amy,r1,40"]return = [["amy","20","40"],["bob","2","10"]]Bob spans 2 through 10 across resources; Amy spans 20 through 40. Rows are sorted by user.
Example 2
logs = ["u,resource,7"]return = [["u","7","7"]]One event supplies both endpoints.
Constraints
- For this exercise, assume
0 <= logs.length <= 10^4. - Identifier lengths are between
1and30. - Timestamps are integers from
0through10^9.