FastPrepInsert Delete GetRandom O(1) - Duplicates Allowed
Problems/Insert Delete GetRandom O(1) - Duplicates Allowed

Insert Delete GetRandom O(1) - Duplicates Allowed

Bloomberg LP logoBloomberg LP● HardNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a firsthand Bloomberg software-engineer phone interview. In our version, GetRandom is only called when every stored copy has the same value. That makes the output fixed, and you still need the O(1) design.

Process commands on a multiset supporting average O(1) insertion, removal, and uniform random sampling over stored occurrences.

  • insert x adds one occurrence and returns true exactly when x was previously absent.
  • remove x removes one occurrence and returns whether removal occurred.
  • getRandom returns a uniformly random stored occurrence.

Return one string result per command. So that the answer is fixed, every getRandom command comes when all stored occurrences have the same value.

Function

processRandomizedCollection(operations: String[]) → String[]

Examples

Example 1

operations = ["insert 1","insert 1","insert 2","remove 1","remove 2","getRandom"]return = ["true","false","true","true","true","1"]

The inserts and removes leave exactly one copy of 1 in the collection, so getRandom has only that value to return.

Constraints

  • 1 <= operations.length <= 10^4.
  • Every getRandom is issued on a nonempty collection whose distinct-value count is one.

More Bloomberg LP Phone Screen questions

  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Randomized String MultisetLinkedIn · PHONE SCREENLinkedIn interview questions
  • Randomized Collection with Duplicate ValuesOkta · ONSITE INTERVIEWOkta interview questions
  • Chatter Message WindowReddit · PHONE SCREENReddit interview questions
  • Versioned Recipe Shopping CartDecagon · PHONE SCREENDecagon interview questions
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Insert Delete GetRandom O(1)Charta Health · PHONE SCREENCharta Health interview questions
  • Portfolio Tickers with Constant-Time Random PickCitadel · PHONE SCREENCitadel interview questions
  • Build a Pivot Table with TotalsSigma Computing · PHONE SCREEN
  • Process On-Call Routing OperationsOpenAI · PHONE SCREENOpenAI interview questions
  • Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
  • Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public String[] processRandomizedCollection(String[] operations) {
      // Write your code here.
    }
}
Checking account…