C# Queue
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\npublic class Solution {\n\n        public int NearestExit(char[][] maze, int[] entrance)\n        {\n            int result = -1;\n            bool[][] visited = new bool[maze.Length][];\n            for (int i = 0; i < maze.Length; i++)\n            {\n                visited[i] = new bool[maze[i].Length];\n                for (int j = 0; j < maze[i].Length; j++)\n                {\n                    if (maze[i][j] == \'+\')\n                    {\n                        visited[i][j] = true;\n                    }\n                }\n            }\n            Queue<(int, int, int)> queue = new();\n\n            queue.Enqueue((0, entrance[0], entrance[1]));\n            visited[entrance[0]][entrance[1]] = true;\n            while (queue.Count > 0)\n            {\n                (int count, int x, int y) = queue.Dequeue();\n\n                if ((x != entrance[0] || y != entrance[1]) && (x == maze.Length - 1 || x == 0 || y == maze[x].Length - 1 || y == 0)) return count;\n\n                count++;\n                //top y-1\n                CheckCoordinatesAndEnqueue(maze, queue, visited, count, x, y-1);\n\n                //bottom y+1\n                CheckCoordinatesAndEnqueue(maze, queue, visited, count, x, y+1);\n\n                //left x-1\n                CheckCoordinatesAndEnqueue(maze, queue, visited, count, x-1, y);\n\n                //right x+1\n                CheckCoordinatesAndEnqueue(maze, queue, visited, count, x+1, y);\n            }\n\n            return result;\n        }\n\n        private void CheckCoordinatesAndEnqueue(char[][] maze, Queue<(int, int, int)> queue, bool[][] visited, params int[] arr)\n        {\n            int count = arr[0];\n            int x = arr[1];\n            int y = arr[2];\n\n            if (x >= 0 && x < maze.Length && y >= 0 && y < maze[x].Length && !visited[x][y])\n            {\n                queue.Enqueue((count, x, y));\n                visited[x][y] = true;\n            }\n        }\n     \n}\n```
['C#']