Count Prime Members With the Longest Consecutive Login Streak

Last updated: November 29, 2026

Quick Overview

Given a list of integer day numbers on which a Prime member opened the app (unsorted, possibly with duplicates), return the length of their longest run of consecutive days. Solve it in linear time.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Given a list of integer day numbers on which a Prime member opened the app (unsorted, possibly with duplicates), return the length of their longest run of consecutive days. Solve it in linear time.

This shows up in Amazon Online Assessment style sets as a quick engagement-metrics problem. Graders look for the O(n) set-based approach rather than sorting, and for correct handling of duplicate days.

What the Interviewer Expects
  • State the sorting solution and its O(n log n) cost
  • Arrive at the hash set approach that only starts counting at run beginnings
  • Argue why the set approach is linear even with the inner while loop
  • Handle duplicates and empty input correctly
  • Trace a small example aloud
Key Topics to Cover
Hash Set
Arrays
Linear Time
Streaks
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you return the actual start and end day of the longest streak?
  • What if days arrive as a stream and you need the current longest streak after each event?
  • How would you compute this for 200 million members in a batch job?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list of ints (days since some epoch), any order, duplicates allowed, possibly empty. Output: an int, the longest count of consecutive distinct days. A single login is a streak of 1, an empty li...

High-Level Design

Put all days into a set. A day d is the start of a run only if d - 1 is not in the set. For each start, walk forward d + 1, d + 2, ... while present and record the length. Because each number is visit...


Submit Your Answer
Markdown supported