Odd Occurring in List

Description:

Given an array of positive integers. All numbers occur even number of times except one number which occurs odd number of times. Find the number in O(n) time & constant space. Example: I/P = [1, 2, 3, 2, 3, 1, 3] O/P = 3 Test Case 1 Input (stdin) 13 2 3 5 4 5 2 4 3 5 2 4 4 2 Expected Output 5 Test Case 2 Input (stdin) 7 1 2 3 2 3 1 3 Expected Output 3

Program :

#include <stdio.h>

#include <iostream>

#include <unordered_map>

using namespace std;

int main(){

     

    int n;

    cin>>n;

    int arr[n];

    std::unordered_map<int,int> m;

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

          cin>>arr[i];

          m[arr[i]]++;

    }

    for(auto it=m.begin();it!=m.end();it++){

         if(m[it->first]%2!=0){

          cout<<it->first;

          break;

         }

    }

    cout<<"\n";

    return 0;

 

}