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.
Cut the sticks
Cut the sticks
+ 0 comments python
def cutTheSticks(arr): f=[] while True: f.append(len(arr)) m=min(arr) for i in range(len(arr)): arr[i]=arr[i]-m for j in range(len(arr)): try: l=arr.index(0) arr.pop(l) except:pass if len(arr)<1: break return f
+ 0 comments JS
const sticks_cut = [arr.length]; let arrCut = arr; while (1) { let length_cut = Math.min(...arrCut); arrCut = arrCut .filter((item) => item !== length_cut) .map((item) => item - length_cut); if (arrCut.length === 0) break; sticks_cut.push(arrCut.length); } return sticks_cut
+ 0 comments >>>>>>> JAVA SOLUTION <<<<<<< public static List<Integer> cutTheSticks(List<Integer> a) { Collections.sort(a); List<Integer> ans=new ArrayList<Integer>(); int pointer=0; int fin=a.get(a.size()-1); while(true){ int small=a.get(pointer); ans.add(a.size()-pointer); if(small==fin) break; while (a.get(pointer) == small ) { pointer++; } } return ans; }
+ 0 comments "Cut the Sticks" is an engaging puzzle game that requires strategic thinking and careful planning. The goal is to remove all the sticks on the board by making a limited number of cuts. Each cut reduces the length of the sticks, and the challenge lies in determining the optimal sequence to minimize the number of cuts needed. As the levels progress, the puzzles become more complex, testing your logical reasoning and problem-solving skills. With its simple yet addictive gameplay, "Cut the Sticks" offers a delightful brain-teasing experience that will keep you entertained and engaged as you unravel the puzzles one cut at a time.
+ 0 comments java 8 :
public static List<Integer> cutTheSticks(List<Integer> arr) { int count=0; List<Integer> res = new ArrayList<>(); while(arr.size>0){ int sm = Collections.min(arr); for(int j = 0 ; j<arr.size(); j++){ arr.set(j, arr.get(j)-sm); count++; } res.add(count); count = 0; arr = arr.stream().filter(x -> x>0).collect(Collectors.toList()); } return res; }
Load more conversations
Sort 1926 Discussions, By:
Please Login in order to post a comment