FastPrepREST API: Country Codes

REST API: Country Codes

Palantir logoPalantirEasyINTERNOA
Learn

Problem statement

You are given a country name country, a phone-number string phoneNumber, and countryRecords, an offline representation of the country API data. Each row contains a country name followed by that record's calling codes in API order.

Find the row whose country name exactly equals country. If no row matches, return -1. Otherwise, use the row's last calling code and return +<calling code> <phone number>. Preserve phoneNumber exactly, including leading zeroes.

Function

getPhoneNumbers(country: String, phoneNumber: String, countryRecords: String[][]) → String

Examples

Example 1

country = "Afghanistan"phoneNumber = "6564454455"countryRecords = [["Afghanistan","93"]]return = "+93 6564454455"

The supplied Afghanistan record has one calling code, 93, so the formatted result is +93 6564454455.

Example 2

country = "Puerto Rico"phoneNumber = "564539386"countryRecords = [["Puerto Rico","1787","1939"]]return = "+1939 564539386"

The Puerto Rico record has calling codes [1787, 1939]. The last entry is 1939, so that code is used.

Example 3

country = "Oceania"phoneNumber = "987574876"countryRecords = [["Afghanistan","93"],["Puerto Rico","1787","1939"]]return = "-1"

No supplied record has the exact country name Oceania, so the function returns -1.

Constraints

  • 0 <= countryRecords.length <= 300
  • 2 <= countryRecords[i].length <= 10
  • Country names in countryRecords are unique.
  • Country names contain English letters and spaces.
  • Calling codes and phoneNumber contain decimal digits.

More Palantir problems

See Palantir hiring insights
public String getPhoneNumbers(String country, String phoneNumber, String[][] countryRecords) {
    // write your code here
}
country"Afghanistan"
phoneNumber"6564454455"
countryRecords[["Afghanistan","93"]]
expected"+93 6564454455"
Checking account…