Highest-Ranked University by Country
Problem statement
You are given university records collected from every page of a paginated ranking API. The records are represented by three parallel arrays:
universities[i]is the university name;countries[i]is its country; andrankDisplay[i]is its displayed rank, either a positive integer such as"12"or a positive range such as"601-650".
The numeric rank of a record is the first integer in rankDisplay[i]. A smaller rank is better.
Given targetCountry, return the name of its highest-ranked university. If several universities have the same best rank, return the lexicographically smallest name. Return the empty string when the country has no record.
Function
highestRankedUniversity(universities: String[], countries: String[], rankDisplay: String[], targetCountry: String) → StringExamples
Example 1
universities = ["Massachusetts Institute of Technology (MIT)","University of Oxford","University of Cambridge"]countries = ["United States","United Kingdom","United Kingdom"]rankDisplay = ["1","3","2"]targetCountry = "United Kingdom"return = "University of Cambridge"The two matching universities have ranks 3 and 2. Rank 2 is better, so return "University of Cambridge".
Example 2
universities = ["Gamma Institute","Alpha University","Beta College"]countries = ["Canada","Canada","Canada"]rankDisplay = ["12","12","20"]targetCountry = "Canada"return = "Alpha University"Gamma Institute and Alpha University tie at rank 12. The lexicographically smaller name is "Alpha University".
Example 3
universities = ["National University of Singapore (NUS)"]countries = ["Singapore"]rankDisplay = ["11"]targetCountry = "Thailand"return = ""No record belongs to "Thailand", so return the empty string.
Constraints
1 <= universities.length <= 10000countries.length == universities.lengthrankDisplay.length == universities.length- Every university name, country, and
targetCountryis non-empty. - Every displayed rank is either one positive integer or a positive integer range
a-bwitha <= b. - Country matching is case-sensitive.