Question: 5. Multi Dimensional Selection Given a 2-d array arr of size nm, a selection is defined as an array of integers such that it contains


5. Multi Dimensional Selection Given a 2-d array arr of size nm, a selection is defined as an array of integers such that it contains at least m/27 integers from each row of arr. The cost of the selection is defined as the maximum difference between any two integers of the selection. Suppose k is the minimum cost of all the possible selections for the given 2-d array. Find the maximum value of the product of k the number of integers considered in the selection with the minimum cost. Example Suppose n=3,m=2, and arr =[[1,2],[3,4],[8,9]] Some of the possible selections are [2,3,8],[1;2,3,9], [1,3,4,8,9] etc. The cost of these selections are 82= 6,91=8, and 8 respectively. Here the minimum cost of all the possible selections is 6. The possible selections with the cost 6 are [2,4,8] and [2,3,4,8]. The maximum value of the required product is obtained using the latter selection i.e. 64 =24. Hence the answer is 24 . Function Description Complete the function getMaxProduct in the editor below. Function Description Complete the function getMaxProduct in the editor below. getMaxProduct has the following parameter: int arr[n][m]: the given 2-d array Returns int: the maximum possible product Constraints - 1n103 - 2m103 - 1arr[i][j]109 - Input Format For Custom Testing The first line contains an integer, n, which denotes the number of rows in arr. The second line contains an integer, m, which denotes the number of columns in arr. Each line i of the n subsequent lines (where 0i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
