Java anagrams

             static boolean isAnagram(String a, String b) {
        // Complete the function
        //convert everything to small char
        String A=a.toUpperCase();
        String B=b.toUpperCase();
        char[]array1=A.toCharArray();
        char[]array2=B.toCharArray();
        int size1=array1.length;
        int size2=array2.length;
        int[]array3=new int[size1];
        int[]array4=new int[size2];
        if(A.length()!=B.length()){
            return false;
        }
        else{
        for(int i=0;i<size1;i++){
            array3[i]=A.charAt(i)-'0';
        }
         for(int i=0;i<size2;i++){
            array4[i]=B.charAt(i)-'0';
        }
        for(int i=0;i<size1;i++){
            if(array3[i]==array4[i]){
                return true;
            }
            else{
                return false;
            }
        }
    }

-Out of 17 test case 6 test case is not right i donno why

Two strings, A and B, are called anagrams if they contain all the same characters in the same frequencies.
it’s not mean they are in same order
and you are checking for anagrams in order

2 Likes

Ok got it :slight_smile: thnku