FastPrepREST API: Highest International Students

REST API: Highest International Students

Rippling logoRippling● EasyFULLTIMEOA
Learn

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:

  1. university: the university name
  2. city: the university city
  3. internationalStudents: 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[][]) → String

Examples

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 0 and 10^9, inclusive.
  • For this exercise, assume at least one record matches firstCity or secondCity.
  • City matching is exact and case-sensitive.

More Rippling problems

See Rippling hiring insights
public String highestInternationalStudents(String firstCity, String secondCity, String[][] universityRecords) {
    // Write your code here.
}
firstCity"London"
secondCity"Boston"
universityRecords[["King's College London","London","15,075"],["University College London","London","21,500"],["Boston Tech","Boston","8,000"]]
expected"University College London"
Checking account…