Question bank › Math
Dsa Math Hard

Prime Gaps

Given a positive integer N, find all gaps between consecutive prime numbers less than or equal to N. A gap is defined as the difference between consecutive primes. Input Format: A single integer N (2 <= N <= 100000). Output Format: Print the gaps between consecutive primes as a list of integers. Example: Input: 10 Output: [1, 2, 2, 4]

Key concepts

mathprimesgaps

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.