We’re preparing your current view and syncing the latest data.
Cat and Mouse Game
gfgYou are given a grid representing a game environment where a mouse and a cat move alternately. The mouse starts at one cell, the cat at another, and there is a food cell. Each player can move up to a certain maximum number of steps in one direction per turn. The mouse moves first, then the cat. The goal is to determine if the mouse can guarantee a win by reaching the food before being caught by the cat or before the cat reaches the food first.
The input is a grid of characters where '#', 'M', 'C', '.' and 'F' represent wall, mouse start, cat start, empty cell, and food respectively. Additional input includes max jump lengths for mouse and cat.
Return true if the mouse can win under optimal play, otherwise false.
The grid size will not exceed 8x8. The maximum jump length for mouse and cat is between 1 and 8.
Example 1
Input
grid = ["####F#","#C....","#M####"], catJump = 1, mouseJump = 2
Output
true
Explanation
The mouse can reach the food before the cat, given their movement constraints and the grid layout.