Amazon Interview Question for Developer Program Engineers


Country: India
Interview Type: Written Test




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

def difference(numbers):
output = []
for i in range(len(numbers) - 1):
output.append(numbers[i+1] - numbers[i])
return output

numbers = [787668, 787787, 787948, 787980, 788094, 788124]

print difference(numbers)

- Elena Henderson October 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def difference(numbers):
    output = []
    for i in range(len(numbers) - 1):
        output.append(numbers[i+1] - numbers[i])
    return output

numbers = [787668, 787787, 787948, 787980, 788094, 788124]

print difference(numbers)

- Elena Henderson October 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
		int[] main = {10,40,78,98};
		int[] result = new int[main.length-1];
		
		for(int i = 0; i<main.length-1; i++){
			result[i] = main[i+1]-main[i];
		}
		
		for(int i = 0; i<result.length; i++){
			System.out.println(result[i]);
		}
	}

- Sachin October 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is a very bad practice to name a local variable the same as the function it is within(main)

- Selmeczy, Péter October 16, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

A few things already missed big time:
1. What if there are no numbers at all?
2. What if we do not know the number of numbers e.g. they are in a file?
3. The output does not look like the requested (e.g. no , between the numbers, and there isn't one at the end

- Selmeczy, Péter October 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void printOutput(InputStream inputStream) {
        Scanner scanner = new Scanner(inputStream);

        List<Long> numbers = new ArrayList<Long>();
        while (scanner.hasNext()) {
            numbers.add(scanner.nextLong());
        }

        int numNumbers = numbers.size();
        if (numNumbers == 0 || numNumbers == 1) {
            //
        } else {
            for (int i = 1; i < numNumbers; i++) {
                System.out.print(numbers.get(i) - numbers.get(i - 1) + ",");
            }
        }

}

- IgorBrown31 October 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def diff(inp):
	op=[]
	for i in range(0,len(inp)-1):
		op.append(abs(inp[i]-inp[i+1]))

	print(op)

inp = [787668, 787787, 787948, 787980, 788094, 788124]
diff(inp)

- shukad333 October 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static int[] diff(int[] a) {
        int[] output = new int[a.length - 1];
        for (int i = 1; i <= a.length - 1; i++) {
            int temp = a[i] - a[i - 1];
            if (temp < 0)
                temp*=-1;
            output[i - 1] = temp;
        }
        return output;

}

- Mehmet October 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void Main()
	{
		int [] arr = {50,100,145,555,344,200};
		
		int nextSum = 0;
		
		for (int i = 0; i < arr.Length; i++)
		{
			nextSum += arr[i];
			
			if (i > 1)
			{
				nextSum -= arr[i-2];	
			}
			
			Console.WriteLine(nextSum);
				
		}
		
		
		
	}

- abramN November 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

oops, that's for the sum...here's the difference

using System;
using System.Collections.Generic;
					
public class Program
{
	
	public static void Main()
	{
		int [] arr = {50,100,145,555,344,200};
		
		int nextDiff = 0;
		
		for (int i = 0; i < arr.Length-1; i++)
		{
			
			
			Console.WriteLine(Math.Abs(arr[i] - arr[i+1]));
				
		}
		
	}
	
}

- abramN November 04, 2014 | 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