/176. Second Highest Distinct Value in List

176. Second Highest Distinct Value in List

Medium
Databases & SQL46.5% acceptance

Given a list of integer values, return the second highest distinct value. If there is no second highest distinct value, return None.

Example 1

Input: [10, 20, 30, 40]

Output: 30

Explanation: Distinct values are [10, 20, 30, 40]. Second highest is 30.

Example 2

Input: [5, 5, 5]

Output: None

Explanation: Only one distinct value exists.

Example 3

Input: [-1, 0, 1, 1]

Output: 0

Explanation: Distinct values are [-1, 0, 1]. Second highest is 0.

Constraints

  • 1 <= len(values) <= 10^5
  • -10^9 <= values[i] <= 10^9
Python (current runtime)

Case 1

Input: [100, 200, 300, 400, 500]

Expected: 400

Case 2

Input: [7, 7, 7, 7, 7]

Expected: None

Case 3

Input: [2, 1, 2, 3, 4, 4]

Expected: 3

Case 4

Input: [-10, -20, -30, -40]

Expected: -20

Case 5

Input: [0, 0, 1]

Expected: 0