PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question assesses algorithmic problem-solving and number-theoretic computation skills, requiring efficient prime generation and complexity analysis in the Coding & Algorithms domain.

  • easy
  • NVIDIA
  • Coding & Algorithms
  • Software Engineer

Find the nth prime number

Company: NVIDIA

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

Given an integer n (1-indexed), return the n-th prime number (e.g., n=1 -> 2, n=2 -> 3, n=3 -> 5). Design an algorithm that is efficient for moderately large n (you may state reasonable constraints, e.g., up to 10^5).

Quick Answer: This question assesses algorithmic problem-solving and number-theoretic computation skills, requiring efficient prime generation and complexity analysis in the Coding & Algorithms domain.

Given an integer n (1-indexed), return the n-th prime number. For example, the 1st prime is 2, the 2nd prime is 3, and the 3rd prime is 5. Design an algorithm that is efficient for moderately large n, so a simple trial-division approach for each candidate number is not sufficient.

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, ...

Input: 6

Expected Output: 13

Explanation: The first six primes are 2, 3, 5, 7, 11, 13.

Input: 10

Expected Output: 29

Explanation: The 10th prime number is 29.

Input: 100

Expected Output: 541

Explanation: Counting primes in order, the 100th prime is 541.

Input: 1000

Expected Output: 7919

Explanation: The 1000th prime number is 7919.

Hints

  1. Instead of testing each number individually for primality, mark multiples of known primes using a sieve.
  2. To size the sieve, use an upper bound for the n-th prime: for n >= 6, p_n < n * (log n + log log n).
Last updated: May 14, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Return all file paths via DFS - NVIDIA (easy)
  • Implement a disk space manager with eviction - NVIDIA (medium)
  • Implement short algorithms on logs, grids, and strings - NVIDIA (hard)
  • Implement encode/decode for list of strings - NVIDIA (easy)
  • Solve small string and API tasks - NVIDIA (medium)