Amazon Interview Question for Software Engineer Interns


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
3
of 5 vote

I'm going say this sounds a lot more like a homework question than something an AMAZON interviewer would ask. The solution to this is 5 seconds and very much so beneath the level of developer they are looking for. If you can count by 20 you're done.

Is there maybe more to the question?

- Anonymous August 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Even the easiest questions can show your coding fundamentals.
If you don't agree, you can try to answer the question then compare with others'.
I believe you can learn from it more or less.

- ttoommbb@126.com September 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

what we have to do?
we have to write code or complexity?

- Anonymous August 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Should we expect anything more from U ?

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

That definitely is not an Amazon interview question, for sure, too simple!

- Raul Rivero August 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I'd say that this question was likely meant as an elimination question rather than as a basis for selection. If someone is not able to code this and is interviewing for a software engineer position, there is no point in moving forward with the interview.

- Jules Verne August 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package gao.zone.study;

import java.lang.reflect.Array;
import java.util.Arrays;

public class SplitArr2 {

	public static void main(String[] args) {

		Integer[] arr = new Integer[88];// or use 0,1,19,20,21,999,1001
		for (int i = 0; i < arr.length; i++) {
			arr[i] = i;
		}

		Integer[][] splits = split(arr, 20);
		for (Integer[] sub : splits) {
			System.out.println(Arrays.toString(sub));
		}
	}

	/**
	 * Split.
	 *
	 * @param <T> the generic type
	 * @param arr the array, not null
	 * @param gap the gap distance, must be positive.
	 * @return the splitted arrays.
	 */
	@SuppressWarnings("unchecked")
	public static <T> T[][] split(T[] arr, int gap) {
		T[][] arrs = (T[][]) Array.newInstance(arr.getClass(),
				Math.min(gap, arr.length));

		int shortLength = arr.length / gap;
		int reminder = arr.length % gap;
		for (int i = 0; i < arrs.length; i++) {
			int partLength = i < reminder ? (1 + shortLength) : shortLength;
			arrs[i] = (T[]) Array.newInstance(arr.getClass().getComponentType(), partLength);
			for (int j = i, k = 0; j < arr.length; j += gap, k++) {
				arrs[i][k] = arr[j];
			}
		}
		return arrs;
	}
}

- ttoommbb@126.com September 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about

for (int i = 0; i < num.size(); i++){
	res[i%20][i/20] = num[i];
}

- tkt February 08, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

/**
 * Put every nth element from given array to list
 * @param input array to grab elements from
 * @param nth every nth element will be selected from input
 * @return a list with every nth element from input array
 */
private static <T> List<T> processArray(T[] input, int nth) {
    List<T> list = new ArrayList<>();
    for (int i=0, j=0; i < input.length; i++) {
        if (j == nth - 1) {
            list.add(input[i]);
            j = 0;
        } else {
            j++;
        }
    }
    return list;
}

/**
 * Test
 */
public static void main(String[] args) {
    Integer[] input = new Integer[1000];
    // Fill array with sample objects
    for (int i = 0; i < input.length; i++) {
        input[i] = i + 1;
    }
    Integer[] result = processArray(input, 20).toArray(new Integer[0]);
    for (Integer i : result) {
        System.out.println(i);
    }
}

- Anonymous August 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It's said "... and store it in a separate array ..."

- ttoommbb@126.com September 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

We are missing one condition here. The condition says to loop through all the elements in the array. So some modification from the above code.

int resultArr[1000];
int inputArr[1000 / 20];
for(int i=0, j=0; i<1000; i++) {
	if ((i%20) == 0) {
		resultArr[j] = inputArr[i];
		j++;
	}
}

- Madhusudhan Kasula September 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

for (i=0 to 1000/20-1)
{
for(j=0 to 19)
{
arr[j][i]=A[i*20+j]
}
}

- dianadijan September 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.


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