Given a 2D grid of characters where 'S' represents the start position, 'T' represents the target, 'O' represents open spaces, and 'X' represents walls, find the shortest path from 'S' to 'T'. You can move up, down, left, or right.
Input: grid = [
['S', 'O', 'X', 'O'],
['O', 'O', 'X', 'O'],
['X', 'O', 'O', 'T'],
['O', 'X', 'X', 'O']
]
Output: 5
Explanation: The shortest path is 5 steps.
When the function findShortestPath is called with the given example input, the expected output is:
5.const grid = [
['S', 'O', 'X', 'O'],
['O', 'O', 'X', 'O'],
['X', 'O', 'O', 'T'],
['O', 'X', 'X', 'O']
];
console.log(findShortestPath(grid)); // Output: 5
Memory: 0
CPU: 0