You are viewing a single comment's thread. Return to all comments →
Why not just use max = -63? If the whole array is -9 then max will never change and output correct answer of -63
max = -63
You're right, that's the best initial value.
In this case I'd say using Integer.MIN_VALUE would be a better choice. This will make it easier to convert your algorithm to one that can be used on any size array and with different integer bounds
It's not that important here, but by initialising to a lower value than any hourglass could have (for example -64), you'll be able to identify more easily whether a bug is causing the max value to never update (max remains at -64) or if max is updating but not to the correct value.
that's a good idea! whenever you can decrease the number of possible causes of a problem, that's a good thing!