function to check if N and K are anagrams
function isValid ( N , K ) { let m1 = new Set ( ) ; let m2 = new Set ( ) ; while ( N > 0 ) { m1 . add ( N % 10 ) ; N = Math . floor ( N / 10 ) ; } while ( K > 0 ) { m2 . add ( K % 10 ) ; K = Math . floor ( K / 10 ) ; } let s = new Set ( [ ... m1 , ... m2 ] ) return s . size == m1 . size && s . size == m2 . size }