Previous Next
0 / 21
Module DEMO-32-106DEMO-C-32

Second Largest Element

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a C program to find the second largest distinct element in an array. If the array size is less than 2 or does not have at least two distinct elements, print "N/A".

Example 1

Input:

5 10 20 5 30 15

Output:

20

Example 2

Input:

3 10 10 10

Output:

N/A

Constraints

1 <= n <= 100

Input Format

n, array logic

Output Format

Second largest or N/A

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
5
10 20 5 30 15
20
Max is 30, second is 20.
Sample #2
Public sample
3
10 10 10
N/A
No distinct second largest.
Sample #3
Public sample
5
10 20 10 20 5
10
Distinct values 5, 10, 20. Max 20, 2nd 10.
Sample #4
Public sample
4
-10 -20 -5 -2
-5
Max -2, 2nd -5.
Sample #5
Public sample
2
5 1
1
Just two elements.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings