Amazon Online Assessment (OA) - Maximal Minimum Value Path II

Given a 2D integer array, find the maximum score of a path from the upper left cell to the bottom right cell that doesn't revisit any of the cells. The score of a path is the minimum value in that path.

Examples

Example 1:

Input:
1[7,5,3]
2[2,0,9]
3[4,5,9]
Output: 3
Explanation:

Here are some paths from [0,0] to [2,2] and the minimum value on each path:

path: 7->2->4->5->9, minimum value on this path: 2.

path: 7->2->0->9->9, minimum value on this path: 0

path: 7->2->0->5->9, minimum value on this path: 0

Notice: the path can move in all four directions (not only right and down, but in ALL FOUR DIRECTIONS).

Here 7->2->0->5->3->9->9 is also a path, and the minimum value on this path is 0.

The path doesn't revisit the same cell twice. Therefore, 7->2->0->5->3->9->0->5->9 is not a valid path.

In the end, the maximum score (the minimum value) of all the paths is 3.

Try it yourself

Implementation

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro
Favorite (idle)