Ugly Number
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
An **ugly number** is a positive integer whose only prime factors are 2, 3, or 5. In other words, after repeatedly dividing the number by 2, 3, and 5 as many times as possible, you should be left with exactly 1.
By convention, 1 is considered ugly because it has no prime factors at all.
Given an integer n, return true if n is an ugly number, and false otherwise. Note that n can be zero or negative; such values are never ugly.
Examples
Constraints
- `-2^31 <= n <= 2^31 - 1`
- `n` fits in a 32-bit signed integer.
- Values of `n` that are `0` or negative are not ugly.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.