JuniorMath

Ugly Number

An ugly number is a positive integer which does not have a prime factor other than 2, 3, and 5.

Given an integer n, return true if n is an ugly number.

Example 1
Inputn = 6
Outputtrue
6 = 2 × 3.
Example 2
Inputn = 1
Outputtrue
1 has no prime factors.

Constraints

  • -2^31 <= n <= 2^31 - 1

Asked at 7 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate