Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Prime Numbers Range Coding

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

Your question is Prime Numbers Range Coding. 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

Hyscaler monitoring tools need to generate prime-number checkpoints within numeric ranges that may have a large upper bound. Given two integers left and right, return every prime number in the inclusive range [left, right] in ascending order.

Use a segmented sieve: generate base primes up to sqrt(right), then mark composite values only inside the requested range. Values below 2 are not prime.

Formal Specification

Implement get_primes(left, right).

  • Input: Two integers, left and right.
  • Output: A list of integers containing all primes p such that left <= p <= right, sorted in ascending order.
  • The range is guaranteed to be valid, with left <= right.

Constraints

  • 0 <= left <= right <= 10^12
  • 1 <= right - left + 1 <= 10^6
  • The output must be sorted in ascending order
  • Values less than 2 must not appear in the output

Function Signature

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