Find Duplicate in Range 0 and n-1

Code

        #include <stdio.h>

        int repeated_arr(int *a, int n){
            for(int i = 0; i < n - 1; i++){
                for(int j = i + 1; j < n; j++){
                    if(a[i] == a[j]){
                        return a[i]; 
                    }
                }
            }
        }

        int main(){
            int n, arr[100]; 
            scanf("%d",&n);
            for(int i = 0; i<n; i++){
                scanf("%d",&arr[i]); 
            }

            printf("%d", repeated_arr(arr,n));
            return 0;
        } 

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

5 0 1 2 3 2

Expected Output

2