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.
Okay ... No problem. You can still do it with initialisation if you don't want an additional if block to make the code simpler. Initialise min to INFINITY, where INFINITY is a macro constant equal to 1e7 + 1, in our case and max is -1. This automatically ensures max and min become the first element of the array.
The only additional care needed with my approach is that minimum changes and maximum changes are initialised to -1, so that the first element is not counted. Here's my code.
Breaking the Records
You are viewing a single comment's thread. Return to all comments →
Okay ... No problem. You can still do it with initialisation if you don't want an additional if block to make the code simpler. Initialise min to INFINITY, where INFINITY is a macro constant equal to 1e7 + 1, in our case and max is -1. This automatically ensures max and min become the first element of the array.
The only additional care needed with my approach is that minimum changes and maximum changes are initialised to -1, so that the first element is not counted. Here's my code.