The Potion Shelf

View as PDF

Submit solution

Points: 6
Time limit: 2.0s
Memory limit: 64M

Authors:
Problem type

The Potion Shelf

Mira the Witch keeps potions on a shelf, each with a power level. She needs the second most powerful potion (second largest DISTINCT value) as a backup. If no second distinct value exists, output NO BACKUP.

Your Task

Given N integers (potion power levels), find the second largest distinct value. If none exists, output NO BACKUP.

Input Specification

The first line contains T — the number of shelves. Each shelf starts with N on its own line, followed by N space-separated integers.

Output Specification

For each shelf print the second largest distinct value, or NO BACKUP.

Sample Input
2
5
5 3 9 7 9
3
4 4 4
Sample Output
7
NO BACKUP
Constraints

1 \le T \le 100\,000
2 \le N \le 10\,000
1 \le each value \le 100\,0000

Test cases available here!


Comments

There are no comments at the moment.