Question: 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.

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. Reportthe answer in order of most recent to leastrecent.Example:Suppose n =5, requests = item1","item2", "item3)"item1", "item3"], and k=3Starting from the right and moving left, collectingdistinct requests, there is"item3" followed by"item1". Skip the second instance of "item3 andfind "item2". The answer is ["item3, "item1""item2".Function DescriptionComplete the function getLatestKRequests in theeditor below.getLatestKRequests takes the followingarguments:str requests[n]: the request idsint k: the number of requests to reportReturnsstr(kj: the kmost recent requestsConstraints1sksns105requests[ij consists of lowercase characters anddigits only, [a-z,0-9].Input Format For Custom TestingThe first line contains an integer, n, the numberof elements inrequests[i.Each of the nextnlines contains a string,The next line contains an integer, k.Sample Case 0STDINSample Input For Custom Testingitem2item3item3witem2", "item1"Sample Outputitem3item2witorrequests.itemlExplanationv Sample Case 1STDIN7temlpreceded by "iten1";FUNCTIONThe last request is "item3" preceded by "item2",Sample Outputitemlrequests[] size n 5EXplanationrequests =["item3",kSample Input For Custom Testing"item2", item3"]FUNCTIONrequests[] size n1requests =["i tem1"]k=ly request to be reported is "item1.Language C192122232425262728293031321)#include cassert.h>333334C46474849505152535856575862696364* Complete the 'getLatestKRequests! function below,* The* The function is expected to return a STRING ARRAY**functi on accepts following parameters:STRTNCINTEGER KTest ResultsING_ARRAY requests* For example,To return the string array from the function, you should:Store the size of the array to be returned in the result_count variableAllocate the array statically or dynami cally* chark* return_string_array_usingstatic_allocation (int * result_count ){*result_count =5;return a:static char* a [5]=("static", "allocation", "of", "string" , "array"} ;*result_count 5;VOEnvironmentchar** return_string_array_using_dynamic_allocation (int* result_count)(char** amal loc (5* sizeof (char:));for (int i =0; i5; it+)*(a*(a + e)(a 1)*(a +2)*(a +3)*(a +4)66> int main()*return a:GAutocomplete Readyi) malloc (20* sizeof(char));"dyac";Location";"of" := "string":"array" ;char** getLatestKRequests(int requests_count, char** requests, int K, int* result_cOunt)Custom inputRun CodeLine: 19 col:Run TestsSubi t
 1. LRU CacheGiven n request ids as an array of strings,requests,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!