Sort by

recency

|

2130 Discussions

|

  • + 0 comments
    public static List<Integer> cutTheSticks(List<Integer> arr) {
        List<Integer> result = new ArrayList<>();
        result.add((int)arr.stream().filter(s -> s!=0).count());
        while(arr.stream().filter(a -> a!=0).count() != 0) {
            int minval = arr.stream().mapToInt(s -> s).filter(s -> s != 0).min().getAsInt();
            arr = arr.stream().map(val -> val != 0 ? val-minval : val).collect(Collectors.toList());
            int cnt = (int)arr.stream().filter(s -> s!=0).count();
            if(cnt != 0) result.add(cnt);
        }
        return result;
    }
    
  • + 0 comments

    If you're planning something special and need a creative spark, Cut the Sticks is such a fun idea to bring people together. Whether it’s a birthday, shower, or even a backyard BBQ, this game adds a playful twist to the event. It’s one of those simple setups that creates big laughs and unforgettable memories. As an Event Consultant SoCal, I’ve seen how these small touches turn casual gatherings into standout celebrations. Guests love the challenge, and it keeps everyone engaged without needing a big production. Just grab some sticks, cut them to different lengths, and let the fun begin! It’s budget-friendly, interactive, and totally worth including in your event lineup.

  • + 0 comments

    Python code easy, please like.

    def cutTheSticks(arr):
        # Write your code here
        print(arr)
        c=[]
        while len(arr)>0:
            n=min(arr)
            arr=list(map(lambda x:x-n,arr))
            c.append(len(arr))
            arr=list(filter(lambda x:x!=0,arr))
        return c
     
    
  • + 0 comments

    Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-cut-the-sticks-problem-solution.html

  • + 0 comments

    JavaScript solution:

    function cutTheSticks(arr) {
        let sticks = [];
        
        while(arr.length){
            sticks.push(arr.length)
            const min = Math.min(...arr);
            arr = arr.map(stick => stick - min).filter(stick => stick);
        }
        
        return sticks;
    }