← Bytedance Interview Insights
Use a window function to group consecutive failed attempts by calculating the difference between the row number and a sequence of timestamps, then filter groups with at least 3 failures on the given date. Finally, aggregate to get the count, first and last timestamps, and join with the users table to return the email.
Pro tip: Clarify whether 'consecutive' means consecutive in time regardless of other users' attempts, or consecutive per user; also confirm if the streak must be entirely within the specific date or can span across dates. Mentioning these edge cases shows attention to detail.
Select login attempts for the specific date and only failed attempts, ensuring you have user_id and timestamp. Order by user_id and timestamp.
Use a window function like ROW_NUMBER() partitioned by user_id and ordered by timestamp, then subtract it from the timestamp (or use a sequence) to create a group identifier for consecutive attempts.
Group by user_id and the group identifier, count the number of failures, and filter groups with count >= 3. Also compute MIN(timestamp) and MAX(timestamp) for the streak.
Join the result with the users table on user_id to get the email, and select the required columns: email, count, first_failure, last_failure.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.