FastPrepCalculate Leftover Stacks
Problems/Calculate Leftover Stacks

Calculate Leftover Stacks

Microsoft logoMicrosoft● EasyOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

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.

Function

calculateLeftoverStacks(stacks: int[]) → int

Examples

Example 1

stacks = [5, 3, 1]return = 4

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

  • 🦊🦊

More Microsoft interview questions

  • Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
  • Authentication SystemOA · Seen Nov 2026
  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Maximum String OperationsOA · Seen Nov 2026
  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Basic Item DiscountsPalantir · OAPalantir interview questions
  • Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
  • Costliest ChocolateRippling · OARippling interview questions
  • Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
  • Plus Mult ArrayIBM · OAIBM interview questions
  • Progressive Tax CalculatorInteractive Brokers · OA
  • 2020 Account Balance with Monthly Card FeesDRW · OADRW interview questions
  • Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
  • Latency Bucket CounterDatadog · OA · PHONE SCREENDatadog interview questions
  • First Fibonacci Number at Least the Array SumBitGo · OABitGo interview questions

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int calculateLeftoverStacks(int[] stacks) {
      // write your code here
    }

}
Checking account…