← 返回 roblox 的题目列表Highest Earning Experience Tracker
类型:online_judge
Highest Earning Experience Tracker
You are implementing a component for a real-time analytics system that tracks the cumulative earnings of experiences (e.g., games/features/events) and can report the currently highest-earning experience at any time.
You are given three arrays of equal length:
operations: an array of characters containing only 'U' (Update) or 'Q' (Query)
experiences: an array of strings where experiences[i] is the experience name involved in operations[i]
deltas: an array of integers
if operations[i] == 'U', then deltas[i] is the profit delta to add (can be positive or negative)
if operations[i] == 'Q', then deltas[i] is unused
Process the operations in order and return the results of all Query operations, in the same order as they occur.
Operation semantics
Update ('U'): add deltas[i] to the cumulative earnings of experiences[i]
Query ('Q'): return the name of the experience with the highest cumulative earnings at that moment
Output
Return a list of strings containing the answer to each Query.
Constraints (typical interview assumptions if not explicitly provided)
1 <= n = len(operations) == len(experiences) == len(deltas) <= 2e5
deltas[i] in a range like [-1e9, 1e9]
experience names are reasonable length (e.g., <= 50)
Tests
Input:
operations = ["U","U","Q","U","Q"]
experiences = ["A","B","_","A","_"]
deltas = [10, 5, 0, -3, 0]
Output: ["A","A"]
Input:
operations = ["U","U","Q"]
experiences = ["x","y","_"]
deltas = [1, 2, 0]
Output: ["y"]
Input:
operations = ["U","Q","U","Q"]
experiences = ["same","_","same","_"]
deltas = [5, 0, 5, 0]
Output: ["same","same"]
Input:
operations = ["U","U","U","Q"]
experiences = ["a","b","c","_"]
deltas = [0, 0, 0, 0]
Output: ["a"] (if ties occur, define and state a tie-break rule)
Input:
operations = ["U","U","Q","U","Q"]
experiences = ["p","p","_","q","_"]
deltas = [3, -10, 0, 1, 0]
Output: ["p","q"]
Example
Input
U
5
A 10
B 5
_ 0
A -3
_ 0
Output
A
A