CPP Solution; 20 ms runtime; better than 100% memory usage;
Implements a simple DFS; Code is commented where I thought necessary, hope this helps. Comment if you have any queries!\n\n\tclass Solution {\n\tpulic:\n    boo
Implements a simple DFS; Code is commented where I thought necessary, hope this helps. Comment if you have any queries!\n\n\tclass Solution {\n\tpulic:\n    bool exist(vector<vector<char>>& board, string word) \n    {\n\t\t\tif(board.empty())\n\t\t\t\treturn false;\n        \n\t\t\tfor(int i=0; i<board.size(); i++)\n\t\t\t{\n\t\t\t\tfor(int j=0; j<board[0].size(); j++)\n\t\t\t\t{\n\t\t\t\t\tif(dfs(board, 0, i, j, word))\n\t\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n        \n        return false;\n    }\n    \n    bool dfs(vector<vector<char>>&board, int count, int i, int j, string& word)\n    {\n        if(word.size() == count) //Signifies that we have reached the end of search\n            return true;\n        \n        if(i<0 || j<0 || i>=board.size() || j>=board[0].size() || board[i][j]!=word[count])\n\t\treturn false;\n        //We check if element is within bounds and then check if the character at that is the same as the corresponding character in string word\n            \n    \n        char temp = board[i][j];\n        board[i][j] = \' \'; //To show that we have visited this node\n        \n        bool res = dfs(board, count+1, i+1, j, word) || dfs(board, count+1, i-1, j, word) || dfs(board, count+1, i, j+1, word) ||dfs(board, count+1, i, j-1, word); //DFS in all 4 directions\n        \n        board[i][j] = temp; //Restore the element after checking\n        \n        return res;\n    }\n\t};
['Depth-First Search', 'C++']