Question: Write the Java method biggestGap, which takes as its parameter an array of integers called myArray. If there are no repeated values in myArray, as

Write the Java method biggestGap, which takes as its parameter an array of integers called myArray. If there are no repeated values in myArray, as is the case with array ar11 below, the method returns the value -1. If the only repeated values in myArray are in adjacent cells, as is the case with array ar22 below, the method returns the value 0. Otherwise, the method returns the largest number of cells between any repeated values of myArray. For example, array ar33 below has many repeated values, so the method would return the value 4, which is the size of the biggest gap between repeated values.

0 1 2 3 4 5 6 7 8
ar11 10 9 18 62 21 0 33 2 55

return value: -1

0 1 2 3 4 5 6 7 8
ar22 8 13 13 9 0 22 22 3 19

return value: 0

0 1 2 3 4 5 6 7 8
ar33 23 77 51 0 0 77 99 51 99

return value: 4

--------------------------------------------------------------------------------------------

public static int biggestGap(int [] myArray) {

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!