Chris Navigates a Maze

Company: Throughput_28thjuly

Difficulty: medium

Problem Statement

Chris and Alex are contestants in a game show where they navigate a maze with hidden gold coins. Chris must collect all of the gold coins and then deliver them to Alex's location. Chris can move horizontally or vertically within the maze through unblocked cells. The maze is represented as an n x m grid. Each cell holds one of three values: 0 means an open cell, 1 means a blocked cell, and 2 means an open cell containing a gold coin. Chris starts at position (0, 0) . Alex is at a specified position (x, y) . Return the length of the shortest path for Chris to collect all gold coins and reach Alex. If it is not possible to collect all coins and reach Alex, return -1 . The length of a path is the number of moves Chris makes. Each move goes from a cell to one of its four side-adjacent cells (up, down, left or right) and costs 1 . Chris may never step onto a blocked cell and may never leave the grid, but he may revisit cells as many times as he likes. A gold coin is picked up simply by