PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates familiarity with phone-keypad character-to-digit mappings, string pattern matching, and efficient filtering of dictionary words, testing competencies in mapping, string manipulation, and algorithmic performance within the coding & algorithms domain.

  • medium
  • LinkedIn
  • Coding & Algorithms
  • Software Engineer

Find dictionary words matching a phone digit string

Company: LinkedIn

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given: - A digit string `digits` consisting of characters `'2'`–`'9'`. - A list of lowercase words `words` (dictionary). Use the classic phone keypad mapping: - `2 -> abc`, `3 -> def`, `4 -> ghi`, `5 -> jkl`, - `6 -> mno`, `7 -> pqrs`, `8 -> tuv`, `9 -> wxyz` A word *matches* `digits` if: - The word length equals `len(digits)`, and - For every position `i`, the `i`-th character of the word is one of the letters mapped from `digits[i]`. Return all words from `words` that match `digits`. ### Input / Output - **Input:** `digits: string`, `words: list[string]` - **Output:** `list[string]` containing all matching words (any order is acceptable). ### Constraints (reasonable interview assumptions) - `1 <= len(digits) <= 20` - `0 <= len(words) <= 2 * 10^5` - Each word contains only `a`–`z` and has length up to 20. ### Examples - `digits = "8733"`, `words = ["tree", "used", "free", "true"]` → output could be `["tree", "used"]`.

Quick Answer: This question evaluates familiarity with phone-keypad character-to-digit mappings, string pattern matching, and efficient filtering of dictionary words, testing competencies in mapping, string manipulation, and algorithmic performance within the coding & algorithms domain.

You are given a digit string `digits` containing only characters `'2'` to `'9'`, and a list of lowercase dictionary words `words`. Use the classic phone keypad mapping: - `2 -> abc` - `3 -> def` - `4 -> ghi` - `5 -> jkl` - `6 -> mno` - `7 -> pqrs` - `8 -> tuv` - `9 -> wxyz` A word matches `digits` if: 1. The word length is exactly `len(digits)`, and 2. For every index `i`, the character `word[i]` belongs to the set of letters mapped from `digits[i]`. Return all words from `words` that match `digits`. Any order is acceptable, but returning them in their original input order is fine.

Constraints

  • 1 <= len(digits) <= 20
  • 0 <= len(words) <= 2 * 10^5
  • Each word contains only lowercase English letters
  • Each word has length at most 20

Examples

Input: ("8733", ["tree", "used", "free", "true"])

Expected Output: ["tree", "used"]

Explanation: `tree` maps to 8733 and `used` also maps to 8733. `free` and `true` do not match the pattern.

Input: ("23", ["ad", "ae", "bd", "cf", "dog", "a"])

Expected Output: ["ad", "ae", "bd", "cf"]

Explanation: The first four words match 2->abc and 3->def. `dog` and `a` are rejected because their lengths do not match.

Input: ("2", [])

Expected Output: []

Explanation: An empty dictionary produces no matches.

Input: ("4663", ["good", "home", "gone", "hood", "foo", "good"])

Expected Output: ["good", "home", "gone", "hood", "good"]

Explanation: All listed 4-letter words except `foo` map to 4663. The duplicate `good` should be preserved.

Input: ("23", ["aa", "gg", "zzz"])

Expected Output: []

Explanation: `aa` maps to 22, `gg` maps to 44, and `zzz` has the wrong length, so nothing matches.

Hints

  1. Instead of checking whether each digit contains a letter, build a reverse mapping from each letter to its corresponding digit.
  2. Skip any word whose length does not match `len(digits)` before checking character-by-character.
Last updated: May 8, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Count Trips From Vehicle Logs - LinkedIn (easy)
  • Design O(1) Randomized Multiset - LinkedIn (easy)
  • Process Mutable Matrix Sum Queries - LinkedIn (medium)
  • Design a Randomized Multiset - LinkedIn (medium)
  • Can You Place N Objects? - LinkedIn (medium)