Why is it showing runtime error

import java.util.*;
class lappindrome
{
public static void main(String args[])
{

    Scanner sc=new Scanner(System.in);
    if(sc.hasNextInt()) {
    int t=sc.nextInt();
    while(t-->0)
    {
       sc.nextLine();
        String str=sc.nextLine();
      
        int[] arr= new int[26];
        int[] arr1= new int[26];
        int n=str.length();
        if(n%2==0)
        {
        	
            for(int i=0;i<n/2;i++)
            {
                arr[str.charAt(i)-97]++;
            }
            
            for(int j=n/2;j<n;j++)
            {
            	arr1[str.charAt(j)-97]++;
            }
            
            if(Arrays.equals(arr, arr1))  
            {
            	System.out.println("YES");
            }
            else
            {
            	
            	System.out.println("NO");
            }
        }
        else
        {
        	for(int i=0;i<n/2-1;i++)
        	{
        		arr[str.charAt(i)-97]++;
        	}
        	for(int j=((n/2)+1);j<n;j++)
        	{
        		arr1[str.charAt(j)-97]++;
        	}
        	if(Arrays.equals(arr, arr1))  
            {
            	System.out.println("YES");
            }
            else
            {
            	
            	System.out.println("NO");
            }
        }
    }
    
    
}

}
}

question link : CodeChef: Practical coding for everyone
while submitting the code why is it showing runtime error(NZEC)
solution code: CodeChef: Practical coding for everyone

I don’t (yet) know why it’s getting Runtime Error, but it’s definitely giving the wrong output for the following:

1
fff

Edit:

Hmmm … can’t think of any reason for Runtime Error unless there is some rogue whitespace in the test input.

Edit2:

Oh, I see - it will crash on the following testcase:

3
az
az
gh
2 Likes

okay !!!

thanks alot for helping me out atlast it worked with some edits
solution CodeChef: Practical coding for everyone

1 Like