Problem Statement
You are given a
Definition
- Class:
- BiggestDuplicate
- Method:
- findLargest
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int findLargest(int[] x)
- (be sure your method is public)
Constraints
- x will contain between 2 and 50 elements, inclusive.
- Each element of x will be between 0 and 1000, inclusive.
Examples
{ 0, 1, 20, 18, 20, 18, 3 }
Returns: 20
The values 18 and 20 are both duplicated, and 20 is the largest of these.
{ 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.
{ 1, 2, 3, 4, 5 }
Returns: -1
There are no duplicates here.
{ 5, 8, 5, 2 }
Returns: 5
Notice that 5, while not the largest element, is the only one that is duplicated.
{ 3, 7, 4, 3, 2, 4, 7, 4, 6, 4, 7, 8, 2, 3, 5 }
Returns: 7
{715,938,703,223,929,664,662,773,851,948,562,226,333,963,307,198,276,67,479,275,685,491,62,703,223,594,620,742,490,464,878,191,925,588,506,402,87,821,905,135,573,505,913,465,751,257,536,638,413,789}
Returns: 703
{152,96,699,954,224,875,1000,1000,334,43,921,282,387,70,370,301,745,457,906,110,456,163,344,703,179,578,598,952,967,58,982,329,702,870,725,95,225,634,282,528,88,821,570,91,653,222,526,395,381,957}
Returns: 1000
{181,507,678,139,989,752,997,774,646,276,48,32,275,62,592,581,517,345,275,75,110,175,378,22,635,593,253,49,958,51,203,571,10,267,801,822,24,730,737,343,229,861,636,251,39,788,294,29,61,642}
Returns: 275
{49,106,881,681,5,129,655,505,396,499,947,817,594,73,478,22,7,261,770,556,788,609,932,846,250,540,127,984,847,298,224,989,316,43,153,465,129,587,796,692,369,225,341,845,282,43,41,177,561,766}
Returns: 129
{768,291,85,221,441,174,34,430,466,2,671,658,97,275,959,501,551,921,13,893,420,466,77,186,562,268,86,564,206,498,950,422,81,12,456,698,230,822,712,290,95,157,329,690,699,567,243,570,324,543}
Returns: 466
{479,326,91,945,343,306,919,720,309,603,363,107,84,623,35,968,189,769,488,934,576,385,520,916,859,604,816,217,317,984,326,369,988,93,462,390,624,206,539,849,45,734,410,369,993,23,868,864,205,680}
Returns: 369
{44,864,566,202,939,94,807,176,86,740,491,702,402,326,276,994,120,991,160,646,344,984,229,639,888,842,975,150,924,835,736,953,11,637,940,463,804,786,155,368,584,447,120,800,358,344,332,84,92,999}
Returns: 344
{904,878,703,560,336,60,634,927,314,96,119,656,252,251,3,538,690,766,386,814,189,334,836,793,61,897,864,430,281,544,510,890,58,925,932,859,249,452,300,879,829,878,471,58,248,928,194,869,796,820}
Returns: 878
{655,567,698,278,810,569,41,911,498,440,197,204,645,771,587,229,598,328,319,145,288,237,465,508,985,312,864,778,544,133,702,995,634,461,889,944,192,780,115,363,817,339,954,861,681,624,232,700,471,19}
Returns: -1
{330,867,550,651,531,417,101,190,294,497,705,264,366,365,739,203,571,183,882,643,37,818,212,957,328,949,284,604,828,360,79,164,306,525,803,835,445,984,931,472,842,1,486,618,659,553,974,588,122,478}
Returns: -1
{53,48,818,828,982,513,654,594,323,582,132,498,363,934,418,541,959,842,562,904,758,587,253,410,802,35,332,595,297,775,976,696,482,349,306,30,346,478,543,290,181,852,661,348,339,344,639,552,200,118}
Returns: -1
{594,131,26,219,720,467,796,407,26,946,180,59,296,548,607,437,15,13,627,387,194,481,299,272,722,907,927,906,71,458,396,781,394,179,181,845,670,263,630,840,235,939,451,597,109,121,555,112,742,902}
Returns: 26
{328,626,925,813,924,113,833,754,497,813,540,890,336,569,549,400,665,116,367,762,768,753,384,787,152,255,29,702,162,600,351,814,164,169,129,771,856,581,256,67,11,916,766,817,299,345,603,883,47,710}
Returns: 813
{457,439,746,980,134,575,242,137,661,669,83,131,592,897,462,727,726,166,439,779,545,84,861,299,750,852,987,568,488,807,653,147,654,452,143,913,67,184,34,555,529,718,921,588,985,881,323,870,354,573}
Returns: 439
{619,436,444,269,165,372,579,447,229,283,588,674,650,854,15,937,477,139,753,550,659,542,132,885,250,828,164,273,314,870,528,117,213,915,188,216,704,385,287,772,334,620,955,752,967,855,67,66,572,48}
Returns: -1
{1, 1, 2, 3, 3 }
Returns: 3
{999, 999 }
Returns: 999
{5, 8, 5, 2 }
Returns: 5