This is another question I was asked in the telephonic interview:
Given a dictionary and a crossword(2d matrix of characters) find all the dictionary words which can be found in the crossword.
All I could think of was hash the dictionary, find every possible word in the crossword and search the hash. I could not optimize it all.
Must admit Microsoft interview questions are tough :(
Please give me the lines to think on.
I would re-write your search() function to take two arguments --- a matrix and a target. Then you can call it with the initial matrix, and the transposed matrix. I'd also modify the search() function to search each row forwards and backwards (and I might make that last part optional).
How about:
I don't think a hash would be a very useful optimization here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With