You are viewing a single comment's thread. Return to all comments →
public static void whatsNext(List<long> arr) { var tzc = 0L; if (arr.Count % 2 == 0) { tzc = arr[^1]; arr.RemoveAt(arr.Count - 1); } var toc = arr[^1]; if (arr.Count > 1) { --arr[^2]; } arr[^1] = 1; arr.Add(1 + tzc); arr.Add(toc - 1); for (var i = 1; i < arr.Count - 1; ) { if (arr[i] == 0) { arr[i - 1] += arr[i + 1]; arr.RemoveRange(i, 2); } else { ++i; } } if (arr[^1] == 0) { arr.RemoveAt(arr.Count - 1); } Console.WriteLine(arr.Count); Console.WriteLine(string.Join(' ', arr)); }
Seems like cookies are disabled on this browser, please enable them to open this website
What's Next?
You are viewing a single comment's thread. Return to all comments →