We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

Very large negative values are not necessary. See that an hourglass is made up of 7 digits. the sum of 'those' 7 digits can be minimum when each digit is itself minimum, i.e, -9. Hence, the minimum sum will be (7)x(-9), which equals -63. So, we can initialize minimum as -64

## 2D Array - DS

You are viewing a single comment's thread. Return to all comments →

Guys we also have one more alternative, with the help of flag we can achieve it,

if (flag) {

max = sum;

flag = false;

}

if (max < sum) {

max = sum;

}

will it not give a compilation error i.e max is not initialized or something like that?

or in JS:

let max;

if (typeof max !== 'number' || sum > max) { max = sum }

I used, max = -Infinity

Very large negative values are not necessary. See that an hourglass is made up of 7 digits. the sum of 'those' 7 digits can be minimum when each digit is itself minimum, i.e, -9. Hence, the minimum sum will be (7)x(-9), which equals -63. So, we can initialize minimum as -64

you could actually initialize it with -63 ,would still work.