-
Notifications
You must be signed in to change notification settings - Fork 380
Description
LeetCode Username
Melisha2904
Problem Number, Title, and Link
Bug Category
Problem hints
Bug Description
You have a starting number.
In each step, you take away a chunk that looks like “a power of two plus num2.”
After some steps, what’s left should exactly match a mix of powers of two.
So we test step counts (1 to 60).
For each count, we check if the remaining number is non-negative, big enough, and can be split into that many powers of two.
If yes, that count is the answer.
If no count works, then it’s impossible, so answer is -1.
Language Used for Code
Java
Code used for Submit/Run operation
Expected behavior
You start with a number num1.
Each move, you take away (2^i + num2) from it.
After k moves, the leftover must be made only from powers of two (like 1, 2, 4, 8...).
So we check for each k (1 to 60):
Is the leftover (num1 - k*num2) not negative?
Can it be broken into at most k powers of two?
Is it big enough for k moves?
The first k that works is the answer. If none works, answer is -1.
Screenshots
No response
Additional context
No response