K Most Recent Unique Request IDs
Updated
Problem statement
You are given an array of request IDs, requests, and an integer k. The end of requests represents the most recent request.
A request ID may appear more than once. Scan requests from right to left and collect each distinct request ID the first time you encounter it. Stop after collecting k distinct IDs.
Return the collected request IDs in order from most recent to least recent.
Function
getMostRecentUniqueRequests(requests: String[], k: int) → String[]Examples
Example 1
requests = ["item1","item2","item3","item1","item3"]k = 3return = ["item3","item1","item2"]Scanning from right to left first collects "item3" and then "item1". The next "item3" is skipped because it has already been collected. Collecting "item2" produces the required three distinct IDs.
Constraints
1 <= k <= requests.length <= 10^5requestscontains at leastkdistinct request IDs.- Every
requests[i]consists only of lowercase English letters and digits.
Source note: The source frame shows the complete task, constraints, and example.
More Microsoft Online Assessment questions
- Maximum Score with Prime JumpsOA · Seen Dec 2026
- Minimum Non-Adjacent Selection CapabilityOA · Seen Dec 2026
- Authentication SystemOA · Seen Nov 2026
- Maximum String OperationsOA · Seen Nov 2026
- Minimum Cost to Process Priority TasksOA · Seen Nov 2026
- Most Visited Sprint MarkerOA · Seen Nov 2026
- Maximum Escape Game ScoreOA · Seen Nov 2026
- Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
- Maximum Interactive Team SizeOA · Seen Nov 2026
- Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
Similar questions at other companies
- Macaron Order with Set DiscountsShopify · OAShopify interview questions
- Build the Task HierarchyPendo · OA
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Count Valid Square PairsAuxoAI · OA
- Two SumAmazon · OA · PHONE SCREEN
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
- Customer Signer ScreeningState Farm · OA
- Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)