Discussion About Unique Number - III

This is Discussion thread about Unique Number - III

Optimal code

#include<iostream>
#include<vector>
#include<string>  
#include<bits/stdc++.h> 
using namespace std;

int main() {
    int n;
    cin>>n;
    int a[n];
    int max=-9999999;
    for(int i=0;i<n;i++)
    {
        int no;
        cin>>no;
        a[i]=no;
        if(no>max)
        {
            max=no;
        }
    }
    int size;
    while(max>0)
    {
        max=max>>1;
        size+=1;
    }
    int ansarr[size]={0};
    for(auto i:a)
    {
        int z=0;
        int no=i;
        
        while(no>0)
        {
            ansarr[z]+=(no&1);
            no=no>>1;
            z+=1;
        }
    }
    string ans;
    for(auto i:ansarr)
    {
        ans+=to_string(i%3);
    }
    reverse(ans.begin(),ans.end());
    cout << stoi(ans, 0, 2);
    
}