+ 10
{Answered}Matrix Question from HackerRank..
Input :- 6*6 matrix Output :-Print the maximum sum of all elements of hourglass. What is an hourglass? Matrix :- a b c d e f g h i j k l m n o p q r s t y v w x Then one hourglass is :- a b c h m n o In 6*6 matrix , 16 hourglasses are possible, We need to print the sum of all the elements of that hourglass, in which the sum of all elements is maximum. Source and more Info :- https://www.hackerrank.com/challenges/30-2d-arrays. SOLUTION :- https://code.sololearn.com/cP9Cgq50uJPk/?re
6 odpowiedzi
+ 8
x =-1;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
S[++x] =M[i] [j] +M[i] [1 +j] +M[i] [j+2] +M[i+1] [j+1] +M[i+2] [j] +M[i+2] [j] +M[i+2] [j] ;
}
}
Then find maximum of "S" array to find maximum of hourglass.
+ 10
yes it did..
+ 9
Thanks, trying to figure things out..
+ 8
maybe...I did this:-
Heres the solution, for the ones still wondering....
https://code.sololearn.com/cP9Cgq50uJPk/#java
+ 5
Did this Solution worked on hackerrank?
+ 5
So do you get the result as expected by hackerrank test cases. Did your code passed on that test case.