function to check if N and K are anagrams
static boolean isValid ( int N , int K ) { HashSet < Integer > m1 = new HashSet < Integer > ( ) ; HashSet < Integer > m2 = new HashSet < Integer > ( ) ; while ( N > 0 ) { m1 . add ( N % 10 ) ; N /= 10 ; } while ( K > 0 ) { m2 . add ( K % 10 ) ; K /= 10 ; } if ( m1 . equals ( m2 ) ) { return true ; } return false ; }