FastPrepDynamic Median with Additions and Deletions
Problems/Dynamic Median with Additions and Deletions

Dynamic Median with Additions and Deletions

ByteDance logoByteDance● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An earlier report that we kept gives balanced heaps, lazy deletion and counters for valid sizes, with follow-ups about a limited value range, approximation with limited memory, and concurrency. The current report only names a streaming median. Our version is about 85% the same as the reported question. Our choices: a finite list of add, remove and query operations, deleting a missing value does nothing, an empty query returns null, and answers are exact reduced fractions. The extra follow-ups are for discussion only.

Process operations on an integer multiset and return one result for every median query.

  • [1, x] adds one occurrence of x.
  • [2, x] removes one occurrence of x, or does nothing when x is absent.
  • [3] queries the current median.
  • For a nonempty multiset, return the median as a reduced numerator/denominator string with a positive denominator. For an empty multiset, return the literal string null.

Function

dynamicMedians(operations: int[][]) → String[]

Examples

Example 1

operations = [[1,5],[1,1],[3],[1,9],[3],[2,5],[3],[2,1],[2,9],[3]]return = ["3/1","5/1","5/1","null"]

The queried multisets are {1,5}, {1,5,9}, {1,9}, and the empty multiset.

Example 2

operations = [[1,2],[1,2],[1,8],[3],[2,2],[3],[2,2],[3],[2,2],[3]]return = ["2/1","5/1","8/1","8/1"]

Each deletion removes only one duplicate occurrence. The final deletion of absent value 2 is a no-op.

Constraints

  • 1 <= operations.length <= 200000.
  • Every operation is exactly [1, x], [2, x], or [3].
  • -1000000000 <= x <= 1000000000.

More ByteDance Onsite Interview questions

  • Search a Row- and Column-Sorted MatrixONSITE INTERVIEW · Seen Nov 2026
  • Alien DictionaryPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lexicographically Smallest Topological OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Implement Multi-Head AttentionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a String Key-Value StoreONSITE INTERVIEW · Seen Oct 2026
  • Binary Tree Maximum Path SumONSITE INTERVIEW · Seen Oct 2026
  • Merge Overlapping IntervalsONSITE INTERVIEW · Seen Oct 2026
  • Tic-Tac-Toe Move WinnersONSITE INTERVIEW · Seen Oct 2026
  • Kth Largest Element without a HeapONSITE INTERVIEW · Seen Oct 2026
  • Least Recently Used CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEW
  • Top K Upvoted Songs by ArtistAmazon · ONSITE INTERVIEW
  • LRU Cache with TTLAutodesk · ONSITE INTERVIEW
  • Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEW
  • Thread-Safe LRU Cache with TTLLinkedIn · ONSITE INTERVIEW
  • Top K Frequent Elements After Each Stream UpdateSalesforce · ONSITE INTERVIEW
  • Limit Order Book Matching EngineCitadel · PHONE SCREEN · ONSITE INTERVIEW
  • Task Scheduler with DependenciesScale AI · ONSITE INTERVIEW
  • Trade Volume LeaderboardBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
  • Design Authentication ManagerOracle · ONSITE INTERVIEW
See ByteDance hiring insights
Saved
class Solution {
    public String[] dynamicMedians(int[][] operations) {
        // Process add, remove, and median operations here.
    }
}
Checking account…