Count User Logins ๐ฟ (Singapore)
Learn this problemProblem statement
A company wants to track the usage of its mobile app by recording users' login times and dates. The company stores the login information in a 2D array of strings, logs, which contains data in the format ["/username<user_id>","login_time","login_date"].
They need a function to process the logs and output a 2D array of strings, sorted lexicographically, that displays the number of times each user logs in per day in the format ["/username<user_id>","login_date","login_count"]. It must filter invalid data in the input array rather than write it to the output array.
Users should be sorted in lexicographic order based on their user_id. Each user's information should be sorted by the login date in ascending order. The date and time are provided in YYYY-MM-DD and HH:MM:SS format, and the username has the format "userX" where X is an integer.
Function
countUserLogins(logs: String[][]) โ String[][]
Complete the function countUserLogins in the editor.
countUserLogins has the following parameter:
String[][] logs: a 2D array of strings containing the login data
Returns
String[][]: a 2D array of strings containing the user login counts per day, sorted lexicographically
Examples
Example 1
logs = [["user1","09:00:00","2021-01-01"],["user1","13:00:00","2021-01-01"],["user2","14:00:00","2021-01-01"],["user1","20:00:00","2021-01-02"],["user2","21:00:00","2021-01-01"]]return = [["user1","2021-01-01","2"],["user1","2021-01-02","1"],["user2","2021-01-01","2"]]
[["user1","2021-01-01","3"],["user1","2021-01-02","1"],["user2","2021-01-01","1"]].Example 2
logs = [["user1","09:00:00","2021-01-01"],["user1","13:00:00","2021-01-01"],["user2","14:00:00","2021-01-01"],["user1","20:00:00","2021-01-01"],["user2","21:00:00","2021-01-01"], ["user3","25:00:00","2021-01-01"], ["user4","22:00:00","2021-02-29"]]return = [["user1","2021-01-01","3"],["user2","2021-01-01","2"]]Constraints
1 โค n (size of logs) โค 10^52000 โค YYYY โค 30000 โค MM, DD, HH, SS โค 99