bool dfs(char** board, int boardSize, int ColSize, char * word, int r, int c, int cnt,int len){
    if (r < 0 || r >= boardSize || c < 0 || c >= ColSize || board[r][c] != word[cnt])
        return false;

    if (len-1 == cnt)
        return true;

    board[r][c] = 0;
    bool flag = dfs(board, boardSize, ColSize, word, r - 1, c, cnt + 1, len) ||
                dfs(board, boardSize, ColSize, word, r + 1, c, cnt + 1, len) ||
                dfs(board, boardSize, ColSize, word, r, c-1, cnt + 1, len) ||
                dfs(board, boardSize, ColSize, word, r, c+1, cnt + 1, len);
    board[r][c] = word[cnt];
    return flag;

}
bool exist(char** board, int boardSize, int* boardColSize, char * word){
    int len = strlen(word);
    for (int i = 0; i < boardSize; i++)
        for (int j = 0; j < *boardColSize; j++)        
            if (dfs(board, boardSize, *boardColSize, word, i, j, 0, len))
                return true;
    return false;
}