Getting RE(SIGSEGV) in Increasing Decreasing (Second Subtask)

I might know the reason which is probably the size of the frequency array and also can you tell a way to initialize frequency array using vectors ?

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int max_size = 100002;
int main(){
    int test_case;  cin >> test_case;
    while(test_case--){
        int n; cin>> n;
        vector<int> v;
        vector<int> v2;
        int freq_arr[n*5]{0};
        int flag=0;
        for(int i=0;i<n;i++){
            int x;  cin >> x;
            v2.push_back(x);
            freq_arr[v2[i]]++;
        }
        int max_element_freq = *max_element(freq_arr, freq_arr+max_size);
        if(max_element_freq == 1){
            sort(v2.begin(),v2.end());
            cout << "YES\n";
            for(auto x:v2) cout << x << " ";
            cout << endl;
        }
        else{
            int max_ele = *max_element(v2.begin(),v2.end());
            if(count(v2.begin(),v2.end(),max_ele) > 1) flag=1;
            if(max_element_freq > 2) flag=1;
            if(flag==1) cout << "NO\n";
            else{
                cout << "YES\n";
                sort(v2.begin(),v2.end());
                for(int i=0;i<n;i++){
                    if(v2[i] != v2[i+1]){
                        cout << v2[i] << " ";
                    }
                    else v.push_back(v2[i]);
                }
                for(int i=v.size()-1; i>=0;i--){
                    cout << v[i] << " ";
                }
                cout << endl;
            }
        }
        
        
    }
   return 0;
}

Edit : Forgot to mention that i did tried by max_size in freq_arr still RE.

you can not be sure if the every element will lies in the range [0,n*5] like array 0,12
so ur freq array should be of either the max size possible or the max in the given array

Check the edit mate