Answered step by step
Verified Expert Solution
Link Copied!

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.

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

Students also viewed these Databases questions

Question

Explain why we use y as an estimate of E(y) and to predict y.

Answered: 1 week ago

Question

Can workers be trained in ethics? How? Defend your answer.

Answered: 1 week ago