Mid/Senior
Active Users
You are given two tables represented as arrays of rows:
accounts, where each row is[id, name]and represents a user account.logins, where each row is[id, login_date]and represents that the user with accountidlogged in onlogin_date.
A user is considered an active user if they logged in for 5 or more consecutive days. Multiple login records on the same day should count as only one day for that user.
Return the active users as rows [id, name], sorted by id in ascending numeric order.
Example 1
Input
accounts = [["1","Winston"],["7","Jonathan"]], logins = [["7","2020-05-30"],["1","2020-05-30"],["7","2020-05-31"],["7","2020-06-01"],["7","2020-06-02"],["7","2020-06-02"],["7","2020-06-03"],["1","2020-06-07"],["7","2020-06-10"]]Output
[["7","Jonathan"]]User 7 has logins on five consecutive dates from 2020-05-30 through 2020-06-03, while user 1 does not.
Example 2
Input
accounts = [["2","Alice"],["3","Bob"]], logins = [["2","2021-01-01"],["2","2021-01-02"],["2","2021-01-03"],["2","2021-01-04"],["2","2021-01-05"],["3","2021-01-01"],["3","2021-01-03"],["3","2021-01-05"]]Output
[["2","Alice"]]User 2 has exactly five consecutive login dates, so they are returned; user 3 has only non-consecutive login dates.
Constraints
- 1 <= accounts.length <= 10^4
- 1 <= logins.length <= 10^5
- accounts[i].length == 2
- logins[i].length == 2
- accounts[i] = [id, name] where id is a positive integer represented as a string
- logins[i] = [id, login_date] where id is a positive integer represented as a string and login_date is in YYYY-MM-DD format
- All account ids are unique
- Each login id appears in accounts