Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Hash Map for Pair Sums and Duplicates

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

Your question is Hash Map for Pair Sums and Duplicates. 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

An Atos monitoring pipeline receives an unsorted array of integer event codes. Implement a function that identifies both distinct value pairs whose sum equals a target and values that occur at least twice, using hash-based lookups.

Return a dictionary with two keys: pairs, containing each distinct pair as a two-element list in the order it is first discovered, with the smaller value first; and duplicates, containing each duplicated value once in the order it reaches its second occurrence.

Formal Specification

  • Input: nums, a list of integers, and target, an integer.
  • Output: A dictionary of the form {"pairs": list[list[int]], "duplicates": list[int]}.
  • A pair uses two different array positions, even when both values are equal.
  • Each distinct value pair and duplicate value must appear only once.
  • Return empty lists when no matching pair or duplicate exists.

Constraints

  • 0 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Pairs and duplicates must contain distinct values only
  • Average hash map and hash set operations take O(1) time

Function Signature

def find_pairs_and_duplicates(nums, target):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output