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 account id logged in on login_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
Inputaccounts = [["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
Inputaccounts = [["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

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate