Cut the Sticks
Updated
Problem statement
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 <= 2000001 <= 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