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
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Heap
  4. Jesse and Cookies
  5. Discussions

Jesse and Cookies

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • AymaneHrouch
    4 months ago+ 1 comment

    What's wrong with my code please??

    class Result {
    
        /*
         * Complete the 'cookies' function below.
         *
         * The function is expected to return an INTEGER.
         * The function accepts following parameters:
         *  1. INTEGER k
         *  2. INTEGER_ARRAY A
         */
    
        public static int iterations = 0;
        public static int cookies(int k, List<Integer> A) {
            Collections.sort(A);
            int a = A.get(0);
            int b = A.get(1);
            if(a>=k && b>=k) {
                return iterations;
            }
            A.remove(0);
            A.remove(1);
            A.add(a+2*b);
            iterations++;
            return cookies(k, A);
        }
    }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy