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

Hey, can you like redefine the term Maximum Loss. like what is the referral point to calculate loss. Thanks

- Mohit Menghnani May 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Go thru the following article:
leetcode.com/2011/05/a-distance-maximizing-problem.html

Might help u ...

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

Traverse the array once keeping track of max_price_so_far and the max_loss_so_far

int max_loss(int price[], int n)
{
    int max_loss_so_far = 0;
    int max_price_so_far = price[0];

    int curr_loss=0;
    for (int i=1; i<n; i++)
    {
        curr_loss = max_price_so_far - price[i];
        if (curr_loss > max_loss_so_far)
            max_loss_so_far = curr_loss;
        if (price[i] > max_price_so_far)
            max_price_so_far = price[i];
    }

    return max_loss_so_far;
}

Time: O(n)
Space: O(1)

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

the question can be rephrased as

find i and j such that a[i]-a[j] is maximum and i>j...now this can be solved in O(n)

int n=10,min=arr[0],max=-32767	;
	for(int i=1;i<n;i++)
	{
		if(arr[i]<min)
		{
			min=arr[i];
			continue;
		}
		if(arr[i]-min>max)
			max=arr[i]-min;
	}
	cout<<"MAX DIFFERENCE IS : "<<max;

- varun July 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

here i>j is v imp.
the code gives max profit it can be changed to max loss by reversing the conditional operator.

- varun July 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

define f(n) is the max price before price n,
just find max(f(n)-price(n)) that's the max lose

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

public static int getMaximumDifference (int [] array){
int max = 0;
int min = array[0];
for(int i=0;i<array.length;i++){
if(array[i]>max) max = array[i];
if(array[i]<min) min = array[i];
}
System.out.println(max);
System.out.println(min);
int diff = max - min;
return diff;
}

public static void main(String [] args){
int [] arr = {6,7,3,2,5,6,79,2,35,67,8,9,999,67};
System.out.println(getMaximumDifference(arr));
}

- vibhanshu jha May 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Take the difference of ech day, and make array.change the sign of each elemnt in array.Then use Longest Maximum subarray solution(Kadane algor

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

traverse the array by checking each day price change. If it is negative this is a lost so we sum to the result. Otherwise we do not. Here is the Java code:

public int maxLoss(int[] a) {
  int result = 0;
  
  for (int i = 1; i <  a.length; i++)
   result += Math.min(0, a[i] - a[i - 1]); 
 
  return result;
 }

- GKalchev July 05, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if(price(i) > currentMax){
currentMax = price(i)
}
else{
currentloss = currentMax-price(i);
if(currentloss > maxloss){
maxloss = currentloss;
}

- - July 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

tree

- bree May 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

One fool proof way is to quick sort the array(complexity of logn) and find the diff of first and last elements.

- anonymous123 May 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

In one traversal, we can find which is the smallest and which is the largest.
Diff of them could give our answer.

- anonymous123 May 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Dear
Prices are increasing day by day, it means sorted form so just do it very simple like..

maxLoss = price[n]-price[1];
:-)

- Anonymous May 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Dear
Prices are increasing day by day, it means sorted form so just do it very simple like..

maxLoss = price[n]-price[1];
:-)

- kaseriya May 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Prices are in the increasing order of the day, and not that Prices are increasing day by day :-(

- Appy June 08, 2012 | Flag


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