Search and Format Contacts
Updated
Problem statement
You are building the search screen of a contacts app. Contact i has a first name names[i], an optional last name lastNames[i] (an empty string means none), a phone number numbers[i] and an optional email emails[i] (an empty string means none).
Given a search string query, remove spaces from both ends of it. A contact matches when its first name starts with the trimmed query, ignoring upper and lower case. An empty trimmed query matches every contact.
Return one line for each matching contact, in input order, formatted as the first name, then a space and the last name if there is one, then ": " and the number, then ", " and the email if there is one. For example, Bob Smith: 4441234567 and Alice: 1234567890, alice@example.com.
Function
searchContacts(names: String[], lastNames: String[], numbers: long[], emails: String[], query: String) → List<String>Examples
Example 1
names = ["John","Alice","Ali","Bob","Sarah","Bobby","Michael","Emily","David","Jonathan","Bobbi"]lastNames = ["","","","","","","","","","",""]numbers = [50291238,1231238761,559123876,349912387,2119123876,299912387,1291238761,294912387,299712387,493912387,299912387]emails = ["John@adyen.com","alice@adyen.com","ali@adyen.com","","Sarah@adyen.com","","michael@adyen.com","emily@adyen.com","","","Bobbi@adyen.com"]query = "Ali"return = ["Alice: 1231238761, alice@adyen.com","Ali: 559123876, ali@adyen.com"]- Both
AliceandAlistart withAli. Each line shows the name, a colon, the number and, because both have an email, a comma and the email.
Example 2
names = ["John","Alice","Ali","Bob","Sarah","Bobby","Michael","Emily","David","Jonathan","Bobbi"]lastNames = ["","","","","","","","","","",""]numbers = [50291238,1231238761,559123876,349912387,2119123876,299912387,1291238761,294912387,299712387,493912387,299912387]emails = ["John@adyen.com","alice@adyen.com","ali@adyen.com","","Sarah@adyen.com","","michael@adyen.com","emily@adyen.com","","","Bobbi@adyen.com"]query = " bob "return = ["Bob: 349912387","Bobby: 299912387","Bobbi: 299912387, Bobbi@adyen.com"]- The query is trimmed to
boband compared without case, soBob,BobbyandBobbimatch, in input order. BobandBobbyhave no email, so their lines end after the number.
Example 3
names = ["Bob","Alice"]lastNames = ["Smith",""]numbers = [4441234567,1234567890]emails = ["","alice@example.com"]query = ""return = ["Bob Smith: 4441234567","Alice: 1234567890, alice@example.com"]- An empty query matches every contact.
Bobhas a last name, which follows his first name:Bob Smith: 4441234567.
Constraints
1 <= n == names.length == lastNames.length == numbers.length == emails.length <= 1000- Each
names[i]has 1 to 20 English letters; eachlastNames[i]has 0 to 20 English letters. 0 <= numbers[i] <= 1010- Each
emails[i]is empty or has the formlocal@domain, each part 1 to 30 characters from letters, digits,.,_and-(no_in the domain). queryhas 0 to 20 characters, each an English letter or a space.
More Adyen interview questions
Similar questions at other companies
- Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
- Process Refunds with Bounded RetriesMercor · PHONE SCREENMercor interview questions
- E-commerce Notification RouterAmazon · PHONE SCREEN
- Project JSON Fields into a Target FormatBooking.com · PHONE SCREEN
- Validate a Single-Letter Word SequenceReddit · PHONE SCREENReddit interview questions
- Incremental String Qualification with Split and MergeStripe · PHONE SCREENStripe interview questions
- Excel Training Data and Model Response AuditMicrosoft · PHONE SCREENMicrosoft interview questions
- Elevator Scheduling SimulationOpenAI · PHONE SCREENOpenAI interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Load/Store Arithmetic InterpreterJane Street · PHONE SCREENJane Street interview questions