Question: code in Java take stdin as input Given a list of integers, return the starting index of the first pair that occurs. If there are

code in Java

take stdin as input

Given a list of integers, return the starting index of the first pair that occurs. If there are no pairs in the list, return -1. A pair consists of two consecutive integers having the same value. Three or more values in a row do NOT make or contain a pair.

Input Format

Input is two lines of data. First line is n, the number of elements in the integer list. Second line is the list of numbers.

Constraints

first line - n - will be between 2 and 1000000 the values will be any valid java integer values.

Output Format

output a single integer value - the index of the first element of the pair of value. if no pair exists, then output -1

Sample Input 0

14 1 2 2 2 3 3 4 5 5 5 4 4 4 1 

Sample Output 0

4 

Explanation 0

There is a single pair of numbers 3 and 3 located at indices 4 and 5 in the list. The starting index is 4 so that is displayed.

Sample Input 1

5 3 3 3 3 3 

Sample Output 1

-1 

Explanation 1

Five numbers in a row don't qualify as a pair, so we output -1

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!