Power of Three
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
Given an integer n, determine whether it is a power of three.
An integer is a **power of three** if there exists some non-negative integer exponent x such that n == 3^x. The valid powers of three therefore begin 1 (which is 3^0), 3, 9, 27, 81, and so on.
Return true if n is a power of three, and false otherwise. Note that zero and all negative integers are never powers of three.
Examples
Constraints
- -2^31 <= n <= 2^31 - 1
- The input is a single 32-bit signed integer.
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.