Google phone screen - minimize variance in row-sorted matrix

Given a n x m matrix, mat where each row is sorted in ascending order, produce a n x 1 vector, v where v[i] corresponds to some element in mat[i] such that the variance of v is minimized. The elements of mat are unique.

The only solution I could come up with is a brute force dfs (time complexity O(n * n^n), but that doesn't take advantage of each row being sorted nor the matrix having unique elements. Any clue how to solve this problem?

Comments (5)