Google
 
Webcprogramming.com




An Affiliate of AIHorizon




Array Sum Challenge

In this challenge, given an array of integers, the goal is to efficiently find the start and end indices of the subarray that has the greatest value when all of its elements are summed together. Note that because some elements of the array may be negative, the problem is not solved by simply returning the start and end elements of the array.

For exaple, given the array

  {1, 2, -5, 4, -3, 2}
  
The maximum sum of a subarray is 4.

Before you write the code, take some time to think of the most efficient solution possible; it may surprise you. The major goal of this challenge is to test your algorithmic skills rather than merely your ability to write code quickly.



View Solution

If you like this problem, you may like the book from which I originally learned of the problem, Programming Pearls by Jon Bentley.

-----
Interested in advertising with us?
Please read our privacy policy.
Copyright © 1997-2006 Cprogramming.com. All rights reserved.
Designs