Format a Phone Number with a Country Calling Code
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[][]) → StringExamples
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
- Base Unit ConversionsOA · Seen Nov 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Top-Funded Villages and ProjectsOA · Seen Aug 2026
- Count Parent Nodes With a Target SumOA · Seen Aug 2026
- Largest Binary Number by ConcatenationOA · Seen Aug 2026
- Count Events by CategoryOA · Seen Aug 2026
- Graph M-ColoringOA · Seen Aug 2026
- Hall of Shifting TilesOA · Seen Aug 2026
- K-th Ancestor Subtree Preorder QueryOA · Seen Aug 2026
- Maze ReachabilityOA · Seen Aug 2026
Similar questions at other companies
- Classify Password StrengthHackerRank · OA · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
- Count One-Swap Number PairsCapital One · OACapital One interview questions
- Perfect SubstringAXQ Capital · OA
- Count Suffix Word PairsTikTok · OATikTok interview questions
- Password Clues and the Next CommandOpenAI · OAOpenAI interview questions
- Decode Words with Anagram KeysCresta · OACresta interview questions
- Parcel Event TrackingAirbnb · OAAirbnb interview questions
- Maximum Valid Substring FrequencyMicrosoft · OAMicrosoft interview questions
- Longest Distinct StringSuperhuman · OASuperhuman interview questions
- Longest String ChainVisa · OAVisa interview questions
Adobe interview experiences
- Adobe New Grad OA: Unit Conversion and Code Review: 1 Experience
- Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe New Grad MTS Interview Questions: 7 Experiences
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)