#swe #leetcode

Related: Leetcode | Math | Software engineering

Problem Explanation

Given an integer n find out if it is a power of 3 so we need to find x such that $$3^x = n

## Initial Thoughts & Brute-Force Approach Given n = 27 if we divide it by 3 a bunch of time we eventually land at 1 ``` if n <= 0: print(0 can not be a power of 3) else: while n > 1 n = n/3 ``` ## Identifying the Pattern - ### Pattern: - ### Key indicators for this pattern: ## Optimal Approach & Algorithm - ### Explanation of the optimal algorithm - ### Why is this approach more efficient than the brute-force method - ### Key Data Structures Used: ## Code implementation ``` ``` ## Analysis - Time Complexity: - Space Complexity: ## Edge Cases