Days Until a Creator's Follower Count Beats Today's Total

Last updated: November 29, 2026

Quick Overview

Given a creator's daily follower totals, return for each day how many days later the total is first strictly higher, or 0 if it never is.

TikTok
Coding & Algorithms
Software Engineer
TikTok
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a creator's daily follower totals, return for each day how many days later the total is first strictly higher, or 0 if it never is.

This shows up in TikTok phone screens as a framing of creator analytics, such as 'days to recover after a follower dip'. The interviewer is checking whether you go past the O(n^2) double loop to a monotonic stack and can explain the invariant in one sentence.

What the Interviewer Expects
  • Mentions the brute force and its O(n^2) cost
  • Uses a stack of indices waiting for a higher value
  • Clearly states the stack invariant
  • Handles equal values correctly with strict comparison
  • Amortized linear argument
Key Topics to Cover
monotonic stack
next greater element
amortized analysis
arrays
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 number of days until the count drops below today instead.
  • Data arrives one day at a time; can you answer for past days online?
  • How would you find, for each day, the previous day with a higher count?
  • What if you need the first day at least 10% higher?
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, one per day. Output: same length list where wait[i] is the smallest j - i with j > i and followers[j] > followers[i], else 0. Equal totals do not count as higher....

High-Level Design

Scan left to right with a stack of day indices that have not yet seen a higher day. The values at those indices are non-increasing from bottom to top, because if a later day were higher than an earlie...


Submit Your Answer
Markdown supported