Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

LeetCode Two Sum and Anagrams

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is LeetCode Two Sum and Anagrams. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output