isPermutation - Azhagu's logic