Hackwithinfy 2021 Solution | Beautiful Array Problem

Question: Beautiful Array Problem

Solution: In C++

#include <iostream>

using namespace std;
void print_vector(vector<auto>v){
    cout<<"[";
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<",";
        
    }
    cout<<"]"<<end;
    
}
class solution{
    public:
    vector<int>beautifulArray(int N){
        vector<int>ret;
        ret.push_back(1);
        while(ret.size()<N){
            vector<int>temp;
            for(int i=0;i<ret.size(),i++){
                if(rey[i]2-1 <= N)temp.push_back(ret[i]-1);
                
            }
            for(int i=0;i<ret.size();i++){
                if(rey[i]2 <= N)temp.push_back(ret[i]);
            }
            ret=temp;
        }
        return ret;
    }
}
main(){
    solution ob;
    print_vector(ob.beautifulArray(6));
}

Follow Us

You Missed


Leave a Comment

Your email address will not be published. Required fields are marked *