Power of Three

Easy · Math & Number Theory · about 5 minutes

Asked at Google, Amazon, Bloomberg, Meta, Microsoft.

Decide whether n equals 3 raised to some non-negative integer power k. Bonus: can you do it without a loop or recursion?