The question is to find the index of first element in the array that repeats itself atleast once in the array.
Input:
7
1 3 4 5 3 7 2
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
cin >> n;
int a[n], curr = -1;
int num = sizeof(a) / sizeof(a[0]);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
{
int x = a[i];
a[i] = -1;
if (binary_search(a, a + num, x))
{
curr = i;
cout << curr << endl;
break;
}
}
cout << curr + 1;
return 0;
}
Expected Output: 2 (As 3 is the first element to appear twice in the array)
Output received: 0