BackmediumArrays Razorpay

Duplicate Element Index Solution

Problem Statement

You are given an array of integers `elements` containing at least one duplicate. Find the index of the first occurrence of a duplicate element in the array.

Example 1
Input
{"elements":[2,1,3,5,3,2]}
Output
3

Explanation: the first occurrence of duplicate 3 is at index 3

Example 2
Input
{"elements":[4,5,7,5,9]}
Output
1

Explanation: the first occurrence of duplicate 5 is at index 1

Example 3
Input
{"elements":[1,2,3,4,5,6,7,8,9,1]}
Output
0

Explanation: the first occurrence of duplicate 1 is at index 0

Constraints

  • The input array will not be empty.
  • Each page object will have a unique id and some data.
  • The array length will not exceed 10000.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free