PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Roblox
  • Coding & Algorithms
  • Software Engineer

Track Highest-Earning Experience

Company: Roblox

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are building a core component for a real-time analytics system that tracks the profitability of experiences on a large online platform. Implement a function that processes a sequence of operations and returns the result of each query. You are given three arrays of equal length: - `operations[i]`: either `'U'` for an update or `'Q'` for a query - `experiences[i]`: the name of the experience involved in operation `i` - `deltas[i]`: the profit change for the experience if `operations[i] == 'U'`; otherwise this value is ignored Rules: - For an update operation `'U'`, add `deltas[i]` to the current total earnings of `experiences[i]` - For a query operation `'Q'`, return the name of the experience with the highest total earnings at that moment - If an experience has not been updated before, treat its earnings as `0` before applying its first update - If multiple experiences are tied for the highest earnings, returning any one of them is acceptable - You may assume each query happens after at least one update Return an array containing the answers for all query operations, in order. Example: - `operations = ['U', 'U', 'Q', 'U', 'Q']` - `experiences = ['GameA', 'GameB', '', 'GameA', '']` - `deltas = [5, 7, 0, 4, 0]` Processing: - Update `GameA` by `+5` → totals: `GameA = 5` - Update `GameB` by `+7` → totals: `GameB = 7` - Query → return `GameB` - Update `GameA` by `+4` → totals: `GameA = 9` - Query → return `GameA` Output: `['GameB', 'GameA']` Design an efficient solution for processing many updates and queries.

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.

You are building a real-time analytics component for an online platform. Given a sequence of update and query operations, return the answer for each query. You are given three arrays of equal length: - operations[i]: either 'U' for an update or 'Q' for a query - experiences[i]: the experience name involved in operation i - deltas[i]: the profit change if operations[i] == 'U'; otherwise it is ignored Processing rules: - For an update 'U', add deltas[i] to the current total earnings of experiences[i] - For a query 'Q', return the name of the experience with the highest total earnings at that moment - If an experience is updated for the first time, its previous total is 0 - If multiple experiences are tied for the highest earnings, any one of them is acceptable - Queries only consider experiences that have been updated at least once so far - You may assume every query happens after at least one update Return a list containing the answers to all query operations in order.

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

  1. Use a hash map to store the current total earnings for each experience.
  2. 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.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Windows Containing a Target - Roblox (medium)
  • Implement Sliding-Window Rate Limiter - Roblox (medium)
  • Find target-heavy sliding windows - Roblox (medium)
  • Find most frequent call path in logs - Roblox (medium)
  • Find the Most Frequent Log Call - Roblox (easy)