Track Highest-Earning Experience
Company: Roblox
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates the ability to maintain and query aggregated state with frequent updates, focusing on data structures for efficient real-time tracking of maximum values and dynamic key-value aggregations in the coding and algorithms domain.
Constraints
- 1 <= len(operations) == len(experiences) == len(deltas) <= 200000
- operations[i] is either 'U' or 'Q'
- For update operations, experiences[i] is a non-empty string
- -10^9 <= deltas[i] <= 10^9
- Each query occurs after at least one update
Examples
Input: (['U', 'U', 'Q', 'U', 'Q'], ['GameA', 'GameB', '', 'GameA', ''], [5, 7, 0, 4, 0])
Expected Output: ['GameB', 'GameA']
Explanation: GameA becomes 5, GameB becomes 7, so the first query returns GameB. After GameA is updated by 4, it becomes 9, so the second query returns GameA.
Input: (['U', 'U', 'U', 'Q', 'U', 'Q'], ['A', 'B', 'A', '', 'B', ''], [10, 8, -5, 0, -10, 0])
Expected Output: ['B', 'A']
Explanation: A goes 0->10->5, B goes 0->8->-2. After the third update, B has the highest total (8). After B decreases to -2, A has the highest total (5).
Input: (['U', 'Q'], ['Solo', ''], [0, 0])
Expected Output: ['Solo']
Explanation: There is only one updated experience, and its total is 0, so the query returns Solo.
Input: (['U', 'U', 'Q', 'U', 'Q'], ['X', 'Y', '', 'Y', ''], [4, 4, 0, 1, 0])
Expected Output: ['X', 'Y']
Explanation: After the first two updates, X and Y are tied at 4. Any tied answer is acceptable; this reference solution returns X because of its deterministic heap ordering. After Y increases to 5, the next query returns Y.
Input: (['U', 'Q', 'U', 'Q'], ['Loss', '', 'Gain', ''], [-3, 0, 2, 0])
Expected Output: ['Loss', 'Gain']
Explanation: After the first update, Loss is the only tracked experience, so it is returned even though its total is negative. After Gain reaches 2, it becomes the highest earner.
Hints
- Use a hash map to store the current total earnings for each experience.
- A single max variable is not enough if an update can decrease an experience's total. Consider a max-heap with lazy removal of outdated totals.