15. Reach the Nth point
Last updated
Last updated
The problem can be found at the following link: Question Link
Initialize num1 and num2 to 1 and mod to 1e9+7.
Use a loop to iteratively calculate the nth term:
Calculate a as the sum of num1 and num2 modulo mod.
Update num1 and num2 with the values of num2 and a.
Return the final value of num2, representing the nth term in the sequence.
Time Complexity: O(n)
- The loop runs for n iterations.
Auxiliary Space Complexity: O(1)
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.