Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Add Unique Numbers in Sequence

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

Your question is Add Unique Numbers in Sequence. 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

FSS payment-processing workflows may receive repeated numeric amounts within a sequence. Given a sequence of integers, return the sum of each distinct value exactly once.

The order of values does not affect the result. Negative numbers and zero must be handled normally. Aim for a single pass through the sequence using additional memory proportional to the number of distinct values.

Formal Specification

Implement sum_unique_amounts(amounts).

  • Input: amounts, a list of integers.
  • Output: An integer equal to the sum of all distinct integers in amounts.
  • If amounts is empty, return 0.

Constraints

  • 0 <= len(amounts) <= 10^5
  • -10^9 <= amounts[i] <= 10^9
  • Each input value is an integer
  • The result fits within Python's integer range

Function Signature

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