• + 0 comments
    function cutTheSticks(sticks) {
        let ans = []; 
        let min = Math.min(...sticks); 
        
        while(sticks.length) {
            ans.push(sticks.length); 
            let newSticks = []; 
            let newMin = 1001; 
            
            for(let length of sticks) {
                let newLength = length - min; 
                if(newLength > 0) {
                    newSticks.push(newLength); 
                    newMin = Math.min(newMin, newLength); 
                }
            }
            min = newMin; 
            sticks = [...newSticks]; 
        }
        
        return ans; 
    }