Work in HR or Recruiting?
Google
4.1 of 5 1,435 reviews
www.google.com Mountain View, CA 5000+ Employees

294 interview experiences Back to all Google Interview Questions & Reviews

Interview Question for Software Engineer Intern at Google:
Jan 16, 2011

You are climbing a stair case. Each time you can either make 1 step or 2 steps. The staircase has n steps. In how many distinct ways can you climb the staircase ?


Add Tags [?]

See more for this Google Software Engineer Intern Interview

Helpful Question?  
Yes | No
Inappropriate?

Answers & Comments (7)

0 of 2 people found this helpful

Jan 25, 2011

by Anonymous:

2.*1*n distinct ways to climb
Helpful Answer?  
Yes | No
Inappropriate?

9 of 9 people found this helpful

Jan 28, 2011

by lamont:

Let c(i-1) = the total for a staircase with i-1 steps. Now add one step to the beginning. You have two choices: start with one step and then do c(i-1), or start with two steps and then do c(i-2). In other words, c(i) = c(i-1) + c(i-2). The basis for the recurrence is c(0) = c(1) = 1.

This is exactly the Fibonacci sequence. I submit that the solution to this problem of n steps is Fib(n+1). Let's verify for small values of n:

1 steps: There's only one way to take one step. (1)
2 steps: There are 2 ways (1+1) or (2)
3 steps: 3 ways (1+1+1), (1+2), (2+1)
4 steps: 5 ways (1+1+1+1), (1+1+2), (1+2+1), (2+1+1), (2+2)
Helpful Answer?  
Yes | No
Inappropriate?

Feb 03, 2011

by vkc:

No. of integral solutions to equation:

x+y = n

= n+2-1C2
Helpful Answer?  
Yes | No
Inappropriate?

Feb 03, 2011

by Shane:

int getways(int n)
{
  int i,j;
  int sumways=0;
  for(i=0;i<=n-i;i++)
  {
    if(i==0)
      sumways++;
    else
    {
      int subways=1;
      for(j=1;j<=i;j++)
        subways*=((n-j)/j);
      sumways+=subways;
    }
  }
}
Helpful Answer?  
Yes | No
Inappropriate?

Mar 04, 2011

by Wendy Godfrey:

If I may take the steps in 1 or 2 or any combination thereof =4 (remember, # of stairs are not factored). HOWEVER, this combination may have infinite combination the more stairs there are! You would still use the basic steps as the question has a base of two :

1+1
1+2
2+1
2+2
1+1+1+1+2+2+2+2. . . .
Helpful Answer?  
Yes | No
Inappropriate?

May 21, 2011

by dantepy:

this is fibonacci

your first step can be either 1 or 2 step.
if first step is 1 step, remaining is an N-1 problem.
if first step is 2 steps, remaining is an N-2 problem.
N problem = N-1 problem + N-2 problem
Helpful Answer?  
Yes | No
Inappropriate?

Oct 17, 2011

by Mihai Roman:

This is a dynamic programming puzzle with the Fibonacci recurrence: s(i) = s(i-1) + s(i-2).

More details here: http://dailyjobquestions.com/2011/10/17/stairs/
Helpful Answer?  
Yes | No
Inappropriate?

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords, helping to categorise interview questions that have something in common.