Highest-Earning Experience Tracker
Learn this problemProblem statement
You are building a core component of a real-time analytics system that monitors the profitability of experiences (games, features, events) on a large online platform. The component must efficiently track the current highest-earning experience as profit changes over time.
You will receive a stream of operations of two types:
- Update — adjust the profit of an experience by some delta (can be positive or negative).
- Query — return the name of the experience with the highest total earnings at that moment.
The stream is given as three equal-length arrays:
operations[i]— either"U"(update) or"Q"(query).experiences[i]— the name of the experience involved in operationi. For a query operation, this value is unused and may be the empty string.deltas[i]— for an update, the signed change to that experience's profit. For a query, the value is unused.
Return an array containing the result of every Query operation, in the order the queries appear.
Tie-break. If two or more experiences are tied for the highest total earnings at the time of a query, return the lexicographically smallest name among them.
If a query is issued before any Update has occurred, return the empty string for that query.
The interviewer explicitly asked for a heap-based solution: a single hash map gives O(1) updates but O(N) queries, and a max-heap keyed by total earnings is what keeps query time fast. Because heap entries become stale when an experience's total changes, the heap must support lazy deletion (push the new total and discard outdated entries when they surface at the top).
Function
highestEarningExperience(operations: String[], experiences: String[], deltas: int[]) → String[]Examples
Example 1
operations = ["U", "U", "Q", "U", "Q"]experiences = ["adopt-me", "blox-fruits", "", "adopt-me", ""]deltas = [100, 200, 0, 150, 0]return = ["blox-fruits", "adopt-me"]Example 2
operations = ["U", "U", "Q"]experiences = ["beta", "alpha", ""]deltas = [50, 50, 0]return = ["alpha"]Example 3
operations = ["U", "U", "Q", "U", "Q"]experiences = ["x", "x", "", "x", ""]deltas = [100, -30, 0, -100, 0]return = ["x", "x"]Constraints
1 <= operations.length <= 10^5operations.length == experiences.length == deltas.lengthoperations[i]is either"U"or"Q".- Experience names consist of lowercase letters, digits, and
-, with1 <= name.length <= 32. -10^6 <= deltas[i] <= 10^6.- For a
"Q"operation,experiences[i]anddeltas[i]are unused (may be""and0).
More Roblox problems
- Most Frequent Call Stack Per ThreadPHONE SCREEN · Seen Jul 2026
- Break a PalindromeOA · Seen Jun 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · Seen Jun 2026
- Closest Binary Search Tree Value — Base PracticePHONE SCREEN · Seen Jun 2026
- Design Search Autocomplete SystemPHONE SCREEN · Seen Jun 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · Seen Jun 2026
- Maximize Distance to Closest Person — Return the SeatONSITE INTERVIEW · Seen Jun 2026
- Maximum Number of Balls in a BoxPHONE SCREEN · Seen Jun 2026