I am solving the algorithm problem Valid Anagram. The official answer judges that "hello" is a valid anagram of "hello". I am doubting this test is wrong.
The usual definition of anagram is:
A word, phrase, or name formed by rearranging the letters of another, such as spar, formed from rasp.
In the trivial case where you have the same arrangement, it's not another word. Similarly, we don't consider words to be synonyms or homonyms of themselves -- these terms are only used when referring to different words.
The website you link to won't let me see the solution (I guess I have to sign up). I expect that it doesn't really match the real definition, it just tests whether two strings consist of the same characters. In particular, I'll bet it doesn't actually test whether the inputs are real words.
A.
(for anagram). It takes two arguments: a word (or any list of things), and an anagram index. The anagram index can run from0
ton!-1
, wheren
is the number of letters in the word (or more generally items in the list). Anagram index 0 always produces the word itself. In other words: in rigorous systems, yes, a word is an anagram of itself (just like a set is a subset of itself). – Dan Bron Sep 12 '15 at 3:48