Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

Given an N x M grid representing a map with two cars, "a" and "b". Each car can move up, down, left, right, or stay in place at each step. The grid contains the following symbols:

  • ".": Road (movable).
  • "#": Wall (impassable).
  • "a": Starting position of car a.
  • "b": Starting position of car b.
  • "A": Destination for car a.
  • "B": Destination for car b.
Test Cases
Input
Output
Expected