Balancing Pan
Easy Accuracy: 0.0% Submissions: 0 Points: 2

Given a simple weighing scale with two pans, we are given a weight T and some other weights which are the powers of a specific number a, our goal is to balance these pans using the given weights. More formally we need to satisfy this equation, T + (some power of a) = (some other powers of a).
Remember that we are given exactly one weight corresponding to one power.

 

Example 1:

Input:
a = 4
T = 11
Output:
YES
Explanation:
The scale can be balanced as,
11 + 4 + 1 = 16.

​

Example 2:

Input:
a = 3
T = 5
Output:
YES
Explanation:
The scale can be balanced as,
5 + 3 = 8.

 

Your Task:

You don't need to read input or print anything. Your task is to complete the function isBalanced() which takes two integers a and T and returns "YES" if we can balance the pans, else "NO"(Without Quotes).

 

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)

 

Constraints :
1 ≤ a ≤ T ≤ 1000

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.