PracHub
QuestionsLearningGuidesInterview Prep
|Home/Data Manipulation (SQL/Python)/Bytedance

Find Each User's Earliest Seven-Day Activity Streak

Last updated: Aug 7, 2026

Quick Overview

A PostgreSQL interview problem about finding each user's earliest streak of at least seven consecutive active dates. It tests date deduplication, gaps-and-islands logic, streak length calculation, earliest-match selection, and deterministic output.

  • medium
  • Bytedance
  • Data Manipulation (SQL/Python)
  • Data Scientist

Find Each User's Earliest Seven-Day Activity Streak

Company: Bytedance

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

# Find Each User's Earliest Seven-Day Activity Streak Write one PostgreSQL SELECT statement or CTE query. Do not create, alter, or modify tables. ## Schema user_activity | column | type | description | |---|---|---| | activity_id | integer | Unique event | | user_id | integer | User | | activity_ts | timestamp | Event time | ## Task Find users who were active on at least seven consecutive calendar dates. Multiple events on one date count as one active date. For each qualifying user, return the start date of that user's earliest qualifying seven-day streak. ## Required Output Return user_id and streak_start. Sort by user_id ascending. ## Constraints - A streak is based on calendar dates, not 24-hour gaps between timestamps. - Longer streaks qualify; return the first date from which seven consecutive dates are present. - Duplicate activity dates must not inflate a streak. ```hint Group consecutive dates into islands After deduplicating user-date rows, subtract a row-number-based day offset. Consecutive dates share the same island key. ```

Quick Answer: A PostgreSQL interview problem about finding each user's earliest streak of at least seven consecutive active dates. It tests date deduplication, gaps-and-islands logic, streak length calculation, earliest-match selection, and deterministic output.

Related Interview Questions

  • Campaign Efficiency Metrics and Below-Average CTR - Bytedance (medium)
  • Find high-value crypto users and top CTR - Bytedance (hard)
  • Find top-paid employee per department - Bytedance (medium)
|Home/Data Manipulation (SQL/Python)/Bytedance

Find Each User's Earliest Seven-Day Activity Streak

Bytedance logo
Bytedance
Aug 3, 2026, 12:00 AM
mediumData ScientistTechnical ScreenData Manipulation (SQL/Python)
0
0

Find Each User's Earliest Seven-Day Activity Streak

Write one PostgreSQL SELECT statement or CTE query. Do not create, alter, or modify tables.

Schema

user_activity

columntypedescription
activity_idintegerUnique event
user_idintegerUser
activity_tstimestampEvent time

Task

Find users who were active on at least seven consecutive calendar dates. Multiple events on one date count as one active date. For each qualifying user, return the start date of that user's earliest qualifying seven-day streak.

Required Output

Return user_id and streak_start. Sort by user_id ascending.

Constraints

  • A streak is based on calendar dates, not 24-hour gaps between timestamps.
  • Longer streaks qualify; return the first date from which seven consecutive dates are present.
  • Duplicate activity dates must not inflate a streak.
Loading comments...

Browse More Questions

More Data Manipulation (SQL/Python)•More Bytedance•More Data Scientist•Bytedance Data Scientist•Bytedance Data Manipulation (SQL/Python)•Data Scientist Data Manipulation (SQL/Python)

Write your answer

Your first approved answer each day earns 20 XP.

Sign in to write your answer.
PracHub

Master your tech interviews with 9,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.