Word Jumble Algorithm

后端 未结 5 1385
执笔经年
执笔经年 2021-01-18 02:04

Given a word jumble (i.e. ofbaor), what would be an approach to unscramble the letters to create a real word (i.e. foobar)? I could see this having a couple of approaches, a

5条回答
  •  抹茶落季
    2021-01-18 02:14

    Have a dictionary that's keyed by the letters of each word in sorted order. Then take you jumble an sort the letters - look up all the words in the dictionary by that sorted-letter string.

    So, as an example, the words 'bear' and 'bare' would be in the dictionary as follows:

    key    word
    -----  ------
    aber    bear
    aber    bare
    

    And if you're given the jumble, 'earb', you'd sort the letters to 'aber' and be able to look up both possible words in the dictionary.

提交回复
热议问题