Longest Streak of Consecutive Days With Xbox Logins

Last updated: November 29, 2026

Quick Overview

Given an unsorted list of day numbers on which a player signed in to Xbox (duplicates possible), return the length of the longest run of consecutive days.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given an unsorted list of day numbers on which a player signed in to Xbox (duplicates possible), return the length of the longest run of consecutive days.

Asked in Microsoft technical screens framed around Xbox engagement features such as login streak rewards. The interviewer wants an O(n) hashing solution rather than sorting, and listens for the trick of only starting a count at the beginning of a run.

What the Interviewer Expects
  • Recognize that sorting gives O(n log n) and push for O(n)
  • Use a set for O(1) membership
  • Only begin counting at days whose predecessor is absent
  • Handle duplicates naturally via the set
  • Argue why the total work is linear
Key Topics to Cover
hash sets
linear time
sequences
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 days of the streak?
  • What if days arrive as a stream and you must report the longest streak so far?
  • How would you allow one missed day (a streak freeze)?
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 integers (day indices), unsorted, possibly with duplicates. Output: the longest count of consecutive integers present. An empty list returns 0. We should aim for linear time because a h...

High-Level Design

Put every day into a set. A day d starts a streak exactly when d - 1 is not in the set. For each such start, walk upward d+1, d+2, ... while present and record the length. Because each day is vi...


Submit Your Answer
Markdown supported