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
Anagram Finder With Tests
00:00
5 left

Anagram Finder With Tests

MediumPython

Problem

Milliman Integrate may need to resolve multiple search terms against a terminology dictionary, treating words as matches when they contain exactly the same letters in a different order. Given a dictionary and several query words, return every dictionary word that is an anagram of each query.

The result for each query must preserve the dictionary's original order, including duplicate dictionary entries. A dictionary word matches only when its character counts are identical to the query's counts. Do not return generated permutations that are absent from the dictionary.

Formal Specification

Implement find_anagrams(dictionary, queries), where dictionary and queries are lists of lowercase English strings. Return a list whose ith element contains all dictionary words that are anagrams of queries[i].

Build reusable lookup information so that the dictionary is processed once rather than rescanned for every query.

Constraints

  • 1 <= len(dictionary), len(queries) <= 10^5
  • Each word contains 1 to 20 lowercase English letters
  • The total number of dictionary characters is at most 2 * 10^6
  • The total number of query characters is at most 2 * 10^6
  • Dictionary duplicates must be preserved

Function Signature

def find_anagrams(dictionary, queries):
Interviewer

Your question is Anagram Finder With Tests. 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.