Microsoft Interview Question for Software Engineer / Developers


Team: Bing
Country: India
Interview Type: In-Person




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

We can convert this to a bin packing problem which can be solved using a Max Winner tree. Complexity is O(log n).

- isandesh7 January 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you explain it a bit more?

- hulk October 24, 2015 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Hi,
Can you please explain more about the question like, what do the numbers 4, (3,1) , (2,2) indicate?
Thanks in advance

- Anonymous December 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Suppose there are no 4 continuous seats. Then your program shd return the seat like 3 together and 1 seperate, if that is not possible. return 2-2 together. and so on.

- Rachit Singhal December 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*
* BusSeat.cpp
*
* Created on: Dec 10, 2012
* Author: Kevin Li
*/


#include <cstdio>
#include <iostream>
using namespace std;
//This is the available seats in each row
int seatRow[10]={3,1,2,2,1,1,2,1,2,1};
bool flag=false;
//check if there is enough seat n for the request
bool seatsAvailable(int n)
{
for(int i =0; i< 10; i++)
{
if(seatRow[i]>=n)
{
seatRow[i]-=n;
return true;
}
}
return false;
}

int getSeat(int total,int n)
{
//check if request seat number available
if(seatsAvailable(n))
{
cout<<"get seat number"<<n<<endl;
if(total>n)
{
//if there is still more seat needed, search them
getSeat(total-n,total-n);
}
return 0;
}
else
{
int seat =getSeat(total,n-1);
}
return 0;
}

- lwh20053276@163.com December 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What is n and total in the above function....
Also interviwer do not need seat number n . he needs n number of seats.

- Rachit Singhal December 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

naga-programming-concepts.blogspot.in/2012/12/bus-reseravation-httpwwwcareercupcomque.html

- cobra December 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This should work,although doing lot more than required.

#include <stdio.h>
#include <stdlib.h>

const int R=10;
const int C=6;

int gettotal(int *seats,int size)
{
	int i,sum=0;
	for(i=0;i<size;i++)
		sum+=seats[i];
	return sum;
}

main()
{
	int seats[R];
	int i,num,start,end,j,max=0,index=-1,available;
	char c;
	for(i=0;i<R;i++)
		seats[i]=C;
	do
	{
		printf("No. of tickets:\n");
		scanf("%d",&num);
		for(i=0;i<R;i++)
		{
			available=gettotal(seats,R);
			if(num>available)
			{
				printf("\n#####Only %d seats available#####\n",available);
				break;
			}
			if(seats[i]>=num)
			{
				start=C-seats[i]+1;
				end=start+num-1;
				printf("\t%d seats allotted at row %d seat %d-%d.\n",num,i,start,end);
				seats[i]=seats[i]-num;
				for(j=0;j<R;j++)
					printf("%d ",seats[j]);
				printf("\n");
				break;
			}
			else
			{
				if(seats[i]>max)
				{
					max=seats[i];
					index=i;
				}
				if(i==R-1)
				{
					start=C-seats[index]+1;
					end=start+max-1;
					printf("\t..%d seats allotted at row %d seat %d-%d.\n",max,index,start,end);
					seats[index]=seats[index]-max;
					num=num-max;
					for(j=0;j<R;j++)
						printf("%d ",seats[j]);
					printf("\n");
					i=-1;
					max=0,index=-1;
				}

			}
		}
		// for(j=0;j<R;j++)
		// 	printf("%d ",seats[j]);
		if(gettotal(seats,R)==0)
		{
			printf("\nNO MORE ALLOCATION POSSIBLE.. QUITTING\n");
			break;
		}
		printf("\nCONTINUE?y[n]: ");
		c=getchar();
		c=getchar();
	}while(c!='n');
}

- snis December 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thank you snis for the solution. But we should also handle the cancelation of the tickets.In that case your program will fail as you are not taking care of the seat numbers that is occupied.

- rachit December 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

onestopinterviewprep.blogspot.com/2014/03/bus-seat-reservation.html

- Wellwisher March 26, 2014 | Flag Reply


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