Amazon Interview Report
- 0of 0 votes
AnswersIt is my first phone screening, it consists of two questions , first question was pretty simple
- tylerDurden September 15, 2011 in India for Data Storage
Q1:WAP to find the sum of contiguous subarray within a one-dimensional array of numbers which has the largest sum.
My Soluton :Kadane’s Algorithm:
int maxSubArraySum(int a[], int size)
{
int max_so_far = 0, max_ending_here = 0;
int i;
for(i = 0; i < size; i++)
{
max_ending_here = max_ending_here + a[i];
if(max_ending_here < 0)
max_ending_here = 0;
if(max_so_far < max_ending_here)
max_so_far = max_ending_here;
}
return max_so_far;
}| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 0of 0 votes
AnswersQ2:Implement T9 moblie phone dictionary .But the problem was just to find all the posible outputs given the the sequence of key pressed.
- tylerDurden September 15, 2011 in India for Data Storage
My Solution :Recursion
private static String[] mapping = { "ABC", "DEF", "GHI", "JKL", "MNO",
"PQR", "STU", "VW", "XY", "Z*#" };
public static void combinations(int[] number, char[] buf, int numIndex) {
for (int i = 0; i < mapping[number[numIndex]].length(); i++) {
buf[numIndex] = mapping[number[numIndex]].charAt(i);
if (numIndex < number.length - 1) {
combinations(number, buf, numIndex + 1);
} else
System.out.println(buf);
}
}
public static void main(String[] args) {
int num[] = { 0, 1};// { 4, 8, 5, 9, 0, 3, 1, 7,6,2 };
PhoneBook.combinations(num, new char[num.length], 0);
}
He was looking for Trie data structure :(| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Trees and Graphs