Highest-Ranked University by Country
Updated
Problem statement
You are given university ranking records. They come from a ranking API that returns its results page by page, and every page has already been collected for you. The records are stored in three arrays of the same length, where entry i of each array describes the same university:
universities[i]is the university name.countries[i]is its country.rankDisplay[i]is its rank as shown on the page. It is either a positive integer such as"12"or a positive range such as"601-650".
The rank of a record is the first integer in rankDisplay[i]. A smaller rank is better.
You are also given targetCountry. Return the name of the highest-ranked university in that country. If several universities share the best rank, return the lexicographically smallest name. That is the name that comes first when you compare the names character by character. If no record has that country, return the empty string.
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 for the best rank, 12. Comparing the names character by character, "Alpha University" comes first, so that is the answer.
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.
More Agoda Online Assessment questions
- Special Diameter EndpointsOA · Seen Nov 2025
- TV Series in a Production WindowOA · Seen Nov 2025
- Count One Groups by SizeOA · Seen Jul 2025
- Minimum Price With Discount CouponsOA · Seen Jul 2025
- Lexicographically Smallest Task QueueOA · Seen Jul 2025
- Jump Game with Prime-3 StepsOA · Seen Jun 2025
- Team FormationOA · Seen Apr 2025
- Two-Core Process AssignmentOA · Seen Apr 2025
- Unique Digits in RangeOA · Seen Apr 2025
- Maximize Sum of Processed TimesOA · Seen Sep 2024
Similar questions at other companies
- Large ResponsesPostman · OAPostman interview questions
- Incident MonitorStripe · OAStripe interview questions
- Correct Apartment Bedroom CountsRamp · OARamp interview questions
- Message Latencies from CSV LogsAmazon · ONSITE INTERVIEW
- Most Cost-Effective MachineCapital One · ONSITE INTERVIEWCapital One interview questions
- Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- Parse and Order Structured LogsCoinbase · ONSITE INTERVIEWCoinbase interview questions