problem no 67: find the element in array which occurs odd number of times.

question:

Given an array of N positive integers where all numbers occur even number of times except one number which occurs odd number of times. Find the exceptional number.

Example 1:

Input:
N = 7
Arr[] = {1, 2, 3, 2, 3, 1, 3}
Output: 3

Example 2:

Input:
N = 7
Arr[] = {5, 7, 2, 7, 5, 2, 5}
Output: 5

Your Task:

You don't need to read input or print anything. Your task is to complete the function getOddOccurrence() which takes arr[] and as input parameters and returns the exceptional number.



code:


 int getOddOccurrence(int arr[], int n) {

        // code here

        map<int,int> mapp;

        for(int i=0;i<n;i++)

        {

            mapp[arr[i]]++;

        }

        

        for(auto ele:mapp)

        {

            if(ele.second%2!=0)

            {

                return ele.first;

            }

        }

        

        

    } 

Comments

Popular posts from this blog

problem 3: given two integers N and M. The problem is to find the number closest to N and divisible by M. If there are more than one such number, then output the one having maximum absolute value.

problem no 7:Given two numbers A and B, find Kth digit from right of AB.

Problem no 16: count the number of squares below N.