Determine whether a given integer is a power of four. A power of four is a positive integer of the form 4 raised to some non-negative exponent (1, 4, 16, 64 and so on). Return false for zero, negative numbers, and null.

Examples:

Input: n = 16 Output: true Explanation: 16 equals 4 raised to the power 2 Input: n = 1 Output: true Explanation: 1 equals 4 raised to the power 0 Input: n = 5 Output: false Explanation: 5 is not a power of four Input: n = 8 Output: false Explanation: 8 is a power of two but not a power of four Input: n = null Output: false Explanation: Null input returns false
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay October 2026 (Oct 16–31)Sponsored by FLXBL

Contest runs October 16 - 31. Complete challenges to climb the leaderboard!

Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes

Only the 16 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In