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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Cut the sticks
  5. Discussions

Cut the sticks

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

Sort 1926 Discussions, By:

recency

Please Login in order to post a comment

  • boyananavadeep56
    14 hours ago+ 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|
    Permalink
  • nguyentrungduc22
    3 days ago+ 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|
    Permalink
  • saivardhan96
    4 days ago+ 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|
    Permalink
  • yirijo5373
    5 days ago+ 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|
    Permalink
  • barunkr0801
    1 week ago+ 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;
        }
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy