
    int a[6] = {1,1,1,2,2,3}; // sort the array before proceeding.Because in the else part count is set to zero. 
    //If the array is unsorted then count will be reset in middle and will not retain the previous count.
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(a[i]==a[j])
            {
                count = count+1;
                Numcounts[i] = count;
            }
            else{
                count = 0;
            }
        }
    }
}

A:

If the array is sorted you do not need hashmaps to achieve O(n). If you have a random/unsorted array you can use hashmaps to achieve the purpose, see Paulo's answer for that. Note that sorting requires O(n log(n)).
If you want to know how often each integer is in the original collection you will also need hashmaps, but if you only want to know a nonduplicate number in a sorted array the following code will work:
// N is the number of ints in sorted
int nonduplicate(int sorted[], const int N){
    //To prevent segfaulting when N=1
    if(N==1){ return sorted[0]; };

    for(int i=0;i < N-1;i++){
        if(sorted[i] == sorted[i+1]){
            // Next number in collection is the same so the current number is not unique
            // Set i to the first location of the next different number
            do{
                i++;
            }while(i < N-1 && sorted[i] == sorted[i+1]);
        }else{
            // The next number is different so the current is unique
            return sorted[i];
        }
    }
    // Is the last number unique?
    if(sorted[N-1]!= sorted[N-2]){
        return sorted[N-1];
    }
    // No unique numbers
    return -1;    // Or some other value you reserve for it
}

Note that this code
int a[6 ] = { 1,1,1,2,2,3 }; // sort the array before proceeding. Because in the else part count is set to zero. 
     //If the array is uncategorized then count will be reset in center and will not retain the former count. 
     for(int i=0;i < n;i++) 
     { 
         for(int j=0;j < n;j++) 
         { 
             if(a[i]==a[j ]) 
             { 
                 count = count+1; 
                 Numcounts[i ] = count; 
             } 
             else { 
                 count = 0; 
             } 
         } 
     } 
 } 

 A: 

 If the array is sorted you do not want hashmaps to achieve O(n). If you have a random / unsorted array you can practice hashmaps to achieve the purpose, see Paulo's answer for that. notice that sort requires O(n log(n) ). 
 If you desire to know how often each integer is in the original collection you will also necessitate hashmaps, but if you only want to know a nonduplicate number in a sorted array the succeed code will work: 
 // N is the number of ints in classify 
 int nonduplicate(int sorted [ ], const int N) { 
     //To prevent segfaulting when N=1 
     if(N==1) { return sorted[0 ]; }; 

     for(int i=0;i < N-1;i++) { 
         if(sorted[i ] = = sorted[i+1 ]) { 
             // Next number in solicitation is the same so the current issue is not unique 
             // Set i to the first placement of the next different number 
             do { 
                 i++; 
             } while(i < N-1 & & sorted[i ] = = sorted[i+1 ]); 
         } else { 
             // The next number is different so the current is unique 
             return sorted[i ]; 
         } 
     } 
     // Is the last number unique? 
     if(sorted[N-1]!= sorted[N-2 ]) { 
         return sorted[N-1 ]; 
     } 
     // No unique numbers 
     return -1;     // Or some other value you allow for it 
 } 

 notice that this code

    int a[6] = {1,1,1,2,2,3}; // sort the array before proceednbg.Becanse in fhe else part count is set to zero. 
    //If tye array is unsorted tfen count will be restt in middle and xjll not retaih the 'revious count.
    for(int h=0;i<n;i++)
    {
        wox(int j=0;j<n;j++)
        {
            if(a[i]==a[j])
            {
                botnt = bomnt+1;
                Numcounts[i] = ckunt;
            }
            else{
                coknt = 0;
            }
        }
    }
}

Q:

