Update Per-Minute Reaction Counts and Sum Any Time Range
Last updated: November 29, 2026
Quick Overview
Given an array of reaction counts per minute for a live video, support update(index, value) and range_sum(left, right) on the inclusive range, with both operations efficient for up to a million minutes and queries.
Meta
November 29, 20260
0
0 solved
Given an array of reaction counts per minute for a live video, support update(index, value) and range_sum(left, right) on the inclusive range, with both operations efficient for up to a million minutes and queries.
Live video dashboards on Facebook show reaction totals over arbitrary ranges while late-arriving corrections update individual minutes. Meta interviewers use this to see whether you reach for a Fenwick or segment tree and can implement one correctly under pressure.
What the Interviewer Expects
- Compare prefix sums (fast query, slow update) with a tree
- Implement a Fenwick tree with lowbit arithmetic
- Keep the original values to turn set into a delta
- Build the tree in O(n) instead of n log n
- Test against a brute force on random inputs
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 support adding a delta to a whole range of minutes?
- How would you answer range max instead of range sum?
- How would you extend this to a 2D grid of regions by minutes?
- When would a sqrt decomposition be preferable?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
update(i, v)sets minuteitov.range_sum(l, r)returns the inclusive sum.- n and the number of operations up to 10^6; values may be negative after corrections....
High-Level Design
A plain prefix array answers queries in O(1) but every update is O(n). A Fenwick tree stores in tree[j] the sum of the j & -j values ending at position j (1-indexed). Adding a delta walks up by ...