Code Room
CodingHardcod-g631
Subject PrimesLevel Senior–Staff~30 minCommon in Algorithms & data structures interviewsIndustries Software development, Technology

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.