Count User Logins 🌿 (Singapore)
Updated
Problem 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"]]
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"]].
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"]]- 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
1 ≤ n (size of logs) ≤ 10^52000 ≤ YYYY ≤ 30000 ≤ 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).
More PayPal interview questions
- Minimum Cost to Merge Values into OneOA · Seen Nov 2026
- Per-User Sliding-Window Rate LimiterOA · Seen Nov 2026
- Total Cost Against the Lowest Earlier PriceOA · Seen Nov 2026
- Can the Singer Perform the Song?PHONE SCREEN · Seen Jul 2025
- Items Purchase (For Java Backend Engineer)OA · Seen Nov 2024
- Find Minimum Price to SpendOA · Seen Oct 2024
- Modify ArrayOA · Seen Jun 2024
- Similar Password 🪴 (Singapore)OA · Seen Mar 2024
Similar questions at other companies
- Decode Words with Anagram KeysCresta · OACresta interview questions
- Longest String ChainVisa · OAVisa interview questions
- Frequently Bought TogetherAmazon · OA
- Maximize Palindromic WordsSquarepoint Capital · OASquarepoint Capital interview questions
- Aggregate Paginated Project Run RecordsReplit · OA
- Parse and Filter Chargeback DisputesStripe · OAStripe interview questions
- Largest Lexicographical Substring 🌿Google · OAGoogle interview questions
- Count Distinct Message MentionsZipRecruiter · OAZipRecruiter interview questions
- Rank Common Translation MistakesDuolingo · OADuolingo interview questions
- Aggregate Investment Ownership from CSVCarta · OA · PHONE SCREEN