Finding anagrams for a given word

后端 未结 12 1040
温柔的废话
温柔的废话 2020-12-04 07:43

Two words are anagrams if one of them has exactly same characters as that of the another word.

Example : Anagram & Nagaram are anagrams

12条回答
  •  一整个雨季
    2020-12-04 08:05

    One solution is - Map prime numbers to alphabet characters and multiply prime number

    For ex - 
    
        a -> 2
        b -> 3
        ......
        .......
        ......
        z -> 101
    

    So

    'ab' -> 6
    'ba' -> 6
    'bab' -> 18
    'abba' -> 36
    'baba' -> 36
    

    Get MUL_number for Given word. return all the words from dictionary which have same MUL_number as given word

提交回复
热议问题