Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

NINJA JASOOS

Easy
0/40
Average time to solve is 15m
profile
Contributed by
5 upvotes
Asked in companies
OlaAdobe

Problem statement

Ninja grew 19 years older and started his own detective company. One day a kidnapper challenges our Ninja to solve a case. Kidnapper makes many duplicates of a child and each child (or we can say duplicate and the original one) is assigned a unique number. A bomb is tied to each child and it will blast within 5 minutes.

Now he gives a number ‘N’ to Ninja and tells him that the child mentioned with “Nth” Fibonacci number is the original child.

So help our Ninja in finding the “Nth” Fibonacci number so he can save the lives of children as within 5 minutes he can't defuse all the bombs alone.

Nth term of Fibonacci series F(N) is calculated using the following formula -

F(N) = F(N-1) + F(N-2), 
Where, F(1) = 1 F(2) = 1
Detailed explanation ( Input/output format, Notes, Images )
Constraints:
1 <= T <= 10000
1 <= N <= 40  

Time Limit: 1 second

Sample Input 1:

2
4
6

Sample Output 1:

3
8

Explanation of Sample Input 1:

Test Case 1:

In the first line, there is the number of test cases i.e., 2, and in the next line ‘4’is the number for which we have to find its equivalent Fibonacci number or we can say return the “4th” Fibonacci number.
So by using the property of the Fibonacci series i.e 

[ 1, 1, 2, 3]
So the “4th” element is “3” hence we get the output.

Test Case 2:

Now the number is ‘6’ so we have to find the “6th” Fibonacci number
So by using the property of the Fibonacci series i.e 

[ 1, 1, 2, 3, 5, 8]
So the “6th” element is “8” hence we get the output.

Sample Input 2 :

2
5
3

Sample Output 2 :

5
2
Full screen
Console