PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of trie data structures, string pattern matching with wildcard characters, and efficient algorithm design for large-scale add/search operations.

  • medium
  • Trexquant
  • Coding & Algorithms
  • Software Engineer

Implement Trie search with wildcard matching

Company: Trexquant

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Design a text dictionary using a Trie. Support the following operations: - `addWord(word)`: Insert a lowercase English word. - `search(pattern)`: Return `true` if any previously added word matches `pattern`. The `pattern` may contain the wildcard character `.` which matches **exactly one** lowercase letter. (All other characters match themselves.) ### Inputs/Outputs You may implement a class with these two methods, or write functions that process a sequence of operations. ### Constraints - Number of operations up to ~10^5. - Word/pattern length up to ~10^3 (assume typical interview constraints; optimize beyond naive scanning). - Must be implemented in C++.

Quick Answer: This question evaluates understanding of trie data structures, string pattern matching with wildcard characters, and efficient algorithm design for large-scale add/search operations.

Process operations ["add", word] and ["search", pattern]. In search, . matches exactly one lowercase letter. Return all search booleans.

Constraints

  • Words are lowercase English strings

Examples

Input: ([['add', 'bad'], ['add', 'dad'], ['add', 'mad'], ['search', 'pad'], ['search', 'bad'], ['search', '.ad'], ['search', 'b..']],)

Expected Output: [False, True, True, True]

Input: ([['search', '.'], ['add', 'a'], ['search', '.'], ['search', '..']],)

Expected Output: [False, True, False]

Hints

  1. DFS branches only when the pattern character is a wildcard.
Last updated: Jun 27, 2026

Related Coding Questions

  • Streaming Median Tracker - Trexquant (medium)
  • Maintain median of a data stream - Trexquant (medium)

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
  • AI Coding 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.