In Detail Explanation 💯 || [Java/C++/JavaScript/Python3/C#/Go]
Approach\n\n#### Main Method (exist):\n1. Iterate through each cell of the board using nested loops.\n2. For each cell, if the character matches the first chara
# Approach\n\n#### Main Method (`exist`):\n1. Iterate through each cell of the board using nested loops.\n2. For each cell, if the character matches the first character of the word:\n   - Initiate a DFS from that cell to search for the entire word.\n   - If the DFS returns true (indicating the word is found), return true.\n3. If no match is found after iterating through all cells, return false.\n\n#### DFS Method (`dfs`):\n1. Base Case:\n   - If the count of characters processed equals the length of the word, return true (indicating the entire word is found).\n   - If the current cell is out of bounds or does not match the next character of the word, return false.\n2. Store the current character of the board in a temporary variable and mark the current cell as visited.\n3. Recursively explore neighboring cells in all four directions (up, down, left, right) to find the remaining characters of the word.\n4. If any of the recursive calls return true, indicating the word is found, set `found` to true.\n5. Restore the original character at the current cell and return `found`.\n\n# Complexity\n- Time complexity: $$O(m \\cdot n \\cdot 4^{L})$$\n    - *In the given scenario, `m` and `n` denote the dimensions of a grid, while `l` signifies the length of word. The expression `4^l` denotes the potential maximum number of recursive iterations required for each starting cell.*\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(L)$$\n    -  *where l is the length of the word. The space complexity is primarily due to the recursive stack depth during the DFS traversal.* \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```Java []\nclass Solution {\n    public boolean exist(char[][] board, String word) {\n        for(int i=0; i<board.length; i++) {\n            for(int j=0; j<board[0].length; j++) {\n                if(board[i][j] == word.charAt(0) && dfs(board, i, j, 0, word)) {\n                    return true;\n                }\n            }\n        }\n        return false;\n    }\n\n    private boolean dfs(char[][] board, int i, int j, int count, String word) {\n        if(count == word.length()) {\n            return true;\n        }\n\n        if(i==-1 || i==board.length || j==-1 || j==board[0].length || board[i][j]!=word.charAt(count)) {\n            return false;\n        }\n\n        char temp = board[i][j];\n        board[i][j] = \'*\';\n        boolean found = dfs(board, i+1, j, count+1, word) ||\n                        dfs(board, i-1, j, count+1, word) ||\n                        dfs(board, i, j+1, count+1, word) ||\n                        dfs(board, i, j-1, count+1, word);\n        board[i][j] = temp;\n        return found;\n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    bool exist(vector<vector<char>>& board, string word) {\n        for (int i = 0; i < board.size(); ++i) {\n            for (int j = 0; j < board[0].size(); ++j) {\n                if (board[i][j] == word[0] && dfs(board, i, j, 0, word)) {\n                    return true;\n                }\n            }\n        }\n        return false;\n    }\n\nprivate:\n    bool dfs(vector<vector<char>>& board, int i, int j, int count, string word) {\n        if (count == word.length()) {\n            return true;\n        }\n\n        if (i == -1 || i == board.size() || j == -1 || j == board[0].size() || board[i][j] != word[count]) {\n            return false;\n        }\n\n        char temp = board[i][j];\n        board[i][j] = \'*\';\n        bool found = dfs(board, i + 1, j, count + 1, word) ||\n                     dfs(board, i - 1, j, count + 1, word) ||\n                     dfs(board, i, j + 1, count + 1, word) ||\n                     dfs(board, i, j - 1, count + 1, word);\n        board[i][j] = temp;\n        return found;\n    }\n```\n```Python3 []\nclass Solution:\n    def exist(self, board: List[List[str]], word: str) -> bool:\n        for i in range(len(board)):\n            for j in range(len(board[0])):\n                if board[i][j] == word[0] and self.dfs(board, i, j, 0, word):\n                    return True\n        return False\n\n    def dfs(self, board: List[List[str]], i: int, j: int, count: int, word: str) -> bool:\n        if count == len(word):\n            return True\n\n        if i < 0 or i >= len(board) or j < 0 or j >= len(board[0]) or board[i][j] != word[count]:\n            return False\n\n        temp = board[i][j]\n        board[i][j] = \'*\'\n        found = self.dfs(board, i + 1, j, count + 1, word) or \\\n                self.dfs(board, i - 1, j, count + 1, word) or \\\n                self.dfs(board, i, j + 1, count + 1, word) or \\\n                self.dfs(board, i, j - 1, count + 1, word)\n        board[i][j] = temp\n        return found\n```\n```Go []\nfunc exist(board [][]byte, word string) bool {\n    for i := 0; i < len(board); i++ {\n        for j := 0; j < len(board[0]); j++ {\n            if board[i][j] == word[0] && dfs(board, i, j, 0, word) {\n                return true\n            }\n        }\n    }\n    return false\n}\n\nfunc dfs(board [][]byte, i, j, count int, word string) bool {\n    if count == len(word) {\n        return true\n    }\n\n    if i < 0 || i >= len(board) || j < 0 || j >= len(board[0]) || board[i][j] != word[count] {\n        return false\n    }\n\n    temp := board[i][j]\n    board[i][j] = \'*\'\n    found := dfs(board, i+1, j, count+1, word) ||\n             dfs(board, i-1, j, count+1, word) ||\n             dfs(board, i, j+1, count+1, word) ||\n             dfs(board, i, j-1, count+1, word)\n    board[i][j] = temp\n    return found\n}\n```\n```C# []\npublic class Solution {\n    public bool Exist(char[][] board, string word) {\n        for (int i = 0; i < board.Length; i++) {\n            for (int j = 0; j < board[0].Length; j++) {\n                if (board[i][j] == word[0] && Dfs(board, i, j, 0, word)) {\n                    return true;\n                }\n            }\n        }\n        return false;\n    }\n\n    private bool Dfs(char[][] board, int i, int j, int count, string word) {\n        if (count == word.Length) {\n            return true;\n        }\n\n        if (i < 0 || i >= board.Length || j < 0 || j >= board[0].Length || board[i][j] != word[count]) {\n            return false;\n        }\n\n        char temp = board[i][j];\n        board[i][j] = \'*\';\n        bool found = Dfs(board, i + 1, j, count + 1, word) ||\n                     Dfs(board, i - 1, j, count + 1, word) ||\n                     Dfs(board, i, j + 1, count + 1, word) ||\n                     Dfs(board, i, j - 1, count + 1, word);\n        board[i][j] = temp;\n        return found;\n    }\n}\n```\n```JavaScript []\n/**\n * @param {character[][]} board\n * @param {string} word\n * @return {boolean}\n */\nvar exist = function(board, word) {\n    for (let i = 0; i < board.length; i++) {\n        for (let j = 0; j < board[0].length; j++) {\n            if (board[i][j] === word[0] && dfs(board, i, j, 0, word)) {\n                return true;\n            }\n        }\n    }\n    return false;\n};\n\nfunction dfs(board, i, j, count, word) {\n    if (count === word.length) {\n        return true;\n    }\n\n    if (i < 0 || i >= board.length || j < 0 || j >= board[0].length || board[i][j] !== word[count]) {\n        return false;\n    }\n\n    let temp = board[i][j];\n    board[i][j] = \'*\';\n    let found = dfs(board, i + 1, j, count + 1, word) ||\n                dfs(board, i - 1, j, count + 1, word) ||\n                dfs(board, i, j + 1, count + 1, word) ||\n                dfs(board, i, j - 1, count + 1, word);\n    board[i][j] = temp;\n    return found;\n}\n```\n\n---\n\n\n---\n\n![5c63d377-8ef4-4beb-b09d-0edb07e09a41_1702955205.6568592.png](https://assets.leetcode.com/users/images/e84753fa-0cfc-4b86-9959-412e459a5683_1712130875.936003.png)\n\n
['Backtracking', 'Python', 'C++', 'Java', 'Go', 'Python3', 'C#']