Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

Well this is just a toy code that assumes we already know the array size. We can start with this and then enhance it.

#include <iostream>
#include <vector>
using namespace std;

int main ( ) {
	int a[] = {1,2,3,4,5};
	int max = -1, i = 0;

	try {
		while (true) {
			if (i > 4) {
				throw max;
			}
			if (a[i] > max) {
				max = a[i++];
			}
		}
	}
	catch (int max) {
		cout << "Max value is: " << max << endl;
	}

	return 0;
}

- Nitin March 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

public static void main(String[] args) {
int[] a = new int[10];
try {
for (int i = 0; i < 100; i++) {
a[i] = 1;
}
} catch (ArrayIndexOutOfBoundsException i) {
System.out.println(i);
}
}

- adi March 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

trow exception with the result

- guru March 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@guru: Could you eloborate on what you posted.As it is not clear

- Srishti March 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@guru: Could you eloborate on what you posted.As it is not clear

- Srishti March 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

how can 'return' be replaced by 'try and catch'?

- joycee March 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a short java demo, you can also add parseInt to get the int or just leave it as string

public static int maxV (int [] arr) throws Exception{
	     int max = Integer.MIN_VALUE;
	     for (int i = 0 ; i < arr.length; i++){
	          if (arr[i] > max){
	               max = arr[i];
	          }
	     }
	     throw new Exception (""+max);
	}    


	public static void main (String args[]){
	     try {
	          int [] arr = {1,45,1,12,4};
	          maxV (arr);
	     } catch (Exception e){
	          System.out.println(e.getMessage());
	     }
	}

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

a short java demo, you can also add parseInt to get the int or just leave it as string

public static int maxV (int [] arr) throws Exception{
	     int max = Integer.MIN_VALUE;
	     for (int i = 0 ; i < arr.length; i++){
	          if (arr[i] > max){
	               max = arr[i];
	          }
	     }
	     throw new Exception (""+max);
	}    


	public static void main (String args[]){
	     try {
	          int [] arr = {1,45,1,12,4};
	          maxV (arr);
	     } catch (Exception e){
	          System.out.println(e.getMessage());
	     }
	}

- miaomiao July 10, 2012 | 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