Amazon Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
4
of 6 vote

The way the question is stated it doesn't make any sense.

- Paul March 21, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;
public class ArrayFrequency{

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
int temp=0;
int n=0;
int[] array;

while (sc.hasNextInt()) {
n = sc.nextInt();
if(n<0 && n>10 ){
System.out.println("please enter a valid numer.");
break;
}
temp=temp+n;
array = new int[n];
for(int i=n-1;i>=0;i--){
array[i]=n;
}

for(int x: array){
System.out.println(x);
}
}
if(sc.hasNextInt()==false){
sc.close();
System.out.println("plese enter a valid numer from 0-9.Exit...");
Runtime.getRuntime().exit(0);

}
}

- lparka123 March 21, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.demo;

import java.util.Scanner;

public class ArrayFrequency{

public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int temp=0;
			int count=0;

			System.out.println("please enter a no of elements.");
			int number = sc.nextInt();
			int[] array=new int[number];
			
			for(int i=0;i<number;i++){
				array[i]=0;
			}
			int n ;
			while(count<number){
			System.out.println("Enter element->.");	
				n = sc.nextInt();
				if(n<0 && n>10 ){
					System.out.println("please enter a valid numer.");
					break;
				}
				array[n]++;
				count++;
				}
			for(int i=0;i<number;i++){
				System.out.print(array[i]);
				System.out.print("");
			}
			}


}

- DuttaJ March 21, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Seems like a very easy problem, for an in-person interview.
Unless I'm missing something.

public static int[] getCnt(){
	Scanner in = new Scanner(System.in)
	int[] res = new int[10];
	for(in.hasNextInt()){
		int t = in.nextInt();
		if(t >= 0 && t <= 9){
			res[t] += 1;
		}
		else{
			throw new IllegalArgumentException("Please enter a number between 0-9");
		}
	} 
	return res;

}

- Anon March 21, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

missed to add array size as 10, and you must fill this array by using 0 - 9.

case 2:
must use maximum numbers to fill the array.
Note:
a[i]=n means, i must present n-times in that array.

- algospecialist March 23, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int[ ] input = { 1, 1, 2, 6, 5,4,3,1,2,3 };
int[] output= new int[9];

for(int i=0;i<input.length;i++)
{
if(output[input[i]]==0)
{
output[input[i]]=1;
}
else
{
int cnt=output[input[i]];
output[input[i]]=cnt+1;
}
}

for (int i = 0; i < output.length; i++) {
System.out.println(output[i]);
}

- Sonam March 23, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int[ ] input = { 1, 1, 2, 6, 5,4,3,1,2,3 };
		int[] output= new int[9];
		
		for(int i=0;i<input.length;i++)
		{
			if(output[input[i]]==0)
			{
				output[input[i]]=1;
			}
			else
			{
				int cnt=output[input[i]];
				output[input[i]]=cnt+1;
			}
		}
		
		for (int i = 0; i < output.length; i++) {
			System.out.println(output[i]);
		}

- Sonam March 23, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def freq(a):

    d = dict(zip([x for x in range(0,10)], [0]*10))

    for x in a:
        d[x] += 1

    print(d)

freq([1,0,4,4,1,4,7,9,0,0,0,2])

{0: 4, 1: 2, 2: 1, 3: 0, 4: 3, 5: 0, 6: 0, 7: 1, 8: 0, 9: 1}

- eo March 28, 2017 | 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