You are using sum as the comparing logic which is not the correct approach. Try it for these strings:
These should be NO but give output as YES because according to your code,
sum(ad) = sum (bc)
sum(il) = sum(jk)
sum(wz) = sum(xy)
Hope you understand the mistake.
i didn’t considered all the possibilities, yes i got it.