Feature #2: Search for Maximum Number of Words in the Boggle Grid
Implementing the "Search for Maximum Number of Words in the Boggle Grid" feature for our "Boggle" project.
We'll cover the following
Description
This feature will be used in the game’s difficult mode. For this feature, we will be given a list of words. We have to implement a module that finds the maximum number of the given words that exist in the Boggle grid. The rules we discussed in the previous lesson for finding words in the Boggle board also apply here. To review, these rules are:
- Words can be constructed from the letters in sequentially adjacent cells.
- These adjacent cells can be horizontal or vertical neighbors only. Diagonally opposite cells are not considered adjacent.
- A cell can only be part of one word on the Boggle board.
The module will take in two inputs: the grid (in the form of a 2D list of characters) and a list of possible words. Our module should return a list containing the words from the input list that were also found in the Boggle grid. Suppose, the grid is [['B', 'S', 'L', 'I', 'M'], ['R', 'I', 'L', 'M', 'O'], ['O', 'L', 'I', 'E', 'O'], ['R', 'Y', 'I', 'L', 'N'], ['B', 'U', 'N', 'E', 'C']]
, and the words to be searched are ["BUY", "SLICK", "SLIME", "ONLINE", "NOW"]
. In this case, the feature will output: ["SLIME", "ONLINE", "BUY"]
. A visual representation of this example is given below:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.