Say you are given an array which has all duplicate members except one, which out this non-duplicate member.
Function to find index of non-duplicate member:
int findNonDuplicate(int A[],int n) { int i; if(A[0]!=A[1] && A[1]==A[2]) return 0; else { for(i=0;i<n-1;i++) if(A[i]!=A[i+1]) return (i+1); } }
Say you are given two arrays where second array is duplicate with one missing element. What should be the best possible way to find that missing element - array1: [1,2,3,4,5,6,7] array2: [1,3,4,5,6,7]
Missing Element: 2