Online Streak Span of Days With Lower or Equal DAU

Last updated: November 29, 2026

Quick Overview

Design a class that receives one daily active user count at a time and, for each new day, returns how many consecutive days ending today had a DAU less than or equal to today's value.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Design a class that receives one daily active user count at a time and, for each new day, returns how many consecutive days ending today had a DAU less than or equal to today's value.

This appears in Meta onsites as a small streaming design question tied to growth dashboards that annotate how long a metric has been at or below today's level. The interviewer wants an amortized O(1) online solution and a clear explanation of what the stack stores.

What the Interviewer Expects
  • Define the span precisely, including today itself
  • Store (value, span) pairs on a decreasing stack
  • Merge popped spans into today's span
  • Prove amortized O(1) per call
  • Discuss memory for a very long-running stream
Key Topics to Cover
Monotonic stack
Streaming
Amortized analysis
Class design
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 support querying the span for an arbitrary past day?
  • What if counts can be revised later (late-arriving data)?
  • Can you bound memory if spans are capped at 365 days?
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

Implement DauSpan with next(count) -> int. The return value is the number of consecutive days, ending with and including today, whose counts are less than or equal to count. Calls arrive in day ...

High-Level Design

Keep a stack of (value, span) pairs where values are strictly decreasing from bottom to top. A pair's span says how many consecutive days it already absorbed. When a new count arrives, start with sp...


Submit Your Answer
Markdown supported