Longest Streak of Consecutive Days With Closed Activity Rings

Last updated: November 29, 2026

Quick Overview

Given an unsorted list of day numbers on which an Apple Watch user closed all their Activity rings (duplicates possible), return the length of the longest run of consecutive days. Solve it in linear time.

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

0

0

0 solved


Given an unsorted list of day numbers on which an Apple Watch user closed all their Activity rings (duplicates possible), return the length of the longest run of consecutive days. Solve it in linear time.

Apple Health and Fitness teams reason about streaks and awards constantly, so this shows up as a screen question with a product wrapper. The interviewer wants the O(n) set-based approach rather than sorting, and checks you only start counting at the beginning of a run.

What the Interviewer Expects
  • Note that sorting gives O(n log n) and ask whether that is acceptable
  • Use a set and only expand from days whose predecessor is absent
  • Argue why the total work is linear
  • Handle duplicates and empty input
  • Return length, then discuss returning the start day too
Key Topics to Cover
hash sets
sequences
amortized analysis
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
  • Return the start and end day of the longest streak.
  • Allow one rest day per week without breaking the streak; how does the approach change?
  • Days arrive one at a time from the watch; maintain the longest streak online.
  • How do time zones affect what counts as a day?
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, possibly unordered and with duplicates. Output: length of the longest run d, d+1, ..., d+k-1 where every day is present. Empty input gives 0. Target O(n) time....

High-Level Design

Put all days in a set. A day d is the start of a run exactly when d - 1 is not in the set. For each start, walk forward d+1, d+2, ... while present and record the length. Every day is visited at...


Submit Your Answer
Markdown supported