Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Trie Data Structure Implementation
00:00
5 left

Trie Data Structure Implementation

EasyPython

Problem

Quantcast may need to index keyword and prefix signals efficiently. Implement a trie with insert, search, and startsWith operations.

Create a Trie class with these methods:

  1. insert(word): Add a lowercase word to the trie.
  2. search(word): Return True only when the complete word has been inserted.
  3. startsWith(prefix): Return True when at least one inserted word begins with prefix.

For automated evaluation, implement process_trie_operations(operations). Each operation is a dictionary with op equal to insert, search, or startsWith, and a word field. The function must return results only for search and startsWith operations, in their original order.

Formal Specification

  • Input: A list of operation dictionaries, where each dictionary has op: str and word: str.
  • Output: A list of booleans produced by search and startsWith operations.
  • Words contain only lowercase English letters and are nonempty.

Constraints

  • 1 <= len(operations) <= 10^4
  • 1 <= len(word) <= 100
  • Words contain only lowercase English letters
  • At most 5 * 10^3 distinct words are inserted
  • Operations are processed in order

Function Signature

def process_trie_operations(operations):
Interviewer

Your question is Trie Data Structure Implementation. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.