FastPrepFormat a Phone Number with a Country Calling Code

Format a Phone Number with a Country Calling Code

Adobe logoAdobe● MediumFULLTIMEOA

Updated

Problem statement

Given a country name and a phone number, look up that country's calling code and return the international-format text.

For this exercise, countryCodes contains the supplied country API response as rows [country,callingCode]. Match countryName exactly. Return "+" + callingCode + " " + phoneNumber, preserving the phone number exactly. The country is guaranteed to exist. This finite response table replaces the network request; no external service is needed.

Function

formatPhoneNumber(countryName: String, phoneNumber: String, countryCodes: String[][]) → String

Examples

Example 1

countryName = "US"phoneNumber = "xxx-xxx-xxxx"countryCodes = [["US","1"],["Example","77"]]return = "+1 xxx-xxx-xxxx"

The US row supplies code 1. Add one plus sign and one space before the original phone text, giving +1 xxx-xxx-xxxx.

Example 2

countryName = "Example"phoneNumber = "(42) 100-200"countryCodes = [["Example","77"]]return = "+77 (42) 100-200"

The calling code is 77. The spaces, parentheses and hyphen in the phone number are preserved.

Constraints

  • For this exercise, assume 1 <= countryCodes.length <= 1000.
  • Every countryCodes row has exactly two strings [country,callingCode].
  • For this exercise, assume 1 <= countryName.length <= 100 and 1 <= phoneNumber.length <= 100.
  • Country names are unique, nonempty ASCII strings of at most 100 characters; countryName matches one row exactly, including case.
  • Calling codes contain one to four decimal digits, with no leading plus sign and no leading zero.
  • phoneNumber is nonempty ASCII text of at most 100 characters; keep it exactly as given.

Source note: Original OA task images and any included source example. The practice contract follows the rules stated in the problem and source note.

More Adobe Online Assessment questions

Similar questions at other companies

Adobe interview experiences

All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public String formatPhoneNumber(String countryName, String phoneNumber, String[][] countryCodes) {
        // Write your solution here.
    }

}
Checking account…