Skip to content
Decoder

Power of Four

Easy

Problem

Return true if the integer n is a power of four (1, 4, 16, 64, ...), otherwise false. Can you do it without loops or recursion?

Example 1

Input
n = 16
Output
true

Example 2

Input
n = 5
Output
false

Example 3

Input
n = 8
Output
false
Why
a power of two, but not of four

Example 4

Input
n = 1
Output
true
Why
4^0

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.