Contacts Search Matching First or Last Name Prefixes

Last updated: November 29, 2026

Quick Overview

Given a contact list of full names, return the contacts where any name part (first, middle or last) starts with the typed query, case-insensitively, in alphabetical order.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a contact list of full names, return the contacts where any name part (first, middle or last) starts with the typed query, case-insensitively, in alphabetical order.

An easy Google phone screen question framed around the Android Contacts or Gmail recipient picker, where typing "sm" should find "Jane Smith". It checks indexing every name token in a trie and deduplicating contacts that match on more than one token.

What the Interviewer Expects
  • Tokenize names and index each token in a trie
  • Store contact ids at nodes to answer queries in one walk
  • Normalize case for matching but keep original display names
  • Deduplicate contacts matched by several tokens
  • Return results in a stable order
Key Topics to Cover
trie
tokenization
case folding
deduplication
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you rank results by how often the user contacts each person?
  • How would you support multi-token queries like 'ja sm'?
  • How would you handle accented characters and non-Latin scripts?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: contacts, full names such as "Jane Smith", and query. Output: sorted list of contact names where some whitespace-separated part starts with query, ignoring case. An empty query returns ...

High-Level Design

A plain prefix trie over full names would only match the first name. Instead, split each contact into tokens, lowercase them, and insert each token into a trie whose nodes hold the set of contact indi...


Submit Your Answer
Markdown supported