Friday, April 5, 2013

Amazon Interview Question #1 - Maximum Sum Sub Array

I have been taking data-structures and algorithm interviews for Amazon. But I have been repeating from a small set of questions and I want to break this habit. So I am planning to post the interview questions and my code.

We expect the candidate to solve these question within an interview of 1 hr duration.

Amazon Interview Question #1: 

Problem: Maximum Sum Sub Array.
Description: given an integer array find the sub array that has maximum sum.

for e.g.
Sample Array = {2,-1,2,-1,4,-5}
Answer: 2,-1,4
Answer: 2,-1,2,-1,4

My Solution:

Have Feedback?Is my solution buggy?
please leave a comment

2 comments:

amal said...

Shouldnt the solution to the sample array input be 2,-1,2,-1,4 ? the sum of that subarray is 6 wheras the sum of the one you have given is only 5.

Am I missing something?

Unknown said...

you are correct. I am fixing the example.