FastPrepFastPrep
Problem Brief

Count User Logins 🌿 (Singapore)

INTERNOA

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 Description

Complete the function countUserLogins in the editor.

countUserLogins has the following parameter:

  1. 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

1Example 1

Input
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"]]
Output
[["user1","2021-01-01","2"],["user1","2021-01-02","1"],["user2","2021-01-01","2"]]
Explanation
Example 1 illustration
The function should output the login counts for each user per day, sorted lexicographically, resulting in a 2-d array of strings in the format [["user1","2021-01-01","3"],["user1","2021-01-02","1"],["user2","2021-01-01","1"]].

2Example 2

Input
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"]]
Output
[["user1","2021-01-01","3"],["user2","2021-01-01","2"]]
Explanation
  • user1 logs into the system 3 times on 2021-01-01
  • user2 logs into the system 3 times on 2021-01-01
  • entry 6 in the logs has an invalid time, 25:00:00.
  • entry 7 in the logs has an invalid data, 2021-02-29.
  • Constraints

    Limits and guarantees your solution can rely on.

  • 1 ≤ n (size of logs) ≤ 10^5
  • 2000 ≤ YYYY ≤ 3000
  • 0 ≤ MM, DD, HH, SS ≤ 99
  • YYYY, MM, DD, HH, and SS are all integers.
  • All usernames are of the format "user" appended with some integer (user_id).
  • public String[][] countUserLogins(String[][] logs) {
        // write your code here
    }
    
    Input

    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"]]

    Output

    [["user1", "2021-01-01", "2", "user1", "2021-01-02", "1", "user2", "2021-01-01", "2"]]

    Sign in to submit your solution.