insidcode
ProblemsDuelLeaderboardStats
Sign In
  1. Home
  2. Problems
  3. Find the second largest element in an array.

Find the second largest element in an array.

Difficulty: Medium

Phase: 4 · Basic Arrays

XP Reward: 20 XP

Topics: Basic Arrays, Medium

Supported Languages: Python, JavaScript, C, C++, Java

Problem Description

Given N (>= 2) followed by N integers, find the second largest distinct element. If no second largest exists, print -1. Input Format: Read input from standard input (stdin). Output Format: Print the result to standard output (stdout).

Constraints

  • -10^9 <= N <= 10^9

Examples

Example 1

Input: 5 10 20 4 45 99

Output: 45

Explanation: Sample execution for input 5 10 20 4 45 99