Complete the finestFoodOutlet function below.
The function is expected to return a STRING.
The function accepts the following parameters:
STRING cityINTEGER votes
API URL: https://jsonmock.hackerrank.com/api/food_outlets?city={city}&page={page_no}
Use the HTTP GET method to retrieve information from a database of food outlets. Query https://jsonmock.hackerrank.com/api/food_outlets?city=<city> to find all the records for a city. The query result is paginated. To access additional pages, append &page=<num> to the URL where num is the page number.
The response is a JSON object with the following fields:
page: The current page of the results.per_page: The maximum number of results returned per page.total: The total number of results.total_pages: The total number of pages with results.data: Either an empty array or an array with a single object that contains the food outlets’ records.
In data, each food outlet has the following schema:
id: outlet idname: The name of the outletcity: The city in which the outlet is locatedestimated_cost: The estimated cost of the food in the particular outletuser_rating: An object containing the user ratings for the outletaverage_rating: The average user rating for the outletvotes: The number of people who voted for the outlet
Given the city name as city and minimum vote count as votes, filter the results by city name. Find the food outlet with the highest rating and whose vote count is greater than or equal to the required minimum votes. In case of a tie in the rating, return the one with the maximum vote count.
Function Description
Complete the function finestFoodOutlet in the editor below.
finestFoodOutlet has the following parameter(s):
string city: name of the city whose outlets have to be filteredinteger votes: number of votes
Returns
string: the winning restaurant
Input Format For Custom Testing
The first line contains the string, city.
The second line contains an integer, votes.
Sample Input For Custom Testing
Seattle
500
Sample Output
Cafe Juanita
Explanation
In Seattle, results are filtered to those with votes >= 500. There are 4 food outlets whose rating is 4.9. Cafe Juanita has 16203 votes.
This problem combines paginated API handling, filtering, and tie-breaking selection. You need to fetch all pages for the given city, keep only outlets whose vote count meets the minimum threshold, and choose the one with the highest average rating. If multiple outlets share the same rating, pick the one with the larger vote count. The sample shows that even when several outlets have a top rating, the answer is determined by the vote-based tie breaker.