FastPrepPhone Numbers by Last Name
Problems/Phone Numbers by Last Name

Phone Numbers by Last Name

Grubhub logoGrubhub● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the record format and the goal of looking up by last name. It does not give how the input is written, the matching rule, the output order, or the input limits. Our version is about 84% the same as the reported question.

You are given an array of contact records and a requested lastName.

Each record is a valid string in one of these forms:

  • first last, 111-222-3333
  • first middle last, 111-222-3333

Name tokens are separated by one space, and the comma is followed by one space. Return every phone number whose final name token exactly equals lastName.

Matching is case-sensitive. Preserve input order and preserve duplicate phone numbers.

Function

phoneNumbersByLastName(records: String[], lastName: String) → String[]

Examples

Example 1

records = ["Ada Lovelace, 111-222-3333","Grace Brewster Hopper, 222-333-4444","Byron Lovelace, 333-444-5555"]lastName = "Lovelace"return = ["111-222-3333","333-444-5555"]

The first and third records have the exact last name Lovelace, so their phone numbers are returned in input order.

Example 2

records = ["Alex Kim, 111-111-1111","Alex kim, 222-222-2222"]lastName = "Kim"return = ["111-111-1111"]

Matching is case-sensitive, so kim does not equal Kim.

Example 3

records = ["A B C, 999-000-1111"]lastName = "Z"return = []

No record has the requested last name, so the result is empty.

Constraints

  • 1 <= records.length <= 10000.
  • Each record contains either two or three nonempty alphabetic name tokens and a phone number in the shown format.
  • Each name token has length from 1 through 30.
  • 1 <= lastName.length <= 30, and lastName is alphabetic.

More Grubhub interview questions

  • Coin ChangePHONE SCREEN · Seen Mar 2022

Similar questions at other companies

  • Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
  • Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
  • Longest Common Parent DirectoryGoogle · ONSITE INTERVIEWGoogle interview questions
  • K-Second Message SuppressionMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Word Search Across DocumentsConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
  • Retry with an Attempt LimitOracle · ONSITE INTERVIEWOracle interview questions
  • Extract Error Log ContextFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
  • Compress Consecutive Integer RangesDocuSign · ONSITE INTERVIEWDocuSign interview questions
All Grubhub interview questionsSee Grubhub hiring insights
Saved
class Solution {
    public String[] phoneNumbersByLastName(String[] records, String lastName) {
        // write your code here
    }
}
Checking account…