top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Find a non-duplicate member of an array using C?

+2 votes
77 views

Say you are given an array which has all duplicate members except one, which out this non-duplicate member.

posted Mar 31, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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);
     }
   }
answer Apr 3, 2016 by Shahsikant Dwivedi
But for this first we need to sort the array
sir,let me know if i understood you in a wrong way, i took example of 122222 and 221222 in both cases  2 is duplicate and 1 is not. First integer array satisfies first 'if' condition therefore it will return 0, while second array of integer returns 2. first if condition in my program is for special case in which non-duplicate number appears at 0'th index for rest else condition follows.
say if array is in the form of 1, 3, 4, 6, 8, 1, 3, 4, 6. Then answer would be 8 which is only non-duplicate member. Looks the function will not work on this.
i understood the question wrong thanks sir, i will correct my code asap.
Similar Questions
–1 vote

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

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...