vmware 电面

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 “_”.

class HangmanSolver {

	public HangmanSolver(String[] dict) {
		// todo
	}
	
	public List<String> solve(String puzzle) {
		// todo
	}
}

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:

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