1/56 In this challenge, the REST API contains information about a collection of users and articles they created. Given the threshold value, the goal is to use the API to get the list of most active authors. Specifically, the list of usernames of users with submission count strictly greater than the given threshold. The list of usernames must be returned in the order the users appear in the results. To access the collection of users perform HTTP GET request to: https://jsonmock.hackerrank.com/api/article_users?page= <pageNumber> where <pageNumber> is an integer denoting the page of the results to return. For example, GET request to: https://jsonmock.hackerrank.com/api/article_users/search?page=2 will return the second page of the collection of users. Pages are numbered from 1, so in order to access the first page, you need to ask for page number 1. The response to such request is a JSON with the following 5 fields: page : The current page of the results per_page : The maximum number of users returned per page. total : The total number of users on all pages of the result. total_pages : The total number of pages with results. data : An array of objects containing users returned on the requested page Each user record has the following schema: id : unique ID of the user username : the username of the user about : the about information of the user submitted : total number of articles submitted by the user updated_at : the date and time of the last update to this record submission_count : the number of submitted articles that are approved comment_count : the total number of comments the user made created_at : the date and time when the record was created Function Description Complete the function getUsernames in the editor below. Question - 1 Most Active Authors SCORE: 75 points REST API Back-End Development Medium JSON EY Back-End Sr Developer (... 140 minutes 2/56 getUsernames has the following parameter(s): threshold: integer denoting the threshold value for the number of submission count The function must return an array of strings denoting the usernames of the users whose submission count is strictly greater than the given threshold. The usernames in the array must be ordered in the order they appear in the API response. Input Format For Custom Testing In the first line, there is an integer threshold Sample Case 0 Sample Input For Custom Testing 10 Sample Output epaga panny olalonde WisNorCan dmmalam replicatorblog vladikoff mpweiher coloneltcb guelo Explanation The threshold value is 10, so the result must contain usernames of users with the submission count value greater than 10. There are 10 such users and their usernames in the order they first appear in the API response are as listed in Sample Output. A REST API contains information about food outlets across multiple cities. Given the city name, and maximum cost for 2 persons, the goal is to use the API to get the list of food outlets that belong to this city and have an estimated cost less than or equal to given cost. The API returns paginated data. To access the information, perform an HTTP GET request to: https://jsonmock.hackerrank.com/api/food_outlets? city=<city>&page=<pageNumber> where < city > is the city to get the food outlets for and <pageNumber> is an integer that denotes the page of the results to return. For example, a GET request to https://jsonmock.hackerrank.com/api/food_outlets? city=Seattle&page=2 Question - 2 REST API: Relevant Food Outlets SCORE: 75 points REST API Back-End Development Medium JSON 3/56 returns data associated with city Seattle , and on the second page of the results. Similarly, a GET request to https://jsonmock.hackerrank.com/api/food_outlets? city=Houston&page=1 returns data associated with city Houston , and on the first page of the results. The response to such a request is a JSON with the following 5 fields: page : The current page of the results. per_page : The maximum number of records returned per page. total : The total number of records in the database. total_pages : The total number of pages with results. data : Either an empty array or an array of outlet objects. Each object has the following schema: city : city we queried for where the outlet is located [STRING] name : name of the outlet [STRING] estimated_cost : estimated cost for 2 persons [INTEGER] user_rating: average_rating : average rating of the outlet [FLOAT] votes : total votes for the outlet [INTEGER] id : unique identifier of the outlet [INTEGER] Below is an example of an outlet object: { "city": "Houston", "name": "Cocoa Tree", "estimated_cost": 10, "user_rating": { "average_rating": 4.5, "votes": 969 }, "id": 938 }, Given a string city , numerical maximum cost for 2 persons maxCost, return the list of food outlet names that are located in this city and have an estimated cost less than or equal to given maxCost. Function Description Complete the function getRelevantFoodOutlets in the editor below. Please perform pagination in order to get all the results. getRelevantFoodOutlets has the following parameter(s): string city: string denoting the city of the food outlet int maxCost: max cost for 2 people Returns An array of strings denoting the food outlet names that are located in this city and have an estimated cost less than or equal to given maxCost. The names in the array must be ordered in the order they appear in the API response. 4/56 Constraints The given city will always have data returned from the API. Note : Required libraries can be imported in order to solve the question. Check our full list of supported libraries at https://www.hackerrank.com/environment. Input Format For Custom Testing In the first line, there is a string, city. In the second line, there is an integer, maxCost Sample Case 0 Sample Input For Custom Testing STDIN Function ----- -------- Denver → city = 'Denver' 50 → maxCost = 50 Sample Output BKC DIVE Vedge Explanation The function makes paginated calls to the api https://jsonmock.hackerrank.com/api/food_outlets? city=Denver&page=1 https://jsonmock.hackerrank.com/api/food_outlets? city=Denver&page=2 and so on, to get all the food outlets in Denver city. It returns the outlets for which estimated_cost is less than or equal to the given maxCost 50. The list of outlets is then printed by the stub code. Sample Case 1 Sample Input For Custom Testing Houston 30 Sample Output Nasi And Mee Zaatar Arabic Restaurant Milano Ice Cream Thaal Kitchen Alakapuri Nawras Seafood Restaurant Brindhavan Vegetarian Restaurant Mustake Multicuisine Restaurant Cocoa Tree Explanation The function makes paginated calls to the api https://jsonmock.hackerrank.com/api/food_outlets? city=Houston&page=1, https://jsonmock.hackerrank.com/api/food_outlets? city=Houston&page=2 and so on, to get all the food outlets in Houston city. It returns the outlets for which estimated_cost is less than or equal to the given maxCost 30. The list of outlets is then printed by the stub code. 5/56 In this challenge, the REST API contains information about a collection of articles. Given a limit value, the goal is to return articles ordered by the number of comments they have and limited to the first ones in that order by the given limit value. To access the collection of users perform HTTP GET request to: https://jsonmock.hackerrank.com/api/articles?page=<pageNumber> where <pageNumber> is an integer denoting the page of the results to return. For example, GET request to: https://jsonmock.hackerrank.com/api/articles?page=2 will return the second page of the collection of articles. Pages are numbered from 1, so in order to access the first page, you need to ask for page number 1. The response to such request is a JSON with the following 5 fields: page : The current page of the results per_page : The maximum number of users returned per page. total : The total number of users on all pages of the result. total_pages : The total number of pages with results. data : An array of objects containing users returned on the requested page Each user record has the following schema: title : The title of the article. Can be null url : the URL of the article author : the username of the author of the article num_comments : the number of comments the article has. Can be null. If it is null, the article has no comments, which means it has 0 comments. story_id : identifier of the story related to the article. Can be null story_title : the title of the story related to the article. Can be null story_url : the URL of the story related to the article. Can be null parent_id : identifier of the parent of the article. Can be null created_at : the date and time when the record was created If both the title and the story title of an article are null, then we ignore such an article. Otherwise, let the name of an article be its title if the title is not null. Otherwise, if the title is null, let the name be the story_title of the article. Given the limit value, the goal is to return an array of names of articles ordered by the number of comments they have and limited to the first ones in that order by the given limit value. If two articles have the same number of comments, the ones with the smallest name, in dictionary order, comes first. Question - 3 Top Articles SCORE: 75 points REST API Back-End Development Medium JSON 6/56 Function Description Complete the function topArticles in the editor below. topArticles has the following parameter(s): limit : integer denoting the maximum number of articles to return The function must return an array of strings denoting the names of articles ordered by the number of comments they have and limited to the first ones in that order by the given limit value. Input Format For Custom Testing In the first line, there is an integer limit Sample Case 0 Sample Input For Custom Testing 2 Sample Output UK votes to leave EU F.C.C. Repeals Net Neutrality Rules Explanation The limit value is 2 so we are interested in the names of the first two articles with the most number of comments. Those top articles are: 1. title : F.C.C. Repeals Net Neutrality Rules, story_title : null, num_comments : 1397 2. title : UK votes to leave EU, story_title : null, num_comments : 2531 and their names are their titles because they are not null. The second of these articles have more comments, so, it comes the first in the order. Therefore, the first element of the answer is "UK votes to leave EU" and the second element is "F.C.C. Repeals Net Neutrality Rules". Write an HTTP GET method to retrieve information from the articles and article_users databases. There may be multiple pages that are accessed by appending &page=num where num is replaced with the page number. Function Description Given a string of author , getAuthorHistory must perform the following tasks: 1. Initialize the history array to store a list of string elements. 2. Query https://jsonmock.hackerrank.com/api/article_u sers?username=<authorName> (replace <authorName>) to retrieve author information in the data field. Question - 4 Author Information SCORE: 75 points REST API Back-End Development Medium JSON 7/56 3. Store the value of the about field from the query response. If the about field is empty or null, do not store a value for this item. 4. Query https://jsonmock.hackerrank.com/api/articles? author=<authorName> (replace <authorName>), to retrieve the list of author's articles in the data field. 5. Add the title from each record returned in the data field to the history array. If the title field is null or empty then use the story_title to add in the history array. If the title and story_title fields are null or empty then ignore the record to add in the history array. 6. Based on the total_pages count, fetch all the data (pagination), and repeat steps 4 and 5. 7. Return the history array. The query response from the website is a JSON response with the following five fields: page : the current page per_page : the maximum number of results per page total : the total number of records in the search result total_pages : the total number of pages which must be queried to get all the results data : an array of JSON objects that contain article information Schema There are 2 tables: ARTICLE_USERS and ARTICLES. ARTICLE_USERS ARTICLE_USERS Name Type Description id LONG This is the first column. unique identifier number for the article user username STRING the author-name about STRING description (about) of the author submission_count LONG total number of submission comment_count LONG total number of comments for the articles created_at STRING created time of the article updated_at LONG updated time of the article ARTICLES Name Type Description title STRING the title of the article url STRING URL of the article author STRING the author name of the article num_comments LONG total number of comments 8/56 story_id LONG unique identifier number for the article story_title STRING an additional title for the article story_url STRING an additional URL for the article parent_id LONG unique identifier number of the parent article created_at LONG created time of the article Sample Case 0 Sample Input For Custom Testing epaga Sample Output Java developer / team leader at inetsoftware.de by day<p>iOS developer by night<p>http://www.mindscopeapp.com<p>http://infl ightassistant.info<p>http://appstore.com/johngoer ing<p>[ my public key: https://keybase.io/johngoering; my proof: https://keybase.io/johngoering/sigs/I1UIk7t3PjfB5 v2GI-fhiOMvdkzn370_Z2iU5GitXa0 ] <p>hnchat:oYwa7PJ4Yaf1Vw9Om4ju A Message to Our Customers “Was isolated from 1999 to 2006 with a 486. Built my own late 80s OS” Apple’s declining software quality Explanation id username abo 1 epaga Java developer / team leader at inetso night<p>http://www.mindscopeapp.com<p>http:/ ngoering<p>[ my public key: https:// https://keybase.io/johngoering/sigs/I1UIk7t <p>hnchat:oYwa7PJ4Yaf1Vw9Om4juJava d 3 saintamh 5 olalonde olalonde@gmail.com<p>http://www.github.com/o ARTICL title url author num_commen A Message to Our Customers null epaga 967 “Was isolated from 1999 to 2006 with a 486. Built my own late 80s OS” null epaga 265 Google Is Eating Our Mail null saintamh 685 9/56 Sample Case 1 Question - 5 Equal Levels SCORE: 50 points Easy Implementation Problem Solving Algorithms Interviewer Guidelines null n ull epaga 705 Show HN: This up votes itself null olalonde 83 Why I’m Suing the US Government null saintamh 305 Sample Input For Custom Testing saintamh Sample Output Google Is Eating Our Mail Why I’m Suing the US Government Explanation id username abo 1 epaga Java developer / team leader at inetso night<p>http://www.mindscopeapp.com<p>http:/ ngoering<p>[ my public key: https:// https://keybase.io/johngoering/sigs/I1UIk7t <p>hnchat:oYwa7PJ4Yaf1Vw9Om4juJava d 3 saintamh 5 olalonde olalonde@gmail.com<p>http://www.github.com/o ARTICL title url author num_commen A Message to Our Customers null epaga 967 “Was isolated from 1999 to 2006 with a 486. Built my own late 80s OS” null epaga 265 Google Is Eating Our Mail null saintamh 685 null n ull epaga 705 Show HN: This up votes itself null olalonde 83 Why I’m Suing the US Government null saintamh 305 10/56 Two signals are being generated as part of a simulation. A program monitors the signals. Whenever the two signals become equal at the same time, the frequency is noted. A record is maintained for the maximum simultaneous frequency seen so far. Each time a higher simultaneous frequency is noted, this variable ( maxequal) is updated to the higher frequency. Note: Both signals start at time t=0, but their durations might be different. In this case, the comparison of equality is performed only until the end of the shorter signal. If both signals have equal frequencies at a given time but the frequency is less than or equal to the current maximum frequency, maxequal, is not updated. The running times of both signals are given, denoted by n and m respectively. During the course of the simulation, how many times is the maxequal variable updated? Example signalOne = [1, 2, 3, 3, 3, 5, 4] signalTwo = [1, 2, 3, 4, 3, 5, 4] 1 2 3 4 5 1 2 3 4 5 Time 6 7 Frerquency Signal 2 Signal 1 maxequal updated Output = 4 (maxequal was updated 4 times) Each of the first three signals match and are increasing, so maxequal is updated 3 times to 1, 2 and then 3 At the fourth time, they are not equal. At the fifth, they are equal to 3 . Since maxequal contains 3 already, it is not updated. At the sixth time, both signals are equal to 5 . This is greater than maxequal = 3 , so now maxequal = 5. At the final time, signals are equal to 4 . Since 4 is less than maxequal , it is not updated. maxEqual was updated a total of 4 times. Function Description Complete the updateTimes function in the editor below. updateTimes has the following parameter(s): int signalOne[n]: the frequencies of the first signal int signalTwo[m]: the frequencies of the second signal Return 11/56 int: the number of updates Constraints 1 ≤ n ≤ 10 0 ≤ signalOne[i] ≤ 10 1 ≤ m ≤ 10 0 ≤ signalTwo[i] ≤ 10 Input Format For Custom Testing The first line contains an integer, n, the running time of the first signal and the number of elements in signalOne Each line i of the n subsequent lines (where 0 ≤ i < n ) contains the frequency of the signalOne[i]. The next line contains an integer, m, the running time of the second signal and the number of elements in signalTwo Each line i of the m subsequent lines (where 0 ≤ i < m) contains the frequency of the signalTwo[i]. Sample Case 0 Sample Input For Custom Testing STDIN Function ----- -------- 5 → signalOne[] size n = 5 1 → signalOne = [1, 2, 3, 4, 1] 2 3 4 1 5 → signalTwo[] size m = 5 5 → signalTwo = [5, 4, 3, 4, 1] 4 3 4 1 Sample Output 2 Explanation 1 2 3 4 5 1 2 3 4 5 Time 6 7 Frerquency Signal 2 Signal 1 maxequal updated Output = 2 (maxequal was updated 2 times) The frequencies are equal during three periods, with frequencies 3, 4 and 1. The maximum frequency is updated twice at 3 , and 4 , since 4 is greater than 3. 5 9 5 9 12/56 It is not updated when their values are 1 because 1 is less than the current maxequal = 4. Sample Case 1 Sample Input For Custom Testing STDIN Function ----- -------- 5 → signalOne[] size n = 5 1 → signalOne = [1, 2, 3, 4, 5] 2 3 4 5 5 → signalTwo[] size m = 5 5 → signalTwo = [5, 4, 3, 2, 1] 4 3 2 1 Sample Output 1 Explanation 1 2 3 4 5 1 2 3 4 5 Time 6 7 Frerquency Signal 2 Signal 1 maxequal updated Output = 1 (maxequal was updated 1 time) The maximum frequency is updated once at 3, the only point where the signals match. Given an array of integers, report the answers to multiple queries based on the elements of the array with respect to a given integer. More formally, an array of integers, an integer X, and a few queries are available. Each query is described by a single integer K. The task is to find the index of the K occurrence of the integer X in the array for each of the queries. Report -1 as the answer to the corresponding query if the K occurrence does not exist. Note : All the answers must be reported assuming 1-based indexing of the array. Question - 6 K-th Occurrence Queries SCORE: 50 points adhoc Implementation Easy th th 13/56 For example, let's say the favorite number is 8, and array values as [1, 2, 20, 8, 8, 1, 2, 5, 8, 0]. Then on query_value=100 and 4, the correct answer to print is -1, since, there is no 4 or 100 occurrence of the favorite number. In case the query_value is 2, print 5, as the 2 occurrence of the favorite number is at index 5 in the array. Function Description Complete the function solve in the editor below. The function must state what must be returned or printed. solve has the following parameter(s): X : an integer arr : an integer array query_values : An integer array Constraints 1 <= |arr|, |query_values| <= 2 * 10 ( Where |A| denotes the length of the array A ) 0 <= arr_values, X, query_values <= 10 Input Format For Custom Testing The first line contains an integer, the value of X. Next line contains a single integer N , denoting the size of the array, arr Then there will be N lines, containing the array values. The next line contains a single integer Q , the number of queries. Then there will be Q lines, containing the query values. Sample Case 0 Sample Input For Custom Testing STDIN FUNCTION ----- -------- 8 -> X = 8 10 -> arr[] size N = 10 1 -> arr[] = [ 1, 2, 20, 8, 8, 1, 2, 5, 8, 0 ] 2 20 8 8 1 2 5 8 0 5 -> query_values[] size Q = 5 100 -> query_values[] = [ 100, 2, 1, 3, 4 ] 2 1 3 4 Sample Output -1 5 4 9 -1 th th nd 5 9 14/56 Explanation Note, there is no 100 or 4 occurrence of 8, hence, for those queries, answer is -1, and for the rest, it is the index of k occurrence of X = 8. Sample Case 1 Sample Input For Custom Testing STDIN FUNCTION ----- -------- 9 -> X = 9 4 -> arr[] size N = 4 9 -> arr[] = [ 9, 8, 9, 9 ] 8 9 9 4 -> query_values[] size Q = 4 7 -> query_values[] = [ 7, 3, 7, 6] 3 7 6 Sample Output -1 4 -1 -1 Sample Explanation We don't have 6 or 7 occurrence of the 9, hence, for those queries, answer is -1, and in query number 2, we have query value as 3, and we can see, the 3 occurrence of 9 in the array is at index 4. Given an array, find two statistic indicators for the array and report the difference between the two stats. The indicators are defined as follows: Indicator 1 : This is defined by the number of instances where a number k appears for exactly k consecutive times in the array. For example, in the array [1, 2, 2, 2, 2, 3, 3, 3, 1, 1, 2, 2], we have 1(1), 2(4), 3(3), 1(2), 2(2) where the value in the braces represents the number of times the integer appeared consecutively. The value of indicator 1 for the given array would be 3 corresponding to 1(1), 3(3) and 2(2). Indicator 2 : This is defined by the number of instances where a number k appears for exactly k consecutive times in the array, starting from index k assuming 1-based indexing. For example, in the array [2, 2, 2, 4, 4, 4, 4, 4, 4], if we start at index 2 we have exactly 2 consecutive 2s coming up. While when we start at index 4, we have 6 consecutive 4s coming up. Hence the value of indicator 2 for the array would be 1 corresponding to the index 2. Your task is to find the absolute difference between the two indicators. Question - 7 Statistic Indicators SCORE: 50 points Simple Maths Easy th th th th th rd 15/56 Function Description Complete the function difference_calculator in the editor below. The function must return the difference between the two indicators. difference_calculator has the following parameter(s): N: the number of elements present in the array arr[arr[0],...arr[N-1]]: an array of N integers Constraints 1 ≤ N ≤ 100 1 ≤ arr[i] ≤ 15 Input Format For Custom Testing The first line contains an integer, N , denoting the number of elements present in the array. Each of the next N lines contain an element of array, arr Sample Case 0 Sample Input For Custom Testing STDIN FUNCTION ----- -------- 14 -> arr[] size N = 14 3 -> arr[] = [ 3, 3, 2, 2, 5, 5, 5, 5, 5, 3, 3, 3, 2, 2 ] 3 2 2 5 5 5 5 5 3 3 3 2 2 Sample Output 3 Explanation Indicator 1 will be 4. 3 3 2 2 5 5 5 5 5 3 3 3 2 2 2 appears exactly two consecutive times. 5 appears for exactly five consecutive times. Then, 3 appears for exactly three consecutive times. Then, 2 appears for exactly two consecutive times. Indicator 2 will be 1. 3 3 2 2 5 5 5 5 5 3 3 3 2 2 5 appears for exactly five times, starting from index 5. The difference is 3. Sample Case 1 Sample Input For Custom Testing STDIN FUNCTION ----- -------- 10 -> arr[] size N = 10 16/56 1 -> arr[] = [ 1, 2, 2, 4, 4, 4, 4, 2, 2, 2 ] 2 2 4 4 4 4 2 2 2 Sample Output 0 Explanation Indicator 1 will be 3. 1 2 2 4 4 4 4 2 2 2 1 appears exactly once. 2 appears exactly two consecutive times. 4 appears exactly four consecutive times. Indicator 2 will be 3. 1 2 2 4 4 4 4 2 2 2 1 appears exactly once, starting from index 1. 2 appears exactly two consecutive times, starting from index 2. 4 appears exactly four consecutive times, starting from index 4. The difference is 0. Create unique device names to be used in a residential IoT (Internet of Things) system. If a device name already exists in the system, an integer number is added at the end of the name to make it unique. The integer added starts with 1 and is incremented by 1 for each new request of an existing device name. Given a list of device name requests, process all requests and return an array of the corresponding unique device names. Example n = 6 devicenames = ['switch', 'tv', 'switch', 'tv', 'switch', 'tv'] devicenames[0] = " switch " is unique. uniqueDevicename[0]="switch" devicenames[1] = " tv " is unique. uniqueDevicename[1]="tv" devicenames[2] = devicenames[0] . Add 1 at the end the previous unique username " switch ", uniqueDevicename[2]="switch1" devicenames[3] = devicenames[1] . Add 1 at the end the previous unique username " tv ", uniqueDevicename[3]="tv1" devicenames[4] = devicenames[2] . Increment by 1 the number at the end of the previous unique username "switch1", uniqueDevicenames[4]="switch2" devicenames[5] = devicenames[3] . Increment by 1 the number at the end of the previous unique username "tv1", uniqueDevicenames[5]="tv2" Question - 8 Device Name System SCORE: 50 points Strings Easy Hashing Data Structures Algorithms Theme: E-commerce 17/56 return uniqueDevicenames = ['switch', 'tv', 'switch1', 'tv1', 'switch2', 'tv2'] Function Description Complete the function deviceNamesSystem in the editor below. deviceNamesSystem has the following parameter(s): string devicenames[n]: an array of device name strings in the order requested. Returns string[n] : an array of string usernames in the order assigned Constraints 1 ≤ n ≤ 10 1 ≤ length of devicenames[i] ≤ 20 devicenames[i] contains only lowercase English letters in the range ascii[a-z]. Input Format for Custom Testing The first line contains an integer, n , denoting the size of the array usernames Each line i of the n subsequent lines (where 0 ≤ i < n ) contains a string usernames[i] representing a username request in the order received. Sample Case 0 Sample Input STDIN Function ----- -------- 4 → devicenames[] size n = 4 mixer → devicenames= ["mixer","toaster","mixer","tv"] toaster mixer tv Sample Output 0 mixer toaster mixer1 tv Explanation 0 devicenames[0] = "mixer" is unique. uniqueDevicename[0]="mixer" devicenames[1] = "toaster" is unique. uniqueDevicename[1]="toaster" devicenames[2] = devicenames[0] . Add 1 at the end the previous unique device name "mixer", uniqueDevicename[2]="mixer1" devicenames[3] = "tv" is unique. uniqueDevicename[3]="tv" uniqueDevicenames = ["mixer", "toaster", "mixer1", "tv"] Sample Case 1 Sample Input 4 18/56 STDIN Function ----- -------- 2 → devicenames[] size n = 2 tv → devicenames=["tv","lamp"] lamp Sample Output 1 tv lamp Explanation 1 devicenames[0] = "tv" is unique. uniqueDevicename[0]="tv" devicenames[1] = "lamp" is unique. uniqueDevicename[1]="lamp" uniqueDevicenames = ["tv", "lamp"] Sample Case 2 Sample Input STDIN Function ----- -------- 4 → devicenames[] size n = 4 lamp → devicenames=["lamp","lamp","tv","lamp"] lamp tv lamp Sample Output 2 lamp lamp1 tv lamp2 Explanation 2 devicenames[0] = "lamp" is unique. uniqueDevicename[0]="lamp" devicenames[1] = devicenames[0] . Add 1 at the end the previous unique device name "lamp", uniqueDevicename[2]="lamp1" devicenames[2] = "tv" is unique. uniqueDevicename[2]="tv" devicenames[3] = devicenames[1] . Increment by 1 the number at the end of the previous unique device name "lamp1" , uniqueDevicename[3]="lamp2" uniqueDevicenames = ["lamp", "lamp1", "tv", "lamp2"] You are given a complex list of n products, each with a name, price, and weight. Find out how many duplicate products are present within the list. Duplicate products contain identical parameters for all fields in the list (i.e. name , price, and weight). Question - 9 Duplicated Products SCORE: 50 points Easy Implementation Problem Solving Algorithms Sets Interviewer Guidelines 19/56 Example: There are n = 5 products with attributes listed in three arrays, aligned by index. name = [ball, bat, glove, glove, glove] price = [2, 3, 1, 2, 1] weight = [2, 5, 1, 1, 1] A complete item description for item 0: (name[0], prices[0], weight[0]) is (ball, 2, 2) Name Price Weight ball 2 2 bat 3 5 glove 1 1 glove 2 1 glove 1 1 The first two items are unique. The two gloves at indices 2 and 4 are equal in all three attributes so there is 1 duplicate. The last glove at index 3 has a different price from the other two, so it is not a duplicate. There is 1 duplicate item in the original list. Function Description Complete the function numDuplicates in the editor below. The function must return an integer denoting the number of duplicates within the product list. numDuplicates has the following parameter(s): string name[n] : string array of size n, where names[i] denotes the name of the product at the index of i. int price[n] : int array of size n, where prices[i] denotes the price of the product at the index of i. int weight[n] : int array of size n, where weights[i] denotes the weight of the product at the index of i. Constraints 1 ≤ n ≤ 10 name[i] is non-empty, has at most 10 characters, and all its characters are lowercase English letters, ascii[a-z] 1 ≤ price[i], weight[i] ≤ 1000 Input Format Format for Custom Testing Input from stdin will be processed as follows and passed to the function: In the first line there is a single integer n which is the length of name Each of the following n lines contains a string for name[i] In the next line, n is repeated denoting the length of price 5 20/56 Each of the following n lines contains an integer for price[i]. In the next line, n is repeated denoting the length of weight Each of the following n lines contains an integer for weight[i]. Sample Case 0 Sample Input STDIN Function ----- -------- 5 → name[] size n = 5 ball → name = ['ball', 'box', 'ball', 'ball', 'box'] box ball ball box 5 → price[] size n = 5 2 → price = [2, 2, 2, 2, 2] 2 2 2 2 5 → weight[] size n = 5 1 → weight = [1, 2, 1, 1, 3] 2 1 1 3 Sample Output 2 Explanation Name Price Weight ball 2 1 box 2 2 ball 2 1 ball 2 1 box 2 3 The 3 balls have the same name, price and weight, so there are 2 duplicates. The two other products are boxes but they have different weights. Sample Case 1 Sample Input STDIN Function ----- -------- 5 → name[] size n = 5 ball → name = ['ball', 'box', 'lamp', 'brick', 'pump'] box lamp brick pump 5 → price[] size n = 5 2 → price = [2, 2, 2, 2, 2] 2 2 2 2 5 → weight[] size n = 5 2 → weight = [2, 2, 2, 2, 2]