Top K Recent Unique Values
Updated
Problem statement
Process the integers in accesses from oldest to newest while maintaining one occurrence of each distinct value in recency order.
When a value is accessed, remove its older position if it is already present, then make it the most recent value. Return up to the first k distinct values from most recent to least recent after every access has been processed.
Function
topKRecentUniqueValues(accesses: int[], k: int) → int[]Examples
Example 1
accesses = [1,2,3,2,4]k = 3return = [4,2,3]Reaccessing 2 moves it ahead of 3 and 1; the final access to 4 makes it most recent.
Example 2
accesses = [5,5,5]k = 5return = [5]The repeated value appears only once, and fewer than five distinct values exist.
Example 3
accesses = []k = 3return = []No values were accessed, so the recency list is empty.
Constraints
0 <= accesses.length <= 100000-1000000000 <= accesses[i] <= 10000000000 <= k <= 100000- If fewer than
kdistinct values exist, return all of them.
More Bloomberg LP Phone Screen 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
- Trapping Rain WaterPHONE 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
Similar questions at other companies
- Meta Copy List with Random PointerMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Deep Copy a Random-Pointer ListSuperhuman · PHONE SCREENSuperhuman interview questions
- Remove All Repeated Values from a Linked ListArista Networks · PHONE SCREENArista Networks interview questions
- Deep Copy a Random-Pointer ListAmazon · ONSITE INTERVIEW
- Pairs of Songs With Total Durations Divisible by 120Cashfree Payments · PHONE SCREEN
- LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
- LRU CacheAthenahealth · PHONE SCREEN
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog 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)