MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / solve

Function solve

CPP/questions/word-search.cpp:5–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3using namespace std;
4
5bool solve(vector<vector<char>> &board, string &word, int index, int x, int y) {
6
7 if(index == word.length()) {
8 return true;
9 }
10
11 if(x < 0 || y < 0 || x >= board.size() || y >= board[0].size() || board[x][y] == '*')
12 return false;
13
14 if(board[x][y] != word[index])
15 return false;
16
17 char temp = board[x][y];
18 board[x][y] = '*';
19
20 if (
21 solve(board, word, index+1, x-1, y) ||
22 solve(board, word, index+1, x+1, y) ||
23 solve(board, word, index+1, x, y-1) ||
24 solve(board, word, index+1, x, y+1)
25 ) {
26 return true;
27 }
28
29 board[x][y] = temp;
30
31 return false;
32}
33
34bool exist(vector<vector<char>> &board, string word) {
35

Callers 1

existFunction · 0.70

Calls 2

lengthMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected