Code RoomPrimes in range
HardPrep Room Coding #1197

Primes in range

CodingAlgorithms & data structuresSenior–Staff~30 min

Count the number of primes in the inclusive range [lo, hi] using a segmented sieve, where 1 <= lo <= hi <= 10^7 and hi - lo <= 10^6. The range can start high (e.g. [9999900, 10000000]) so you must NOT sieve from 0 to hi naively for the whole window; sieve base primes up to sqrt(hi) and mark only the window.

Implement
count_primes_in_range(lo: int, hi: int) → int
Examples
in[10,20]out4
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 30 min
InputExpectedGot
[10,20]4not run yetsample