Find the nth prime number
Company: NVIDIA
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Overview: This question assesses algorithmic problem-solving and number-theoretic computation skills, requiring efficient prime generation and complexity analysis in the Coding & Algorithms domain.
Constraints
- 1 <= n <= 100000
- The answer fits in a 32-bit signed integer for the given constraints
- An efficient solution is expected, such as using the Sieve of Eratosthenes with a suitable upper bound
Examples
Input: 1
Expected Output: 2
Explanation: The 1st prime number is 2.
Input: 2
Expected Output: 3
Explanation: The sequence of primes starts as 2, 3, 5, 7, ...
Hints
- Instead of testing each number individually for primality, mark multiples of known primes using a sieve.
- To size the sieve, use an upper bound for the n-th prime: for n >= 6, p_n < n * (log n + log log n).