Connection Status:
Competition Arena > BiggestDuplicate
Rookie SRM 6 · 2021-07-14 · by erinn · Sorting
Class Name: BiggestDuplicate
Return Type: int
Method Name: findLargest
Arg Types: (vector<int>)
Problem Statement

Problem Statement

You are given a int[] containing a list of non-negative integers. Find and return the largest one that is duplicated in the list. If there are no duplicates, return -1.

Constraints

  • x will contain between 2 and 50 elements, inclusive.
  • Each element of x will be between 0 and 1000, inclusive.
Examples
0)
{ 0, 1, 20, 18, 20, 18, 3 }
Returns: 20

The values 18 and 20 are both duplicated, and 20 is the largest of these.

1)
{ 15, 12, 3, 15, 7, 12, 15, 7, 12 }
Returns: 15

Notice that 15 and 12 each appear many times. Anything appearing more than once is a duplicate.

2)
{ 1, 2, 3, 4, 5 }
Returns: -1

There are no duplicates here.

3)
{ 5, 8, 5, 2 }
Returns: 5

Notice that 5, while not the largest element, is the only one that is duplicated.

4)
{ 3, 7, 4, 3, 2, 4, 7, 4, 6, 4, 7, 8, 2, 3, 5 }
Returns: 7

Submissions are judged against all 23 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class BiggestDuplicate with a public method int findLargest(vector<int> x) · 23 test cases · 2 s / 256 MB per case

Submitting as anonymous