![]() |
VOOZH | about |
Given a Fibonacci number N, the task is to find the previous Fibonacci number.
Examples:
Input: N = 8
Output: 5
5 is the previous fibonacci number before 8.
Input: N = 5
Output: 3
Approach: The ratio of two adjacent numbers in the Fibonacci series rapidly approaches ((1 + sqrt(5)) / 2). So if N is divided by ((1 + sqrt(5)) / 2) and then rounded, the resultant number will be the previous Fibonacci number.
Below is the implementation of the above approach:
5
Time Complexity: O(1)
Auxiliary Space: O(1)