PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This problem evaluates string-processing and filtering skills, focusing on exact prefix matching, case sensitivity, duplicate handling, and edge-case management over arrays of strings. Commonly asked in Coding & Algorithms interviews, it assesses practical implementation ability and understanding of algorithmic complexity at an implementation-level (basic to intermediate).

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Return dictionary words matching a prefix

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a list of strings `words` (a dictionary) and a string `prefix`. Return all words in `words` that start with `prefix`. Clarifications/constraints: - Matching is case-sensitive. - If no words match, return an empty list. - If `words` contains duplicates, include duplicates in the output. - You may return the result in any order unless the interviewer asks for a specific ordering (e.g., lexicographic).

Quick Answer: This problem evaluates string-processing and filtering skills, focusing on exact prefix matching, case sensitivity, duplicate handling, and edge-case management over arrays of strings. Commonly asked in Coding & Algorithms interviews, it assesses practical implementation ability and understanding of algorithmic complexity at an implementation-level (basic to intermediate).

You are given a list of strings `words` representing a dictionary and a string `prefix`. Return all words in `words` that start with `prefix`. Rules: - Matching is case-sensitive. - If no words match, return an empty list. - If `words` contains duplicates, include duplicates in the output. - For this problem, return matching words in the same order they appear in `words`. - An empty prefix matches every word.

Constraints

  • 0 <= len(words) <= 100000
  • 0 <= len(prefix) <= 1000
  • Each element of `words` is a string
  • Matching must be case-sensitive

Examples

Input: (['apple', 'app', 'banana', 'apply'], 'app')

Expected Output: ['apple', 'app', 'apply']

Explanation: These are the words that start with 'app', kept in their original order.

Input: (['Cat', 'car', 'Cart', 'dog'], 'Ca')

Expected Output: ['Cat', 'Cart']

Explanation: Matching is case-sensitive, so 'car' does not match 'Ca'.

Input: (['dog', 'deer'], 'cat')

Expected Output: []

Explanation: No word starts with 'cat'.

Input: (['test', 'team', 'test', 'toast'], 'te')

Expected Output: ['test', 'team', 'test']

Explanation: Duplicates are preserved in the result.

Input: ([], 'a')

Expected Output: []

Explanation: An empty dictionary has no matches.

Input: (['a', '', 'ab'], '')

Expected Output: ['a', '', 'ab']

Explanation: An empty prefix matches every word, including the empty string.

Hints

  1. Scan through the list once and decide for each word whether it begins with the prefix.
  2. Be careful with duplicates and with the case where `prefix` is an empty string.
Last updated: Apr 19, 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

  • Solve Rooms and Top-K Streams - Google (medium)
  • Find Containing Range - Google (medium)
  • Rearrange Tasks With Cooldown - Google (medium)
  • Implement Employee Management and Expression Evaluation - Google (medium)
  • Solve Three Array and Matrix Path Problems - Google (medium)