Skip to content
DeepForgeby svx
All problems
MediumAlgorithmsal-206

Boggle Word Count

Problem

Given a board of characters and a list of words, return how many words can be traced through horizontally or vertically adjacent cells without reusing a cell.

Run DFS from every cell for each word, temporarily marking visited cells and restoring them while backtracking. Each list entry is counted separately, and an empty word list gives 0.

Hint

The same word appearing twice in the list counts twice.

Test cases

case 1
in: [[["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]],["ABCCED","SEE","ABCB"]]
expected: 2
case 2
in: [[["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]],["A","B"]]
expected: 2
case 3
in: [[["a"]],["a","b"]]
expected: 1
case 4
in: [[[]],["a"]]
expected: 0
case 5
in: [[["A"]],[]]
expected: 0
Starter codePython
def boggle_word_count(board, words):
    # Your code here
    pass

5 test cases · run your code against them in the editor