We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

# Cut the sticks

# Cut the sticks

#### Sort by

recency

#### |

#### 2053 Discussions

#### |

Please Login in order to post a comment

def cutTheSticks(arr): # Write your code here result = [] if len(arr) <= 0: result.append(0) return result

C#public static List cutTheSticks(List arr) { var results = new List();}

I know, this is just a "remove min elements, add the new length of the array to the return array" problem but this is how it can be done in C. Welcome to relatively low level programming guys:

The requirement is presented as:

"The shortest stick length is 1 , so cut that length from the longer two and discard the pieces of length"

So: first cut, then discard pieces same length as the shortest. But the solution is expected to be: first discard sticks of shortest length, and then cut the bigger sticks. Moreover the other requirement is that result list contains the size of the list

aftereach iteration, but the solution is expected to include the size of the listat the beginningof any iteration.How is this question different from just iteratively removing the smallest elements? I tried the following, and it passes test cases, but fails most of the others.

List number = new List(); while (arr.Count > 0) { number.Add(arr.Count); arr.RemoveAll(i => i == arr.Min()); } return number;