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.

  • 2
    Welcome to EL&U. I would think the answer depends on how loosely you define anagram, and how that compares with the software author's definition. What does the dictionary say? Is this a case of the software having a bug as opposed to a question of language? – choster Sep 12 '15 at 3:23
  • 5
    A mathematician would call that the trivial anagram. If you want to exclude it, you want an anagram which is nontrivial. – Nate Eldredge Sep 12 '15 at 3:25
  • 2
    @choster nailed it. As a concrete example: in a programming language I use, J, there is a primitive called A. (for anagram). It takes two arguments: a word (or any list of things), and an anagram index. The anagram index can run from 0 to n!-1, where n 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
  • relevant: english.stackexchange.com/questions/45712/… in both cases, I think there is not any unanimous consensus on whether to include or exclude the trivial examples. – herisson Sep 12 '15 at 21:06
  • 2
    "stifle" is an anagram of "itself" if you want to be a wiseass. – user662852 Sep 23 '15 at 15:20

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.