Question: Duplicate in an Array Description You are given an array of 'n' integers. The integers in the array are between 1 and n-1. You have

Duplicate in an Array

Description

You are given an array of 'n' integers. The integers in the array are between 1 and n-1. You have to find the duplicate.

You need to do it in O(n) time, but you can use extra space.

Input Format:

The input contains the number of elements in the array, followed by the elements in the array.

Output Format:

The output returns the duplicate integer or returns -1 if there is no duplicate.

Sample Test Cases:

Input:

5 1 4 3 2 3

Output:

3

Input:

4 1 3 2 1

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!