Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Random Distinct Numbers Function

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

Your question is Random Distinct Numbers Function. 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

Ford Pro telemetry services need batches of distinct numeric identifiers for simulated vehicle events. Implement a function that returns count uniformly random, distinct integers from the inclusive range [start, end] without materializing the entire range.

The function must support an optional seed so tests and replayable simulations produce deterministic results. The output order should be random, and every valid subset of size count must have equal probability. Do not use random.sample or construct a list containing every value in the input range.

Formal Specification

Implement generate_distinct_numbers(start, end, count, seed=None).

  • Inputs are integers start, end, and count, plus an optional integer seed.
  • start <= end, and 0 <= count <= end - start + 1 are guaranteed for valid inputs.
  • Return a Python list containing exactly count distinct integers from [start, end].
  • Raise ValueError when the range is invalid or too small for count.
  • With the same inputs and seed, return the same sequence.

Constraints

  • -10^12 <= start <= end <= 10^12
  • 0 <= count <= 10^5
  • count <= end - start + 1
  • The full numeric range may be too large to store in memory

Function Signature

def generate_distinct_numbers(start, end, count, seed=None):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output