You are viewing a single comment's thread. Return to all comments →
If the sums of hourglasses are all negative , and if u have taken your max variable initilized to zero and calculate the max with refrence to 0 obviously you will be returning 0 as the answer which is wrong . So its better to initilize with Integer.MIN_VALUE to a variable to which will be storing a max value .
thanks mate... helped a lot!!!
Or initialize it to any value less than -63, because the input values of the array ranges from -9 to +9. So a hour glass can contain a maximum of 7 times -9, which sums up to -63. Any value greater than -64 can be accepted to swap the max variable, right!
Try this man!
Actually, -63 will work too.
Taking max value as integer.MIN_VALUE is also correct however max can also be sumArray (the array of sum of hourglasses) .
Thanks ! That helped.