+ 3

How to write a java program for finding square submatrix with highest sum value from matrix of variable dimension?

Consider a 2D matrix of numbers from 0 to 9 with variable width and height. Find the square submatrix with the highest sum of boundary elements.

3rd Sep 2018, 7:46 PM
Mubasshira Khan
Mubasshira Khan - avatar
17 ответов
0
I did it in university, does the square have pre-defined size or can it be in any size
4th Sep 2018, 8:47 AM
Eldar Bakerman
0
not defined value is given for square submatrix .bt here we can take of size 3×3.
4th Sep 2018, 8:56 AM
Mubasshira Khan
Mubasshira Khan - avatar
0
Okay, so what you want is 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 And find the square with the biggest sum of boundaries?
4th Sep 2018, 9:00 AM
Eldar Bakerman
0
Which is 13 14 15 18 19 20 23 24 25
4th Sep 2018, 9:00 AM
Eldar Bakerman
0
yes..this is the right output.bt how to write java code for this.im not getting the logic for this.
4th Sep 2018, 9:05 AM
Mubasshira Khan
Mubasshira Khan - avatar
0
Right, so basically the center of the square doesn't matter, only the boundaries?
4th Sep 2018, 9:07 AM
Eldar Bakerman
0
yeah..bt sum value of matrix must be high as compare to other submatrix.
4th Sep 2018, 9:08 AM
Mubasshira Khan
Mubasshira Khan - avatar
0
I gave it as an example, obviously it's not sorted
4th Sep 2018, 9:15 AM
Eldar Bakerman
0
Mubasshira Khan but are all the numbers in the matrix are to sum or only the boundaries?
4th Sep 2018, 9:16 AM
Eldar Bakerman
0
not necessary that all the elements in matrix need to be sorted...and have to find sum of all values including center value of a square submatrix.
4th Sep 2018, 9:23 AM
Mubasshira Khan
Mubasshira Khan - avatar
0
Okay, I'll answer when I'll get to a computer because it's impossible through phone
4th Sep 2018, 9:33 AM
Eldar Bakerman
0
He said 2D
4th Sep 2018, 9:36 AM
Eldar Bakerman
0
Also multiple dimensions can be 10D as well, it's two-dimensional array, not multiple.
4th Sep 2018, 9:37 AM
Eldar Bakerman
0
No one calls it multidimensional sir, that's why.
4th Sep 2018, 9:46 AM
Eldar Bakerman
0
its a 2D array..nd we have to derive a square submatrix from this 2D matrix.
4th Sep 2018, 9:57 AM
Mubasshira Khan
Mubasshira Khan - avatar
0
Eldar Bakerman sir can you share a code for this problem if you have solved?
4th Sep 2018, 7:06 PM
Mubasshira Khan
Mubasshira Khan - avatar
0
I did not have time. Anyway what you need to do is 2 for loops and a check of how can you form a square.
6th Sep 2018, 3:32 AM
Eldar Bakerman