GeeksforGeeks » Interview Questions
Google Interview Question for Software Engineer/Developer about Puzzle
(3 posts)-
You have N steps to get down. You have two options
a. either you come one step down (nth to (n-1)th )
b. or you directly jump to the 3rd step leaving one step in between. ( say from nth to (n-2)th )Find the total possible ways in which one can get down.
-
Let F(n) defines the number of ways you can climb down n steps..
Since you can either go one step and find F(n-1) or go two steps and find F(n-2)
=> F(n) = F(n-1) + F(n-2)
A fibonacci series
Base case will be F(0) = 1 and F(1) = 1
-
There are several way to compute n-th Finonacci number: recursive O(2^n), dynamic programming O(n) and using the formula F(n) = [phi ^ n / 2 - 1/2] where phi is the golden ratio : phi = (1 + sqrt(5))/2. To compute the n-th power of a number is O(log n) - treat cases when n is odd or even.
Reply
You must log in to post.