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
LeetCode Two Sum and Anagrams
00:00
5 left

LeetCode Two Sum and Anagrams

EasyPython

Problem

For an AKKODIS engineering assessment, implement one function that solves two independent collection tasks: find the unique pair of indices whose values add to a target, and group a list of lowercase words by anagram equivalence.

Formal Specification

Define solve_two_sum_and_group_anagrams(nums, target, words):

  1. Return the indices of two distinct elements in nums whose values sum to target.
  2. Return groups of anagrams from words. Words in the same group must contain identical character counts. Preserve the order of words within each group and order groups by the first occurrence of any word in that group.
  3. Return a dictionary with exactly two keys: two_sum and anagram_groups. The value of two_sum is a two-element list of indices. The value of anagram_groups is a list of word lists.

Each input is guaranteed to contain exactly one valid Two Sum pair. Do not reuse an array element. All words contain only lowercase English letters.

Constraints

  • 2 <= len(nums) <= 100000
  • -10^9 <= nums[i], target <= 10^9
  • 1 <= len(words) <= 100000
  • 1 <= len(words[i]) <= 100
  • The total number of characters across all words is at most 1000000
  • Exactly one valid Two Sum pair exists
  • Words contain only lowercase English letters

Function Signature

def solve_two_sum_and_group_anagrams(nums, target, words):
Interviewer

Your question is LeetCode Two Sum and Anagrams. 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.