PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Data Manipulation (SQL/Python)/Netflix

Determine Maximum Consecutive Order Days Per User

Last updated: Mar 29, 2026

Quick Overview

Determine Maximum Consecutive Order Days Per User evaluates SQL or pandas logic, joins, grouping, window functions, null handling, edge cases, and validation in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

  • Medium
  • Netflix
  • Data Manipulation (SQL/Python)
  • Data Scientist

Determine Maximum Consecutive Order Days Per User

Company: Netflix

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: Medium

Interview Round: Onsite

orders +----+---------+------------+ | id | user_id | order_date | +----+---------+------------+ | 1 | 101 | 2024-01-01 | | 2 | 101 | 2024-01-02 | | 3 | 101 | 2024-01-05 | | 4 | 102 | 2024-01-03 | | 5 | 102 | 2024-01-04 | +----+---------+------------+ ##### Scenario The commerce team wants to know each customer’s best ordering streak for loyalty analysis. ##### Question For every user, return the maximum number of consecutive calendar days on which they placed at least one order. ##### Hints Generate dense date series per user; use gaps-and-islands or window functions.

Quick Answer: Determine Maximum Consecutive Order Days Per User evaluates SQL or pandas logic, joins, grouping, window functions, null handling, edge cases, and validation in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Solution

# Solution Alignment Use a gaps-and-islands pattern after deduplicating each user's order dates. ## PostgreSQL Query ```sql WITH user_days AS ( SELECT DISTINCT user_id, order_date::date AS order_date FROM orders ), numbered AS ( SELECT user_id, order_date, order_date - (ROW_NUMBER() OVER ( PARTITION BY user_id ORDER BY order_date )::int) AS island_key FROM user_days ), streaks AS ( SELECT user_id, island_key, COUNT(*) AS streak_len FROM numbered GROUP BY user_id, island_key ) SELECT user_id, MAX(streak_len) AS max_consecutive_order_days FROM streaks GROUP BY user_id ORDER BY user_id; ``` ## Why It Works For consecutive calendar days, subtracting the row number from the date produces the same island key for every day in the same streak. Deduplicating `user_id, order_date` first ensures multiple orders on one day do not inflate the streak length. ## Complexity The dominant cost is sorting within each user for the window function: O(n log n) overall in the usual implementation. Space is O(n) for intermediate rows. ## Edge Cases Users with multiple orders on the same date, one-day streaks, gaps between dates, and users with no orders if they must be included from a separate users table.

Related Interview Questions

  • Aggregate D1 retention cohorts in SQL - Netflix (Medium)
  • Write SQL for DAU and first-purchase conversion - Netflix (Medium)
  • Write SQL for rolling frequency caps - Netflix (Medium)
  • Transform flat keys into nested dictionary - Netflix (Medium)
  • Analyze Retention Metrics Using SQL and Python - Netflix (Medium)
|Home/Data Manipulation (SQL/Python)/Netflix

Determine Maximum Consecutive Order Days Per User

Netflix logo
Netflix
Jul 12, 2025, 6:59 PM
MediumData ScientistOnsiteData Manipulation (SQL/Python)
56
0

Determine Maximum Consecutive Order Days Per User

orders

+----+---------+------------+ | id | user_id | order_date | +----+---------+------------+ | 1 | 101 | 2024-01-01 | | 2 | 101 | 2024-01-02 | | 3 | 101 | 2024-01-05 | | 4 | 102 | 2024-01-03 | | 5 | 102 | 2024-01-04 | +----+---------+------------+

Scenario

The commerce team wants to know each customer’s best ordering streak for loyalty analysis.

Question

For every user, return the maximum number of consecutive calendar days on which they placed at least one order.

Hints

Generate dense date series per user; use gaps-and-islands or window functions.

Constraints & Assumptions

  • Preserve the scope, facts, inputs, and requested outputs from the prompt above.
  • If the prompt leaves a detail unspecified, state a reasonable assumption before relying on it.
  • Keep the answer interview-ready: concise enough to present, but concrete enough to implement or evaluate.

Clarifying Questions to Ask

  • Clarify SQL dialect or Python library versions, date/time semantics, duplicate handling, and null handling.
  • Define the grain of each intermediate result before aggregating.
  • State expected output columns and ordering explicitly.

What a Strong Answer Covers

  • A query or pandas plan that matches the requested output grain.
  • Correct joins, filters, grouping, window functions, and treatment of NULLs or duplicates.
  • A brief explanation of why the result is correct and how it handles edge cases.
  • Performance notes, indexes/partitioning, and validation queries when relevant.

Follow-up Questions

  • How would you test the query on a tiny hand-built dataset?
  • What changes if duplicate events or late-arriving data are present?
  • Which indexes, clustering, or partitions would help at production scale?
Loading comments...

Browse More Questions

More Data Manipulation (SQL/Python)•More Netflix•More Data Scientist•Netflix Data Scientist•Netflix 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 8,000+ real questions from top companies.

Product

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

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.