HackerRank: Cut the sticks (Easy)

Link to code challenge
function cutTheSticks(arr) { let sticksLeft = []; while (arr.length > 0) { sticksLeft.push(arr.length); arr.sort((a, b) => b - a); let lowest = arr[arr.length - 1]; for (let i = arr.length - 1; i >= 0; i--) { if (arr[i] === lowest) arr.splice(i, 1); else arr[i] -= lowest; } } return sticksLeft; }

Comments

Popular posts from this blog

Code Wars: Data Reverse (6 kyu)

Code Wars: longest_palindrome (6 kyu)

Code Wars: Find the odd int