Skip to content

Practice Check if Number is a Sum of Powers of Three

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1780
LeetCode Problem

Check if Number is a Sum of Powers of Three

Problem Statement

Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three. Otherwise, return false. An integer y is a power of three if there exists an integer x such that y == 3^x.

Source: Check if Number is a Sum of Powers of Three on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 12
Output
true

# Example 2

Input
n = 91
Output
true

# Example 3

Input
n = 21
Output
false

Constraints

1 <= n <= 10^7

Related LeetCode Problems

Practice more problems similar to Check if Number is a Sum of Powers of Three.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.