Min-Max Matrix P45836


Statement
 

pdf   zip

Given a square matrix MM of n×nn\times n (with n1n\geq 1) of integers, its matrix minMax is the matrix mMmM of n×2n\times 2 such that for all ii (with 0i<n0\leq i<n), mM[i][0]mM[i][0] is the minimum element of the ii-th row of MM and mM[i][1]mM[i][1] is the maximum element of the ii-th column of MM.

For instance, if M=[[1,2,3],[3,1,2],[2,3,1]]M = [[1,2,3], [3,1,2], [2,3,1]], mM=[[1,3],[1,3],[1,3]]mM = [[1,3], [1,3], [1,3]]

Implement the @min_Max(M)@ function that given the square matrix MM returns its minMax matrix.

You can use the @min()@ and @max()@ functions of Python, that given a list, they return their minimum and maximum element respectively.

Sample session

Sample session
>>> min_Max([[1,2,3],[3,1,2],[2,3,1]])
[[1, 3], [1, 3], [1, 3]]
>>> min_Max([[100]])
[[100, 100]]
>>> min_Max([[2,2],[2,2]])
[[2, 2], [2, 2]]
>>> min_Max([[17, 4],[1,1]])
[[4, 17], [1, 4]]
>>> min_Max([[5, 1, 2, 1, -2],[1,21,-1,-2,8],[2,3,1,6,6],[1,2,3,4,5]])
[[-2, 5], [-2, 21], [1, 3], [1, 6]]
Information
Author
Professors Informàtica EEBE
Language
English
Other languages
Catalan Spanish
Official solutions
Python
User solutions
Python