← 返回 bytedance 的题目列表SQL: Longest Consecutive Login Days per User
类型:online_judge
Problem: Longest Consecutive Login Streak per User (SQL)
Given a login table logins, write SQL to compute the maximum consecutive-day login streak for each user.
Schema
logins(user_id STRING, login_date DATE)
A user may have multiple rows for the same day (deduplicate by day).
Output
user_id
max_consecutive_days
Order by user_id ascending.
Notes
Consecutive means consecutive calendar days.
Missing any day breaks the streak.
Must handle duplicate rows per day.
Example
See the sample table in the Chinese statement; expected output is:
u1 -> 2
u2 -> 2
Example
Input
-- Table-driven SQL problem; no stdin
Output
-- Expected: compute max consecutive login days per user