Word morph game

I came across this interview question recently:

Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at a time. The new word you get in each step must be in the dictionary.

I thought it was a neat problem and was bored enough to code a web version of this. Check it out at

http://106.187.92.122/word_morph

The PHP script calls an external C++ program, which can be viewed here:

http://106.187.92.122/word_morph/word_morph.cpp

 

2 thoughts on “Word morph game”

  1. Hi Nghia!

    Loved your post about finding cycles in a linked list.
    I went on to read this post and I was interested in how you solved this problem. I’m not very good at PHP and I was wondering if you could give a run down of how you approached the problem.

    Thank you so much! 🙂

    1. Been a while since I looked at this. It’s one of those CS type interview problems I came across. You basically do a brute force by changing one letter at a time, and if the word exists you keep it for the next iteration. It’s a tree type search, similar to finding moves in chess I guess. Eventually you either find the destination word or hit a dead end.

Leave a Reply

Your email address will not be published. Required fields are marked *