Power of Four

Given an integer n, return true if it is a power of four. Pattern focus: Isolate Lowest Bit. First confirm that n is a power of two, then verify that the single set bit sits at an even position.

Input Format

n = integer

Output Format

true if n is a power of four

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • n must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

n = 16

Output:

true

Explanation:

16 is 4^2.

Example 2:

Input:

n = 8

Output:

false

Explanation:

8 is a power of two but not a power of four.

Loading...
Power of Four - Bit Manipulation DSA Problem