Algorithm for grouping anagram words

前端 未结 14 1546
悲&欢浪女
悲&欢浪女 2020-12-07 23:30

Given a set of words, we need to find the anagram words and display each category alone using the best algorithm.

input:

man car kile arc none like
<         


        
14条回答
  •  悲&欢浪女
    2020-12-08 00:07

    Anagrams can be found in following way:

    1. Length of word should match.
    2. Perform addition of each character in terms of integer value. This sum will match if you perform same on anagram.
    3. Perform multiplication of each character in terms of integer value. Evaluated value will match if you perform same on anagram.

    So I thought through above three validations, we can find anagrams. Correct me if I'm wrong.


    Example: abc cba

    Length of both words is 3.

    Sum of individual characters for both words is 294.

    Prod of individual characters for both words is 941094.

提交回复
热议问题