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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample Answer
Requirements
- Input: list of ints
scores, possibly negative or repeated. - Output: list
countswherecounts[i]is the number ofj > iwithscores[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 ...