Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 769 Bytes

21.md

File metadata and controls

36 lines (25 loc) · 769 Bytes

Print Pattern

Print a sequence of numbers starting with N, without using loop, where replace N with N - 5, until N > 0. After that replace N with N + 5 until N regains its initial value.

Example 1:

Input: N = 16 Output: 16 11 6 1 -4 1 6 11 16 Explaination: The value decreases until it is greater than 0. After that it increases and stops when it becomes 16 again.

vector<int> ans;
    
    void find(int n)
    {
            
        ans.push_back(n);
        
        if(n<=0)
            return;
        find(n-5);
        ans.push_back(n);
    }
    
    vector<int> pattern(int N){
        // code here
        
        find(N);
        return ans;
    }