Google | Phone Interview | Smallest of maximums for all paths in matrix
Anonymous User
1887

I was given this problem for a Google new grad phone screen a while back. I was able to provide a brute force solution that was definitely not the best way to solve the question.


You are given a 2D integer matrix as input. You always start in the top left corner and have to make your way to the bottom right index by only moving right or downwards. For each possible path to the bottom right corner, there is a maximum integer in the path. Find the minimum of all possible maximum integers for all the paths from the top left to the bottom right.

For example:
You are given the following matrix [ [1, 7] [5, 3] ]

The possible paths are (1, 5, 3) and (1, 7, 3). Subsequently, the maximum of the paths are (5, 7). Finally, the minimum of all the maximums is 5.


I was wondering what the optimal way to solve this problem is (Python especially) either using recursion, DP, or a logical solution. Also, what would the space/time complexity be?

Comments (7)