What's wrong in the solution??

I have been trying to solve LAPINDROME.
Link

Getting the wrong answer for that.

Can somebody help me with this code. Thanks

Here is the code.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Lapindrome{
	
	
public static void main(String[] args) throws NumberFormatException, IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int t = Integer.parseInt(br.readLine());
	while(t-->0){
		String s =br.readLine();
		int arr[] = new int[26];
		int flag =0;
		int harr[] = new int[26];
		Arrays.fill(arr, 0);
		Arrays.fill(harr, 0);

		char[] chars = s.toCharArray();
		int split = chars.length/2;
		for(int i=0;i<split ;i++){
			arr[chars[i] - 'a'] +=1;
		}
		
		if(chars.length%2!=0)
			split+=1;
		for(int i=split;i<chars.length ;i++){
			harr[chars[i] - 'a'] +=1;
		}
		
		for(int i=0; i<chars.length;i++){
			if(arr[chars[i]-'a']==harr[chars[i] - 'a']){
				flag = 1;
			}
			else
				flag = 0  ;
		}
		
		if(flag==1){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
		
	}
	br.close();
	}
}

INPUT :

1

xzyz

YOUR OUTPUT :

YES

EXPECTED is NO …

if last character’s(in both halves) frequency is same then your code is printing YES regardless of other characters …
modify the last loop.