bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 913. Cat and Mouse

913. Cat and Mouse

Leetcode Solutions

Minimax Algorithm with Percolation from Resolved States

  1. Initialize color, a map of states to their outcome (MOUSE, CAT, DRAW).
  2. Initialize a queue and add all initially resolved states to it.
  3. While the queue is not empty: a. Dequeue a state. b. For each parent state of the dequeued state: i. If immediate coloring is possible, color the parent state. ii. If not, decrement the count of DRAW children. iii. If the count of DRAW children is zero, apply eventual coloring. c. Enqueue any newly colored parent states.
  4. After processing all states, return the color of the initial state (1, 2, 1).
UML Thumbnail

Depth-First Search with Memoization

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...