Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Python Coding to Find Numbers

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

Your question is Python Coding to Find Numbers. 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

Cognite Data Fusion can expose large collections of numeric telemetry readings. Given a list of integer readings and a target value, return every distinct unordered pair of values whose sum equals the target.

Each pair must be represented as [smaller, larger], including pairs containing the same value, such as [3, 3]. Return the pairs sorted lexicographically. Duplicate readings must not create duplicate pairs.

Formal Specification

Implement a function that accepts nums, a list of integers, and target, an integer. Return a list of two-element integer lists. Every returned pair [a, b] must satisfy a <= b and a + b == target. Return [] when no valid pair exists.

Constraints

  • 1 <= len(nums) <= 10^5
  • -10^9 <= nums[i], target <= 10^9
  • Duplicate values are allowed.
  • Each returned pair must use two different positions.
  • The result contains distinct pairs sorted lexicographically.

Function Signature

def distinct_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