Adobe Interview Question for Software Engineer / Developers






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

what does shifted 'downward' or 'upward' mean? Is it shift left and right??

- Anonymous October 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

unimodal array

- anon November 10, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Find the pivot element, i.e the initial random number using binary search and perform the binary search on left or right part.

- Erik October 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Erik: you understood the problem? could you please rephrase it so we could all understand?

- hgk October 25, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Erik: you understood the problem? could you please rephrase it so we could all understand?

- hgk October 25, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think the problem is :
Suppose we have an array {1 2 3 4 5 6 7}. We choose a random number lets say 3. Now all elements on right of 3 are moved to its left and vice versa.The array then is {4 5 6 7 3 1 2}. We need to search for a particular number in this array.
I hope its correct.

- Spec October 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Even then Eric's solution would be ok.
1]Check on the number selected.
2]Shift the numbers as per the requirement.
3]I believe, if the shifts happen as per Spec's assumption,
the sub arrays with the pivot as the selected number are still sorted.
4] Now again select a number to be searched. If greater than the pivot, perform binary search on the left subarray or else of smaller than the pivot perform binary search on the right subarray.

Please advise.

- amit October 25, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Binary search
1. Check no in middle
2. If no is > mid item then check if no is < last item then check in upper half else check in lower half.
If no is < then mid then check if no is > first item then check it in lower half else check it in upper half.

3. Repeat step 1 & 2

- Anonymous October 26, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

binary_search(int x,int low,int high)
{


mid = (low+high) / 2;
if(A[mid] == data)
{
printf("the data is found at the index %d",mid);

}

if(data > A[mid])
if( A[high] > data)
{

binary_search(data, mid+1, high);
}
else
{
binary_search(data,low,mid-1);


}

else(data < A[mid])
if(data < A[low])
{
binary_search(data,mid+1,high);

}
else
binary_searhc(data,low,mid-1);

}

- Nagendra October 26, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This code fails for the following case
{5,6,7,8,9,10,11,4,3,2,1}

binary_search on 11.

- GK November 06, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

decide whether the sequence is asending or descending. now find the pivot by
dividing the data set into 2 power parts(we have 1, 3, 7 ... partition points and compare the data at those points, as you know whether they are ascending or descending) and find where the flow of ascending or descending breaks (and starts again).. and there we have pivot. after finding pivot, it is cakewalk with binary search.. read till you understand..

- shashidhar November 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ok, nagendra can you please give the basic idea or a proof of concept behind your approach. I can see that it works but cant convince myself.

And yes can somebody or the one who posted the ques throw light on the fact "whether we know the position of the pivot while shuffling the array". If yes the ques is pretty straight forward.

- Hary November 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Suppose the elements are {10,15,20,25,30,35,40} and the random no is 20. The new array would be {25,30,35,40,20,10,15}. Suppose the no. to be searched is x.
Step1. Find index of random no. i.e 20. can be done in O(n) or could have been cached earlier.
Step2. Check x with random no i.e Array[index] i.e 20.
Step3. If x is greater than random no, then do binary search between elements 0 to index-1. If x is less than random no, then do binary search between elements index+1 to Arraymax
Every one knows binary search.
The logic is that all elements above random no is sorted and all elements below random no are sorted. Hence we need to manually identify where x falls and then use binary search

- Avinash November 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi Avinash. If pivot element is the first number or second number, you end up scanning the whole array. So it is O(n).
If you are using an O(n) solution then why search for pivot element, you could have searched for the key itself. So this is not a good solution.

- Himanshu Govil November 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

binSearch(int low,int high,int data, int arr[]){
   mid = (high + low) /2;
   if (A[mid-1] < A[mid] && A[mid] < A[mid-1]){ // we are in the increasing range
     if(A[mid) < data)
       binSearch(mid,high,data,arr)
     else
       binSearch(low,mid,data,arr)
   }
   else{ // we are decreasing range
     if(A[mid] < data)
        binSearch(low,mid,data,arr)
     else
        binSearch(mid,high,data,arr)
   }   
}

- Anonymous November 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

ofcourse
if (A[mid] == data)
return true;

- Anonymous November 23, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@anonymous:check your if condition,I suppose u meant A[mid-1]<A[mid]&&A[mid]<A[mid+1].Now,If my array is {0,1,2,3,4,5,6,7,8,9} and pivot is 7 then new array would become {8,9,7,0,1,2,3,4,5,6}.If I am searching for 9 then according to your code after,checking conditions of middle your code would start a binary search on subarray {1 2 3 4 5 6}..Thus giving wrong answer

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

Find the pivot point, divide the array in two sub-arrays and call binary search.
The main idea for finding pivot is – for a sorted (in increasing order) and pivoted array, pivot element is the only only element for which next element to it is smaller than it.
Using above criteria and binary search methodology we can get pivot element in O(logn) time

Input arr[] = {3, 4, 5, 1, 2}
Element to Search = 1
1) Find out pivot point and divide the array in two
sub-arrays. (pivot = 2) /*Index of 5*/
2) Now call binary search for one of the two sub-arrays.
(a) If element is greater than 0th element then
search in left array
(b) Else Search in right array
(1 will go in else as 1 < 0th element(3))
3) If element is found in selected sub-array then return index
Else return -1.

- Bindu January 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Find pivot which can be done in o(logn) as follows
a= arr[0], b=arr[last].....now b < pivot < a ...pre check if pivot is a or b
1 left=0, right=end, mid=(left+right)/2
2 if(arr[mid] < arr[mid-1]) then pivot is at mid
else if(arr[mid] <a) then mid =(left+mid)/2 and right = old value of mid
else mid=(right+mid)/2 and left = old value of mid
loop until pivot is found

3. now that pivot postion is fond ..search the element on required side of arrray using binary search...
this gives algo in o(logn)

- arpit wanchoo March 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool binsearch(int *arr, int l, int h, int searchElement)
{
int mid = (h-l)/2;

if(l>= h)
return false;
if(arr[mid] == searchElement)
return true;
else if(searchElement > arr[mid])
binsearch(arr, mid+1,h,searchElement);
else
binsearch(arr,l,mid-1,searchElement);
}

bool FindElement(int *arr, int circShifted, int SearchElement,int length)
{
if(arr[circShifted] == SearchElement)
return true;
else
return (binsearch(arr,0,circShifted-1,SearchElement) || binsearch(arr,circShifted+1,length,SearchElement));
}

- DashDash July 18, 2010 | 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