• + 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);
        }
    }