REST API: Highest International Students
Problem statement
The original task retrieves every page from a global university API. For deterministic practice, all fetched records are supplied in universityRecords. Each row has exactly three fields:
university: the university namecity: the university cityinternationalStudents: a nonnegative decimal count that may contain comma separators
First consider records whose city exactly equals firstCity. If at least one exists, return the university name with the largest parsed international-student count. Otherwise, perform the same selection for secondCity.
If several universities in the selected city have the same maximum count, return the lexicographically smallest university name.
Function
highestInternationalStudents(firstCity: String, secondCity: String, universityRecords: String[][]) → StringExamples
Example 1
firstCity = "London"secondCity = "Boston"universityRecords = [["King's College London","London","15,075"],["University College London","London","21,500"],["Boston Tech","Boston","8,000"]]return = "University College London"London has records, so Boston is not considered. 21,500 is larger than 15,075, so University College London is returned.
Example 2
firstCity = "Seattle"secondCity = "Boston"universityRecords = [["Beta University","Boston","12,000"],["Alpha University","Boston","12,000"],["Gamma College","Chicago","25,000"]]return = "Alpha University"Seattle has no record, so the search falls back to Boston. The two Boston universities tie at 12,000, and Alpha University is lexicographically smaller.
Constraints
- For this exercise, assume
1 <= universityRecords.length <= 100000. - For this exercise, assume every row has exactly three nonempty strings in the order
[university, city, internationalStudents]. - For this exercise, assume each parsed international-student count is between
0and10^9, inclusive. - For this exercise, assume at least one record matches
firstCityorsecondCity. - City matching is exact and case-sensitive.