Like max, second_max should also be initialized to the lowest possible extreme, such as negative infinity or MIN_VALUE.
Understanding Variable Initialization (MIN_VALUE)
What should second_max be initialized to?
The answer
More FAQs in Understanding Variable Initialization (MIN_VALUE)
If the dataset contains only negative numbers, 0 will incorrectly be returned as the maximum, even though it doesn't exist in the data.
It is a constant representing the smallest possible value a 32-bit integer can hold (-2,147,483,648). It is the perfect starting point for finding maximums.
In Python, you should use float('-inf') to represent negative infinity, and float('inf') to represent positive infinity.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.