12. Recursive sequence
The problem can be found at the following link: Question Link
My Approach
This question is straightforward. Simply follow the steps asked by the question. I used two loops to compute the partial factorial, then combined sequence using modular arithmetic.
Time and Auxiliary Space Complexity
Time Complexity:
(O(n^2))
- The nested loops iterate through each integer up to n, and within each iteration, there is a calculation of the factorial which takes(O(n))
time.Auxiliary Space Complexity:
(O(1))
- Only a few variables are used for calculations, independent of the input size.
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the getlost01/gfg-potd repository.
Last updated