Count Later Videos With Lower Engagement Than Each Video

Last updated: November 29, 2026

Quick Overview

Given a creator's videos in posting order with integer engagement scores, return for each video how many videos posted after it have a strictly lower score. The list can have up to 10^5 videos, so a quadratic scan is too slow.

TikTok
Coding & Algorithms
Software Engineer
TikTok
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given a creator's videos in posting order with integer engagement scores, return for each video how many videos posted after it have a strictly lower score. The list can have up to 10^5 videos, so a quadratic scan is too slow.

Creator analytics at TikTok compare each post against later performance to describe momentum, and this onsite question tests whether you know an ordered structure that supports rank queries. The interviewer looks for a Fenwick tree or merge sort solution with coordinate compression and clear reasoning about duplicates.

What the Interviewer Expects
  • Rejects the O(n^2) scan given the input size
  • Scans from right to left, querying how many smaller values were already seen
  • Uses coordinate compression so the Fenwick tree size is the number of distinct values
  • Handles duplicates by querying strictly smaller ranks
  • Mentions merge sort counting as an alternative with the same complexity
Key Topics to Cover
Fenwick tree
coordinate compression
ordered sets
inversion counting
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 count later videos with a score at most half of the current one?
  • How would you answer this for a sliding window of the next 100 videos only?
  • How would you parallelize it for billions of videos across creators?
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 scores, possibly negative or repeated.
  • Output: list counts where counts[i] is the number of j > i with scores[j] < scores[i].
  • n up to 10^5....
High-Level Design

Walk from right to left. Everything to the right is already inserted into a structure that can answer "how many inserted values are less than x". A Fenwick tree (binary indexed tree) over value ranks ...


Submit Your Answer
Markdown supported