Amazon Interview Question for Software Engineer / Developers

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

Please keep up the good work !

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

binary search is Log-base2-n

len=a.length;

Check middle element a[len/2]==x

If x < a[len/2], search left half.
Else if x > a[len/2], search right half.

Do this iteratively until found.

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

in order search.

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

def bsearch(x, a):
if not a:
return None
i = len(a)//2
p = a[i]
if x == p:
return i
return bsearch(x, a[:i] if x < p else a[(i+1):])

print(bsearch(4,[1,1,1,2,3,4,5,5,6,7,20]))

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

int bsearch(int k, int n, int * x)
{ int head = 0; int tail = n-1; int mid = n/2;
while (k != x[mid]) && (head <= tail)
{ if (k < x[mid]) tail = mid-1;
}
if (k == x[mid]) return mid;
else return -1;
}

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.