Prepin
Log in

Display all the words from a dictionary that appear on a specified boggle board.

Approach / Explanation

This question presents a 2D grid, commonly referred to as a boggle board, that is populated with letters. Along with this grid, you are provided with a dictionary of words. Your objective is to identify all the words from the dictionary that can be constructed by linking adjacent letters on the boggle board. You are allowed to move in any direction—up, down, left, right, or diagonally—to create words, but you must not revisit the same cell. The words that can be formed from the dictionary should be displayed. It is essential to grasp the problem fully. You need to: Navigate the boggle board Locate words within the dictionary that can be formed using the letters on the boggle board Be aware that a single cell cannot be utilized more than once in a word This task can be tackled using depth-first search (DFS), along with some enhancements, such as employing a Trie data structure to efficiently store and access the dictionary words.

Suggested Answer

As an illustration, let's examine a boggle board that looks like this: A B C E S F C S A D E E Assuming the dictionary includes the following words: { "SEE", "SEEN", "CS", "AS"} . In this scenario, we can create the word "SEE" by starting from the 'S' located at (1,0), then moving to the 'E' at (2,2), and finally reaching the 'E' at (2,3). Similarly, we can form "CS" by beginning at the 'C' found at (0,2) and then proceeding to the 'S' at (1,3). However, we cannot create the word "SEEN" since a single cell cannot be reused within the same word. Therefore, the result in this instance would be ["SEE","CS"] .

Alternative Answer

Another illustration could be a boggle board like this: T A C S O P Q H G And a dictionary that includes the words { "TOP", "SO", "SOAP", "CAP", "HOST"} . In this example, we can create "TOP" by starting from the 'T' located at (0,0), then moving to the 'O' at (1,1), and finally to the 'P' at (1,2). Similarly, "SO" can be formed by starting from the 'S' at (1,0) and then transitioning to the 'O' at (1,1). However, the word "CAP" cannot be formed because doing so would require revisiting the 'A' cell, which is not permitted. Therefore, the resulting output would be ["TOP","SO","SOAP","HOST"] .

Question Details

Difficulty & Category

Medium
algorithms

Companies

Microsoft

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.