MCPcopy Create free account
hub / github.com/chaharnishant11/CodeIn10DSA / helper

Method helper

Backtracking/Code/wordSearch.cpp:3–16  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution {
2public:
3 bool helper(vector<vector<char>>& board,string word,int i,int j,int n,int m,int k){
4 if(k >= word.size())return true;
5 if(i<0 || i>=n || j<0 || j>=m || board[i][j]=='.' || word[k]!=board[i][j]) return false;
6 if(word.size() == 1 && word[k]==board[i][j]) return true;
7 board[i][j] = '.';
8 bool temp = false;
9 int x[4] = {0,0,-1,1};
10 int y[4] = {-1,1,0,0};
11 for(int index=0;index<4;index++){
12 temp = temp || helper(board,word,i+x[index],j+y[index],n,m,k+1);
13 }
14 board[i][j] = word[k];
15 return temp;
16 }
17
18 bool exist(vector<vector<char>>& board,string word) {
19 int n=board.size();

Callers

nothing calls this directly

Calls 1

helperFunction · 0.70

Tested by

no test coverage detected