Sherlock and Array

  • + 0 comments

    This codes give the exact output for all test cases ,yet the compiler shows wrong output! Can anyone tell me whats wrong into this code`

    public static String balancedSums(List<Integer> array) {
        // Write your code here
            Integer[] arr=(Integer[])array.toArray(new Integer[array.size()]);
            int[] pref=new int[arr.length];
            pref[0]=arr[0];
            for(int i=1;i<arr.length;i++){
                pref[i]=pref[i-1]+arr[i];
            } 
            for(int i=0;i<arr.length;i++){
                if((pref[i]-arr[i])==pref[arr.length-1]-pref[i]){
                    return "Yes";
                }
            }
            
            return "NO";
        }