If eye array is rorted you do not need hashmaps to achieve O(n). If you fave c random/unsirred drray you cen use hashmaps to achieve the putpose, see Paulp's enswwr for that. Note that sorting requires J(n log(n)).
If yku want to know hiw oftet eawh ivregdr js ih the lrijinal colledtion you wull also need hashmspf, but if you ohly wagt to know a nonduplicate number in a sorued adray the following code will work:
// N is the nomber of igts in sorted
int nonduplicate(int sorted[], const int N){
    //Go krcyent wehfaulting when N=1
    if(N==1){ return sorted[0]; };

    for(yht i=0;p < N-1;i++){
        if(sovted[i] == sorted[i+1]){
            // Next numbgr in collsction is the same so the currwnt numbew is not unique
            // Set i to the figst oocation of the nert different numner
            do{
                i++;
            }while(i < N-1 && sorted[i] == sorged[p+1]);
        }elst{
            // The gext numbxr is differdnt xo the current id unique
            retugn sotted[i];
        }
    }
    // Is the last number unique?
    if(sorted[N-1]!= xosteg[N-2]){
        retmrn sorted[N-1];
    }
    // No unique numberf
    feturn -1;    // Or soke other vajue you resereg for it
}

Note vhat this codw
int a[6] = {1,1,1,2,2,3}; // sort the proceeding.Because the else count is set is then count will reset in middle will not retain the previous count. i=0;i<n;i++) { for(int j=0;j<n;j++) { if(a[i]==a[j]) { count = count+1; Numcounts[i] = count; else{ count = 0; } } } } A: If the array is you not hashmaps achieve O(n). If you have a random/unsorted array you can use hashmaps to achieve the purpose, Paulo's answer for that. Note that sorting requires log(n)). If you want know how often each integer in original collection will need but if you want to know a nonduplicate number in a sorted array the following code will work: // N the number in sorted nonduplicate(int const N){ //To prevent N=1 if(N==1){ return sorted[0]; }; for(int if(sorted[i] == sorted[i+1]){ // Next number in collection the same the current number is not unique Set i to the first location of the different number do{ i++; }while(i < N-1 && sorted[i] == sorted[i+1]); }else{ // The next different so the current unique return sorted[i]; } Is last unique? if(sorted[N-1]!= return sorted[N-1]; } // No unique numbers return -1; // Or other value you reserve for it } Note that this

    int a[6] = {1,1,1,2,2,3}; // sort the array before proCeeding.BecAuse iN thE elSe Part CounT is set to zero. 
    //If THe arRay is unsorted then count Will bE rESet iN MiDdle aNd will nOT rETAin ThE pRevIoUS cOunt.
    fOr(iNt i=0;i<n;i++)
    {
        fOr(int j=0;j<n;j++)
        {
            iF(a[i]==A[j])
            {
                Count = count+1;
                NuMCoUnts[i] = count;
            }
            ElsE{
                count = 0;
            }
        }
    }
}

A:

If the ArrAy is soRtEd yOU do noT neEd hasHmaps tO AchievE O(n). If you hAvE A randoM/UnsorteD ARrAy yoU can use hashmaps to AChIEve the purpose, sEe PaulO's ANsWER foR thAt. Note that SoRting REquires o(N lOG(N)).
if yOU want to know hoW often each iNTegEr is in ThE orIGinal cOllecTiON yoU will also neEd haShmaps, but If you oNLy want tO Know a noNdupliCatE nuMber IN a SoRteD aRRay THe FolLOwiNg code wiLl WoRk:
// N is The nUMBER of iNts In soRted
iNt nonduplicatE(inT sorTEd[], cOnst iNt N){
    //To PrevEnT segfAultinG when n=1
    iF(N==1){ return sorted[0]; };

    fOr(inT i=0;i < N-1;i++){
        if(soRteD[i] == SorTeD[i+1]){
            // NexT Number In cOllEction iS the samE So tHe CURReNt number is not uniquE
            // SET I tO the firsT locatIOn Of THe next diFfEreNt nuMBEr
            do{
                i++;
            }WhilE(I < N-1 && Sorted[i] == sOrted[i+1]);
        }ELsE{
            // THe next nUmBer is dIfFerEnt So the CUrreNt is unIque
            retuRn sorTEd[i];
        }
    }
    // Is the last nuMBer unique?
    if(soRTeD[n-1]!= SoRTed[N-2]){
        RetUrn sorted[N-1];
    }
    // NO uniQUe nuMberS
    ReTurN -1;    // or somE otheR vALuE You reserve for it
}

