Career Hub/Interview questions/Longest Trading Streak
Coinbase logo

Longest Trading Streak

Coinbase·hard·SQL

For each user, find their longest streak of consecutive days on which they placed at least one trade. Return user_id and max_consecutive_days, ordered by max_consecutive_days descending.

Schema

trades
trade_idINTEGER
user_idINTEGER
cryptoVARCHAR
quantityDECIMAL
priceDECIMAL
traded_atTIMESTAMP

Target output

Target output
user_idmax_consecutive_days
37
15
44
23

What this question tests

The classic gaps-and-islands problem: turning runs of consecutive days into groups, then measuring the longest run. It is a hard-tier staple across interview loops; deriving the grouping trick under pressure is the test, and candidates who have it find most other window-function questions easy.

More SQL interview questions

  • Category Explorers · Amazon · medium
  • Top Monthly Searches · Google · medium
  • Underperforming Drivers · Lyft · medium
Querytrades
Cmd+Enterto runLoading...
Output

Loading sample data...