Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

well , skip k - a[i] elements after each element and then search again ....
repeat till you find k

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

We can find mid if a[mid]<p and a[mid]>0 return mid;

else if a[mid]>p search left between 0 and mid else find between mid and p.

this is log(n) where n is length of array.

- Free Bird May 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

consider the following example
0, 1, 2, 1, 1
will your logic work??

- ra1 May 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

to ra1: since the constrain is 0 < k < p. there is no such k in your example. With the constrain, binary search works.

- sqw May 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Don't agree. How about 0,1,2,3,4,5,4,3,4,4,4 K=3? There are two Ks, one in left one in right.

Binary search is used for exclusively unique value. If one value simultaneously occurs in both side, then binary search is useless.

- Anonymous June 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

what's O(n/k) algo?

- curious May 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use binary search-> compare value of k with value of index mid and value at mid as follows:
if(a[mid]==k) return mid;
else
       if(k<mid)
              if(k>a[mid])
                    low=mid+1
              else
                   high=mid-1
      else //when k >=mid
           low=mid+1

- rrrk May 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

well the binary search work just as it is..because, if K is greater than current mid then their must be an element on right of current mid which is equal to K otherwise the last element cannot be p (which is greater than K). Similarly if K is less than current mid there must be an element on left of current mid equal to K (otherwise the current mid cannot be greater than K). So apply binary search as follows:
if K is greater than current mid, compare K with mid element of right array and vice versa.

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

Don't agree. How about 0,1,2,3,4,5,4,3,4,4,4 K=3? There are two Ks, one in left one in right.

- Anonymous June 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

difference = MOD(arr[i]-k)

if difference = 0 then print else skip next difference elements
i+=difference

repeat till k is found or end of array is reached

- varun July 17, 2012 | 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