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.
C#
public static List cutTheSticks(List arr)
{
var results = new List();
do
{
var smallestValue = arr.Min();
var operation = 0;
for (var i = 0; i < arr.Count; i++)
{
var value = arr[i] - smallestValue;
operation++;
if (value == 0)
{
arr.RemoveAt(i);
i--;
continue;
}
arr[i] = value;
}
results.Add(operation);
} while (arr.Count > 0);
return results;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cut the sticks
You are viewing a single comment's thread. Return to all comments →
C# public static List cutTheSticks(List arr) { var results = new List();
}