Help the Old Man!!!

 https://practice.geeksforgeeks.org/problems/help-the-old-man3848/1#

void solve(vector<int> &ans, int N, int n, int &i, int src, int help, int dest){
        if(N == 0){
            return;
        }
        solve(ans, N-1, n, i, src, dest, help);
        i = i+1;
        if(i == n){
            ans.push_back(src);
            ans.push_back(dest);
            return;
        }
        solve(ans, N-1, n, i, help, src, dest);
        return;
    }
    
    vector<int> shiftPile(int N, int n){
        // code here
        vector<int> ans;
        int i=0;
        solve(ans, N, n, i, 1, 2, 3);
        return ans;
    }

Comments

Popular posts from this blog

Perfect Peak of Array

Is Rectangle?

Sort array with squares!