Leetcode Problem 1728. Cat and Mouse II

1728. Cat and Mouse II

Leetcode Solutions

DFS + Memoization + Game Theory

  1. Initialize a memoization table to store the outcome of game states.
  2. Define the DFS function that takes the current positions of the cat and mouse, and the number of turns taken so far.
  3. If the current state is already in the memoization table, return the stored result.
  4. If the number of turns exceeds the threshold, return false (cat wins).
  5. If the mouse reaches the food or the cat catches the mouse, return the appropriate outcome.
  6. On the mouse's turn, explore all possible moves the mouse can make. If any move leads to a winning state, return true.
  7. On the cat's turn, explore all possible moves the cat can make. If any move leads to a losing state for the mouse, return false.
  8. Store the result in the memoization table and return it.
UML Thumbnail

BFS + Early Stopping

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...