Segment Queries
Problem Overview
- Given arrays cat[n] and cnt[n], answer q queries on ranges [l[i], r[i]] by summing, within each range, the maximum cnt per unique category in cat, then clear cnt in that range.
- Inputs: cat, cnt, and 1-based query arrays l and r; Output: an array of q integers with results in order.
- Models segment analytics over categorized counts where categories can repeat across positions.
- This is a TikTok coding interview problem and a common interview question on array range queries.
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
