![]() |
VOOZH | about |
Given integers 'K' and 'N', the task is to find the Nth term of the K-Fibonacci series.
In K - Fibonacci series, the first 'K' terms will be '1' and after that every ith term of the series will be the sum of previous 'K' elements in the same series.
Examples:
Input: N = 4, K = 2 Output: 3 The K-Fibonacci series for K=2 is 1, 1, 2, 3, ... And, the 4th element is 3. Input: N = 5, K = 6 Output: 1 The K-Fibonacci series for K=6 is 1, 1, 1, 1, 1, 1, 6, 11, ...
A simple approach:
Time Complexity: O(N*K)
An efficient approach:
Below is the implementation of the above approach:
3
Time Complexity: O(N)
Auxiliary Space: O(N)