Count the letters, not the order.
transcript
Stone and tones. Same letters, new order. Do not sort them. Count them. Rearranged letters hide in tags. A scan for each letter is slow.
The first word is stone. Add one for each letter. Five counts are now one. The sheet has a row for each letter. One tally for each letter. The order does not matter.
Now the second word, tones. Take one away for each letter. Each count cancels. Every count ends at zero. A count below zero means no. An extra letter cancels nothing.
Check the lengths first. Never let a count go below zero. Then every count ends at zero. One pass for each word. Twenty six counts. Constant space. Sorting works too. It is n log n. Unicode needs a map. The idea is a count for each key. Say your alphabet aloud. Sorting needs no array.
Count the letters. Full breakdown in the lecture.