Third Maximum Number Problem

Third Maximum Number Problem — ExecCode School DSA Practice

Solve the Third Maximum Number problem on ExecCode. Free online school DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given a list of integers, find and print the third maximum distinct number. Your task is to solve Third Maximum Number. If there are fewer than three distinct numbers, print the maximum number instead.

Examples

Input 3 3 2 1; Output 1. Input 2 1 2; Output 2

Constraints

1 <= n <= 10^5

Practice Third Maximum Number free on ExecCode. Browse DSA problems, topic map, and placement guides.