Highest-Ranked University by Country
Reported by candidates from Agoda's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Agoda OA reported in June 2025 looks like a ranking problem, but it's really a single-pass scan with a tiny state. Three parallel arrays, one target country, and you return the best-ranked university name. No fancy structure needed, just a running best (rank, name) pair. The catch is the rank format: "601-650" means 601. If you blank on parsing or tie-breaking, StealthCoder is the invisible safety net on the live OA. But this one is easy to own with five minutes of thought.
The problem
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; and rankDisplay[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) → String Examples 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 <= 10000 countries.length == universities.length rankDisplay.length == universities.length Every university name, country, and targetCountry is non-empty. Every displayed rank is either one positive integer or a positive integer range a-b with a <= b. Country matching is case-sensitive.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that you don't need a map or a sort. Loop once over the indices. Skip any record where countries[i] doesn't equal targetCountry exactly, since matching is case-sensitive. Parse the rank by taking the characters up to the first non-digit, so "601-650" gives 601 and "12" gives 12. Keep a best rank and best name. If the new rank is lower, replace both. If it's equal, keep the lexicographically smaller name. Start best rank at infinity and best name as an empty string, so a missing country returns "" naturally. The common pitfalls are parsing the whole string as an integer, which crashes on ranges, and forgetting the tie rule. Another is sorting 10000 records when a scan does it in O(n). If you freeze mid-OA, StealthCoder can hand you this loop in seconds.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Highest-Ranked University by Country cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Agoda's OA.
Agoda reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Highest-Ranked University by Country FAQ
How hard is the Agoda Highest-Ranked University problem really?+
Easy. It's a linear scan with one comparison rule. The only real work is parsing the rank from strings like "601-650" and handling ties by name. If you've written a min-tracking loop before, you can finish this quickly.
What's the trick to parsing rankDisplay?+
Read digits from the start of the string until you hit a non-digit. That gives the first integer for both "12" and "601-650". You can also split on "-" and take the first part. Don't parse the entire string as one number.
Do I need to sort the universities?+
No. Sorting works but costs O(n log n) and adds code. One pass tracking the best rank and best name is O(n) and simpler. With up to 10000 records either passes, but the scan has fewer places to slip.
How do I handle ties and missing countries?+
On equal ranks, compare names and keep the lexicographically smaller one. For a country with no records, never update the best, so you return the empty string you initialized. Example 3 tests exactly this, so check it.
How do I prepare for this in 48 hours?+
Practice parallel-array scans with a running best and a tiebreak. Write the rank parser by hand, then test the three given examples plus a range rank and a case mismatch. Case-sensitive matching means plain string equality is correct.