Skip to main content
LeetCode 264, Medium. Topics: Hash Table, Math, Dynamic Programming, Heap (Priority Queue). View on LeetCode. Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:

Problem

An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. Given an integer n, return the nth * ugly number*.

Examples

Constraints

  • 1 <= n <= 1690

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026