A word search is a matrix of letters as defined in Word Search Puzzle Generation. For a word search to contain a word, it means that that word appears somewhere in the matrix horizontally, vertically, or diagonally.

Your task is to write a program that takes a list of strings and outputs the dimensions of the smallest-area word search that contains those strings.


  • You can assume the word search and the input strings consist of only lowercase ASCII letters.
  • You can output the dimensions in either order (y x instead of x y) because it doesn't matter to the word search.
  • This is , so the shortest valid solution (in bytes) wins.

Test Cases

word                     -> 4 1
hello, e                 -> 5 1
hello, f                 -> 6 1
small, llama             -> 8 1
words, other             -> 5 2
words, order, about, orb -> 5 3
  • 5
    \$\begingroup\$ I'm not convinced that makes a meaningful difference? Do you have any reason to suspect any algorithm that would be competitive here and not if you had to print it? \$\endgroup\$ – FryAmTheEggman Feb 21 '17 at 23:44
  • \$\begingroup\$ Actually, there's a fairly major difference: that challenge asked for squares, this one for rectangles, and that may well make a large difference. If not for that, though, I'd call it a duplicate; the difference in output format might change which language wins, but it's unlikely to change the non-output part of the algorithms. \$\endgroup\$ – user62131 Feb 22 '17 at 6:06
  • \$\begingroup\$ None of the test cases include diagonals, you should probably add one for that. \$\endgroup\$ – ETHproductions Feb 22 '17 at 13:31
  • 1
    \$\begingroup\$ Wouldn't hello, f be 6 1 ? 6x1 is smaller than 5x2 \$\endgroup\$ – NibblyPig Feb 22 '17 at 14:48
  • \$\begingroup\$ @SLC Yes, edited. \$\endgroup\$ – Esolanging Fruit Feb 23 '17 at 2:28