Intel Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
4
of 4 vote

Its a Fibonacchi seq.. Can be solved by recursion in FIB.

1st step - 1 way to climb
2nd step - 2 ways
3rd step - 3 ways (Take one then take 2 steps or take 2 or take 1 step or take one step each. Hence total 3 ways)
4th step - will have 5 ways

and so on ...

If you look into it ... it will be a fib series.

Please post any suggestions
Thanks.

- Neo March 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what i think is question was to find number of combinations not permutations
Hence the answer for 3rd step should be 2 {(2+1),(1+1+1)} as (2+1)=(1+2)

also to find solution first of all find number of 2 step that it can take +1


therefore 5/2(int) +1;

- rdx March 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
3
of 3 vote

It's a febonacci equation with following property:

f(n) = f(n-1) + f(n-2) { iff n > 2}

f(1) = 1 // only 1 choice
f(2) = 2 // 2 choices either 2 step (1 step each) or 1 step (2 step)

Thanks

- Manoj March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

package random;

public class Stair {
	
	static int steps = 0;
	static StringBuilder sb = new StringBuilder();
	
	public static void main(String[] args){
		doSearch(0,sb);
	}
	
	public static void doSearch(int current, StringBuilder sb){
		
		if (current == 5) {
			System.out.println(sb);
			return;
		}
		
		
		if (current + 1 <=5){
			sb.append("1");
			doSearch(current+1,sb);
			sb.setLength(sb.length()-1);
		}
		if (current + 2 <=5){
			sb.append("2");
			doSearch(current+2,sb);
			sb.setLength(sb.length()-1);
		}
	}
	
}

- Jie March 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yes, it is pretty cool.

- chenlc626 March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

from point of view of generalising it wudnt work well...i am sure the next q would be to generalize it for more steps ;)

- bbarodia March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i think ans . is 8..
step1:if don't use 2 steps .then only 1 way
step 2: if we use single 2 steps ..then 4 ways
step 3: if we use double 2 steps .then 3 ways
so total combintaion is 8..
plz comment if you are not agreed!!

- Mukesh Kumar Dhaker March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think 8 as well - combos follow:

1 1 1 1 1
1 2 1 1
1 1 2 1
1 1 1 2
2 1 1 1
1 2 2
2 1 2
2 2 1

- mandererj March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<map>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cctype>
#include<queue>
using namespace std;
int cnt=0,parr[6];
void dfs(int crs,int dep);

int main()
{
    dfs(0,1);
    cout<<cnt;

}

void dfs(int crs,int dep)
{

    for(int i=1;i<=2;i++)
    {
        int ncrs=crs;
        if(i==1){ncrs+=1;parr[dep]=i; }else {ncrs+=2;parr[dep]=i;}
        if(ncrs==5)
        {
            cnt++;int sm=0;
            for(int j=1;j<=5;j++)
            {
                sm+=parr[j];
                 if(sm<=5)
                cout<<parr[j]<<"  ";
                else
                    cout<<"0  ";
            }
            cout<<endl;

            return;
        }

        else if(ncrs>5)return;
        else
        {

            dfs(ncrs,dep+1);

        }
    }
}

/*
Output :

1  1  1  1  1
1  1  1  2  0
1  1  2  1  0
1  2  1  1  0
1  2  2  0  0
2  1  1  1  0
2  1  2  0  0
2  2  1  0  0
8


*/

- Peter March 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Plz check this line
else if(ncrs>;5)return;

semicolon got inserted automatically , remove it to run . :D

- Peter March 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Running Source Code here :

ideone.com/XA0aS3

- Peter March 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

build up a tree, the root node is 5, the sub node is ether -1 or -2, which means how many steps you take, so the tree is like below. Totall 8 combinations.
5 - 4 - 3 - 2 - 1
- 0
- 1
- 2 - 1
- 0
- 3 - 2 - 1
- 0
- 1

From the tree, we can also see,
if there are 1 stairs, there is only 1 combination
2 stairs, there are 2 combinations
3 stairs = f(2) + f(1)
f(4) = f(3) + f(2)
...
if there is m stairs, you can take 1 - n steps
f(m) = f(m-1) + f(m-2) + ... + f(m-n)

- Anonymous March 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

one scenario is if m == n, we need consider f(0) = 1;

- Anonymous March 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Steps {
	public static void main(String[] args) {
		total("",5);
	}

	private static void total(String str,int steps){
		if (steps == 0)
			System.out.println(str);
		if (steps >= 1)
			total(1+" "+str,steps-1);
		if (steps >= 2)
			total(2+" "+str,steps-2);
	}
}

1 1 1 1 1
2 1 1 1
1 2 1 1
1 1 2 1
2 2 1
1 1 1 2
2 1 2
1 2 2

- asahai March 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
In ruby, this is what you do: {{{ puts ([1,2,1,1].permutation.to_a.uniq.length + [2,2,1].permutation.to_a.uniq.length + [1,1,1,1,1].permutation.to_a.uniq.length)}} The output is 8 - Anonymous March 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

To solve this in pure math:

Arrange 5 identical items in 5 spaces = 1!

Arrange 1 unique item and 3 similar items in 4 spaces = 4!/3!

Arrange 1 unique item and 2 similar items in 3 spaces = 3!/2!


Total number of arrangements:

1! /1!+ 4!/3! + 3!/2! = 8

- Anonymous March 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I have made an generic algorithm, that ask fot the number of stairs, and returns the number of ways to climb the stairs:

first, I assume that exist at least one way ti climb the stairs (only 1s), then, I add the number of permutations of '2s' in the secuence, starting with one 2, then 2 2s and so.

int n;
cout << "give me number of stairs:" << endl;
cin >> n;

int formas = 1;
int cantidad = n;
int i = 1;
int tmp;
while((cantidad - (2*i)) > 0)
{
tmp = cantidad - (2*i);
formas += (tmp + i)*i;
i++;
}
cout << "ways to climb the stairs:" << formas << endl;

- Pablo Camarillo June 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

but, it is needed to rest the number of repettions of 2

- p.camarillor June 23, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is the right solution, sorry:

cout << "give me number of stairs:" << endl;
cin >> n;

int formas = 1;
int cantidad1s = n;
int cantidad2s = 1;
int tmp;
while((n - (2*cantidad2s)) > 0)
{
cantidad1s = n - (2*cantidad2s);
formas += factorial(cantidad1s + cantidad2s)/
(factorial(cantidad1s)*factorial(cantidad2s));
cantidad2s++;
}
cout << "ways to climb to the stairs:" << formas << endl;

- p.camarillor June 23, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

8 combinations-
1,1,1,1,1
1,2,1,1
1,2,2
1,1,1,2
1,1,2,1
2,1,1,1
2,1,2
2,2,1

- Nuka shrinivas Rao February 13, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

int stepCount(int stepRemaining) {
    if( stepRemaining == 0 ) return 0;
    if ( stepRemaining == -1 ) return -1;
    return totalNumberOfStep = stepCount (stepRemaining -1 ) + StepCount (stepRemaining -2);

- sjain March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This code is incorrect.. the above code will fail even for 1 or 2 steps

- asahai March 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

have you atleast tried for dry run before giving a negative vote..

- sjain March 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, I tried it. With input =1 , output will be -1 . Same result with input = 2 i.e. -1

- asahai June 26, 2015 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More