How are duplicate minimums handled?
Exactly the same way. The second condition must explicitly include (current != min) to ensure duplicates of the absolute minimum are ignored.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Finding the Second Smallest Element
The structural logic is identical. The only differences are initializing variables to very large numbers instead of very small ones, and checking for < instead of >.
If you initialize 'min' to 0 and the array contains only positive numbers, the condition (current < min) will never trigger, and 0 will incorrectly be returned.
In Java, use Integer.MAX_VALUE. In C++, use INT_MAX from the <climits> library. In Python, use float('inf').
Still have questions?
Browse all our FAQs or reach out to our support team
