Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Sum Pairs with Variations

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

Your question is Sum Pairs with Variations. 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

Find the sum of two numbers in an array, then handle variations: duplicates, multiple valid pairs, frequency-sorted output, etc.

Asked in the interview round 1 stage. SCE technical interview 1.

Implement find_sum_pairs(nums, target). Return one entry [a, b, count] for every unique pair of values where a <= b and a + b == target. count is the number of distinct index pairs producing those values. Sort entries by descending count, then ascending a. Return an empty list when no pair exists.

Constraints

  • 1 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Each unique value pair is returned at most once
  • For a pair of equal values, two distinct occurrences are required

Function Signature

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