## Microsoft Interview Question for Software Engineer / Developers

• 0

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

I don't get the question.

A one-pass scan will do the job. Or I miss something?

Comment hidden because of low score. Click to expand.
0

Yes! It doesn't have to be hard to be an interview question, right?

let val = neg_infi.
val is equal or less than N.

if (array[i] <= N && array[i] > val)
val = array[i]

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

subtract N from all...now read again if there is a value that reads 0 then there was a N there...otherwise the value that is the maximum in negative is the closest smallest to N...(-1 is greater than -2)

3 2 1 9 8 5 7
N=6
subtract N gives
-3 -4 -5 4 3 -1 1

Comment hidden because of low score. Click to expand.
0

it's not necessary have to be only the difference of one

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

i mean you dont have to read again just store the -ve value with the index in 2 temp variables ...the one with the max negative value on the numberline is the one

Comment hidden because of low score. Click to expand.
0

Does that make any better ?? I dont think so ... Khoa sol. is right.

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

int
myFunc(int *in,int size,int N)
{
int flag=0;
int cNo=-1;
for(int i=0;i<size;i++)
{
if (in[i]==N) {
cNo=i;break;
}
else if (in[i] < N && flag==0)
{
cNo =in[i];
flag=1;
}
if(in[i] < N && flag ==1) {
cNo= (in[i]>cNo) ? in[i]:cNo;
}
}
return cNo;
}

int main()
{
int in[7]={13,5,8,2,6,9,10};
int d= myFunc(in,sizeof(in)/sizeof(int),11);
char c=getchar();
}

check this out babes.

Comment hidden because of low score. Click to expand.
0

I think the second "if" ( if(in[i] < N && flag ==1) {
cNo= (in[i]>cNo) ? in[i]:cNo; )

is not required as the question says " first number that is smaller than N. "

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

This needs to be done using a hash table . We need to look up for numbers which are smaller than 0 in the hash table.

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

what if there is no value smaller than N?
Thats my first question to the interviewer

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.

### 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.