VMware | Phone | Hangman Solver

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2019-12-17Added By Anonymous
Source: Link

Design data structure for HangMan solver game. We are given array of lexocographically sorted strings 'dict[]' as input and a pattern 'puzzle', return list of all the words matching pattern 'puzzle'. 'puzzle' is a pattern containing underscore character "_".

1class HangmanSolver { 2 3 public HangmanSolver(String[] dict) { 4 // todo 5 } 6 7 public List<String> solve(String puzzle) { 8 // todo 9 } 10}


Here solve method could be called multiple times however HangManSolver() will be called only once. So the problem is to process strings in the input array and store in a data structure efficient for searching strings matching given pattern.


Example:

1HangmanSolver solver = new HangmanSolver(["ant", "feet", "meet", "zebra"]); 2solver.solve("_e_t"); // ["feet", "meet"]
Comments