Power of Three (Easy)

Good evening! Here's our prompt for today.

You may see this problem at Cisco, Autodesk, Vmware, Groupon, Flatiron Health, and Segment.

Given an integer num, write a method to determine if it is a power of 3.

Description

The method will be called as follows:

JAVASCRIPT
1console.log(powerOfThree(9));
2// true
3
4console.log(powerOfThree(7));
5// false

Constraints

  • The given would be a non zero positive integer in the range between 1 and 2147483647
  • Expected space complexity : O(logn)
  • Expected time complexity : O(1)
JAVASCRIPT
OUTPUT
Results will appear here.