Professional Documents
Culture Documents
Print All Matrix Whose Sum Is Highest
Print All Matrix Whose Sum Is Highest
1. String rotation
Example :-
Input:- rhdt:246,ghftd:1246
Output: trhd,ftdgh
For second case : 1*1+2*2+4*4+6*6=85 which is odd so rotate string left by 2 so “ghftd” will be “ftdgh”
In case, two or more square matrix has maximum sum then print largest matrix followed by next largest
matrix and so on.
In case, more than one matrix has same size print in order of their occurance.
INPUT:
6,3,6,20,3,6,-15,3,3
OUTPUT:
636
20 3 6
-15 3 3
63
6 20
6 20
36
Explanation:-
636
20 3 6 -> It’s sum is 35 and is order 3*3,
-15 3 3
63
6 20 -> It’s sum is 35 and is order 2*2,
6 20
36 -> It’s sum is 35 and is order 2*2,
Now , 3*3 is printed first because it’s has the highest order ,and the 2*2 order matrix must be printed
in sequence ,which comes first in the given input (must) and there should be no extra space printed
anywhere