FastPrepCut the Sticks
Problems/Cut the Sticks

Cut the Sticks

Microsoft logoMicrosoft● EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Microsoft internship assessment report described this cutting process and shared the example [1, 1, 3, 4] -> [4, 2, 1]. The report left out the function signature and the input limits, so we state them here. Our version is about 99% the same as the reported question.

Given an array of positive integer rod lengths lengths, repeatedly perform cutting rounds while at least one rod remains.

At the start of each round, record the number of remaining rods. Then subtract the length of the shortest remaining rod from every remaining rod. Remove every rod whose length becomes 0.

Return the recorded rod counts in round order.

Function

cutSticks(lengths: int[]) → int[]

Examples

Example 1

lengths = [1,1,3,4]return = [4,2,1]

The first round starts with 4 rods and removes the two rods of length 1. The remaining lengths are [2, 3]. The next two rounds start with 2 rods and then 1 rod.

Example 2

lengths = [5,4,4,2,2,8]return = [6,4,2,1]

The distinct positive lengths are 2, 4, 5, and 8. Respectively, 6, 4, 2, and 1 rods remain when those levels are removed.

Constraints

  • 1 <= lengths.length <= 200000
  • 1 <= lengths[i] <= 1000000000

More Microsoft Online Assessment questions

  • Authentication SystemOA · 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
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
  • Minimum Cost K-Capable ModelsOA · Seen Nov 2026
  • Find Available Meeting RoomsOA · Seen Oct 2026

Similar questions at other companies

  • Macaron Order with Set DiscountsShopify · OAShopify interview questions
  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • TV Shows Produced During a PeriodRippling · OARippling interview questions
  • Capping Portfolio WeightsCapstone Investment Advisors · OA
  • Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
  • Macaron Order PriceOpenAI · OAOpenAI interview questions
  • Parcel Attribute Store with TTLAirbnb · OAAirbnb interview questions
  • Sorted Cyclic Shift Difference SumsCapital One · OACapital One interview questions
  • Optimize Package Order by Sorting One WindowAmazon · OA
  • Track Received Byte RangesRoblox · OARoblox interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

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)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[] cutSticks(int[] lengths) {
        // write your code here
    }
}
Checking account…