Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 . LRU CacheGiven n request ids as an array of strings,requests, and an integer k after all requests arereceived, find the kmost recent requests.
LRU CacheGiven n request ids as an array of strings,requests, and an integer k after all requests arereceived, find the kmost recent requests. Reportthe answer in order of most recent to leastrecent.Example:Suppose n requests item"item "itemitem "item and kStarting from the right and moving left, collectingdistinct requests, there isitem followed byitem Skip the second instance of "item andfind "item The answer is item "itemitemFunction DescriptionComplete the function getLatestKRequests in theeditor below.getLatestKRequests takes the followingarguments:str requestsn: the request idsint k: the number of requests to reportReturnsstrkj: the kmost recent requestsConstraintssksnsrequestsij consists of lowercase characters anddigits only, azInput Format For Custom TestingThe first line contains an integer, n the numberof elements inrequestsiEach of the nextnlines contains a string,The next line contains an integer, kSample Case STDINSample Input For Custom Testingitemitemitemwitem "item"Sample Outputitemitemwitorrequests.itemlExplanationv Sample Case STDINtemlpreceded by "iten;FUNCTIONThe last request is "item preceded by "itemSample Outputitemlrequests size n EXplanationrequests itemkSample Input For Custom Testing"item itemFUNCTIONrequests size nrequests i temkly request to be reported is "itemLanguage C#include cassert.hC Complete the 'getLatestKRequests! function below, The The function is expected to return a STRING ARRAYfuncti on accepts following parameters:STRTNCINTEGER KTest ResultsINGARRAY requests For example,To return the string array from the function, you should:Store the size of the array to be returned in the resultcount variableAllocate the array statically or dynami cally chark returnstringarrayusingstaticallocation int resultcount resultcount ;return a:static char a static "allocation", of "string" "array" ;resultcount ;VOEnvironmentchar returnstringarrayusingdynamicallocation int resultcountchar amal loc sizeof char:;for int i ; i; itaa ea a a a int mainreturn a:GAutocomplete Readyi malloc sizeofchar;"dyac";Location";"of : "string":"array" ;char getLatestKRequestsint requestscount, char requests, int K int resultcOuntCustom inputRun CodeLine: col:Run TestsSubi t
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started