Question:
How to find the total number of special sequences possible using C++

Summary

Consider the following three aspects:

  • seqi+1 >= 2*seqi 

  • seqi > 0

  • seqi <= m


Let’s assume: 

Function- Sequence and numberSequence


Solution


// User function Template for C++


class Solution{

    

    int Sequence(int length, int start, int end)

    {

        if (length == 0) return 1;


        if (start > end) return 0;


        auto result = 0;


        for (int i = start; i <= end; i++)

        {

            result += Sequence(length - 1, i*2, end);

        }

        

        return result;

        

    }

    

public:

    int numberSequence(int m, int n)

    {

        auto ret = Sequence(n, 1, m);

        

        return ret;

    }

};


Suggested blogs:

>Find the number of pairs of elements whose sum is equal to K using C++

>How to check whether string is palindrome or not using C++

>How to determine the smallest possible size of a vertex cover using C++

>Build an Electron application from scratch

>Building Web API using ASP.NET (C#)

>Built Web API using ASP.NET (C#)


Nisha Patel

Nisha Patel

Submit
0 Answers