Description
Solutions
Get Latest K Requests 🌿
🔥 FULLTIME📚RELATED PROBLEMS
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 Description
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
Example 1:
Input: requests = ["item1", "item2", "item3", "item1", "item3"], k = 3
Output: ["item3", "item1", "item2"]
Explanation: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! 🥰

Related Problems
Testcase
Result
Case 1
input:
output: