FastPrepFastPrep
Problem Brief

Calculate Leftover Stacks

OA

Given a list of stacks (just a number), each stack has the following operation: every 2 blocks get converted over to 1 and pushed to the next stack. Your goal is to calculate the number of stacks of 1 leftover by the time you complete all possible stack operations.

1Example 1

Input
stacks = [5, 3, 1]
Output
4
Explanation
Following the given operations:
  • 4 from the first stack can get converted into 2 to the next stack with one left over
  • 2 + 3 = 5 which follows the same, one left over with the 4 converted into 2 for the next stack
  • 2 + 1 = 3 which makes two blocks get converted into 1 into the next stack
  • 1 + 0 = 1, no possible operation
Thus, there are 4 stacks with 1 block leftover.

Constraints

Limits and guarantees your solution can rely on.

🦊🦊
public int calculateLeftoverStacks(int[] stacks) {
  // write your code here
}
Input

stacks

[5, 3, 1]

Output

4

Sign in to submit your solution.