• + 0 comments

    C#

     public static List<int> cutTheSticks(List<int> arr)
        {
            List<int> stickCut = new List<int>();
    
            stickCut.Add(arr.Count);
    
            arr.Sort();
    
            while (arr.Count > 0)
            {
                int min = arr[0];
                for (int i = 0; i < arr.Count; i++)
                {
                    arr[i] = arr[i] - min;
                }
                arr.RemoveAll(x => x == 0);
                stickCut.Add(arr.Count);
            }
            stickCut.RemoveAt(stickCut.Count - 1);
            return stickCut;
    
        }