Second Largest Value — Solution & Editorial
Keep the two largest distinct values while scanning, or deduplicate and sort. Handle the all-equal case explicitly.
Complexity: O(N log N) or O(N)
Watch out: Duplicates of the maximum do not count as the second largest — the values must be distinct.