#include <stdio.h> int find_duplicate(int arr[], int n) { int i, j; for(i = 0; i < n; i++){ // Key = arr[i] for(j = 1; j < (n - 1); j++){ if(arr[i] == arr[(i + j) % n]){ return arr[i]; } } } return -1; } int main() { int n; scanf("%d", &n); int arr[100]; for (int i = 0; i < n; i++) scanf("%d", &arr[i]); int result = find_duplicate(arr, n); printf("%d", result); return 0; }
Test Cases
Test Results
Input
5 0 1 2 3 2
Expected Output
2