Random Removal from a Set
Updated
Problem statement
Given values and choices, return the selected values in order after the following removals.
Start with a dense set of the distinct integers in values, stored in an array with no gaps between active entries. Each entry in choices is a zero-based random index into the current array. Zero-based means the first position has index zero.
Select the value at that index and add it to the result. Remove it in O(1) time by moving the current last value into its slot and shortening the array.
Function
randomRemovalSequence(values: int[], choices: int[]) → int[]Examples
Example 1
values = [1,4,7,9]choices = [2,0]return = [7,1]Index 2 selects 7, and 9 moves into that slot. Index 0 then selects 1 from the updated array.
Constraints
- Values are distinct.
choices.length <= values.length.- Each choice is valid for the current size.
More Bloomberg LP Onsite Interview questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Escape Room LeaderboardPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
- Insert, Delete, And Get Random In Constant TimeAmazon · ONSITE INTERVIEW
- Insert, Delete, And Get Random In Constant TimeGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Future-Effective Employee SalaryRippling · ONSITE INTERVIEWRippling interview questions
- Array With Set AllMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Constant-Time Key Store Built on ArraysPatreon · ONSITE INTERVIEWPatreon interview questions
- Randomized Collection with Duplicate ValuesOkta · ONSITE INTERVIEWOkta interview questions
- Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Bank Accounts with Balance HistoryMeta · OAMeta 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)