Problem ยท Array
Get Latest K Requests ๐ฟ
Learn this problemProblem statement
Given n request ids as an array of strings, requests, and an integer k, after all requests are received, find the k most recent requests. Report the answer in order of most recent to least recent.
Function
getLatestKRequests(requests: String[], k: int) โ String[]
Complete the function getLatestKRequests in the editor below.
getLatestKRequests takes the following arguments:
str requests[n]: the request idsint k: the number of requests to report
Returns
str[k]: the k most recent requests
Examples
Example 1
requests = ["item1", "item2", "item3", "item1", "item3"]k = 3return = ["item3", "item1", "item2"]Starting from the right and moving left, collecting distinct requests, there is "item3" followed by "item1". Skip the second instance of "item3" and find "item2". The answer is ["item3", "item1", "item2"].
Constraints
Unknown for now. If you happen to know about it, feel free to lmk. Many thanks in advance! ๐ฅฐMore IBM problems
- Parent Process NumberOA ยท Seen Jul 2026
- Request Retry CountOA ยท Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA ยท Seen Jul 2026
- Maximum Requests in a Time WindowOA ยท Seen Jul 2026
- Query Type Frequency WindowOA ยท Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA ยท Seen Jul 2026
- Spam Text ClassificationOA ยท Seen Jul 2026
- Count Ideal NumbersOA ยท Seen Jun 2026