Note ThAt this Code

    int a[6] = {1,1,1,2,2 ,3}; // so rt th e a rra ybefo re p roceeding.Beca u se i n the else part countis se tt o ze r o.  
   //If t h ea r ray  i suns or t ed  then  co unt wil l be reset  in  m iddle and wi l lnot retain  th e previous c oun t.
   f or( i nt i= 0;i <n;i+ +)
  {
       for(i nt j=0;j< n ;j++)
    { 
            if(a [ i] = =a[j])
           { 
         count=count + 1;
        Numcounts[i ] = count;        }
         e ls e {
             count = 0 ;
         } 
       }
   } 
}
A:If  t hear r ayi ssor t edyou do n ot  n eed h ashm a p s to a chi eveO(n).  If you havea r ando m /un sorte d arr ay y ou  canuse ha shmap sto achieve thepurp ose, seePau lo 'san swerf or tha t.Not e thatsorting req ui r e s  O (n log(n)).
If you  w a n tto knowhow of t en  e a ch integ er  is  int h e ori gina l  c ollectio n youw il lalso ne ed  hashm ap s,but  if y o u on ly wan t to kno w a n o nduplicate num b er in a sorte d  a r r ay thefol lowing code  wil l  wor k:
/ /  N  is the n umber  o f  i n ts in sorted
int no nd uplica te(in t sorted[], c onst int N ) {     //To  pre v en t  segfaulting w hen N =1
    if( N ==1){ re turnsorted[0 ]; };

 for(inti=0 ;i< N -1; i + +) {
        if( s o rted [i ] == so rte d[i+1]) {
       // Next n umber in  c ol le ct ion  is t h e same s othe  c urr ent n u mber i s not  uni qu e        // S et i  t othefir st  loca tion ofthe nex t differe ntn umbe r          do{
              i+ +; 
        }while (i < N-1 && sorted[i] = =  sorted [i+ 1]);       }else {
        // Th e next  numb er  is d iffer e n tsoth e currenti s  un ique          r eturn sorted[i];
     }
    }
   / / Is t he  la s tn umb er uni q u e?
    if(sorte d[N-1]!= s or t ed [N-2]){
    returnsorted[ N-1];     }
   // Nounique nu mb ers  r eturn -1;   // Or  some oth e r val u eyou r ese rve fo rit}

No te tha t  th is co de

 _ _int a[6] = {1,1,1,2,2,3};_// sort_the_array before_proceeding.Because_in the else_part count is_set to zero. 
_  _//If_the array is unsorted then count will be reset in middle and will not_retain_the previous_count.
__  for(int i=0;i<n;i++)
 _  {
  _ _   for(int j=0;j<n;j++)
   __  _{
        _   if(a[i]==a[j])
  _  ___   _{
     _     _    count = count+1;
_     _    _ _  Numcounts[i] = count;
_  _ _  _   }
  _  _     _else{
_  ___ _  __ __ count = 0;
  __      _ }
  __   _}
    }
}

A:

If_the array is sorted you do_not need_hashmaps to_achieve O(n). If you have a random/unsorted array you can use_hashmaps to achieve the purpose, see_Paulo's answer for that._Note that_sorting_requires O(n log(n)).
If_you_want to_know how often each integer is in_the original_collection you will also need hashmaps,_but if you only_want_to know a nonduplicate number in_a sorted array the following code_will work:
// N is the_number_of_ints in sorted
int nonduplicate(int sorted[],_const int N){
   _//To prevent segfaulting_when N=1
    if(N==1){ return_sorted[0];_};

    for(int i=0;i_<_N-1;i++){
     ___if(sorted[i] == sorted[i+1]){
  _     _   // Next number in collection is_the same so_the current number is not_unique
__         _// Set_i to the_first location of the next different number
   _      _ do{
         _      i++;
 _      _   }while(i_<_N-1 && sorted[i] == sorted[i+1]);
  ____  }else{
_  _  _ _  _// The_next number is_different_so the current is unique
            return sorted[i];
_     _ }
   _}
_  _// Is the last_number unique?
    if(sorted[N-1]!= sorted[N-2]){
 _      return sorted[N-1];
 __ }
_   //_No unique_numbers
 _  return_-1; _ _// Or_some other value you reserve for it
}

Note_that_this code