← Capital One Interview Insights
The filter part was obvious but the consecutive-days logic took me a minute.
First, filter the transactions to include only successful ones, then deduplicate to get distinct user-date pairs. Use the 'gaps and islands' technique: for each user, assign a row number ordered by date and subtract it from the date to create a group identifier for consecutive days. Finally, count the size of each group and take the maximum per user, ordering by streak length descending.
Pro tip: Mention that you would clarify the definition of 'consecutive days' (e.g., calendar days vs. business days) and confirm that a streak can start on any day, not necessarily the first transaction. Also, note that if a user has no successful transactions, they should be excluded from the result.
Filter the transactions to include only successful ones (exclude failed/reversed). Then, extract distinct user_id and transaction_date pairs to ensure each day is counted once per user.
For each user, order the distinct dates and assign a row number. Subtract the row number from the date to create a group key; consecutive dates will have the same group key.
Group by user_id and the group key, then count the number of days in each group. This gives the length of each consecutive streak.
For each user, take the maximum streak length from the previous step. This yields the longest consecutive days with successful transactions.
Return user_id and longest_streak, ordered by longest_streak descending. Optionally, handle ties by user_id or leave as is.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.