23. Rohan's Love for Matrix
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
Initialize two variables prev1 and prev2 to store the values of the first and second elements of the matrix respectively.
Iterate from 2 to n to calculate the nth power of the matrix.
Inside the loop, calculate the next element curr of the matrix as the sum of the previous two elements (prev1 and prev2) modulo 1000000007.
Update prev1 and prev2 with the values of prev2 and curr respectively.
After the loop, return the value of prev2, which represents the first element of the resulting matrix an.
Time Complexity : O(N)
Auxiliary Space Complexity : O(1)
For discussions, questions, or doubts related to this solution, please visit our . 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 repository.