Recognize Powers of Three without Iteration

Quick Overview

Recognize Powers of Three without Iteration. Return whether signed integer n is 3 raised to a nonnegative integer power.

Recognize Powers of Three without Iteration

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return whether signed integer n is 3 raised to a nonnegative integer power. ```cpp bool isPowerOfThree(int n); ``` ### Examples ```text n = 81 -> true n = 45 -> false ``` ### Constraints - n spans the signed 32-bit domain. ### Optional follow-up Can you solve it without loops or recursion?

Overview: Recognize Powers of Three without Iteration. Return whether signed integer n is 3 raised to a nonnegative integer power.

Google logo
Google
Date not reported
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return whether signed integer n is 3 raised to a nonnegative integer power.

bool isPowerOfThree(int n);

Examples

n = 81 -> true
n = 45 -> false

Constraints

  • n spans the signed 32-bit domain.

Optional follow-up

Can you solve it without loops or recursion?