Thread: Max Subarray challenge

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    3

    Max Subarray challenge

    The solution to the Max Subarray challenge here: http://www.cprogramming.com/challenges/array_sum.html
    does not work for an input of all negative integers.

    For example
    Code:
    int y[] = {-9, -8, -7, -5, -1, -9};
    put through the function should return -1. But the solution code returns 0.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    No, -1 is correct if you don't allow 0 length sub arrays.

    edit: Bleh misread your post. So I guess the question is if it allows 0 length sub arrays. Which I guess the solution allows. I guess the question should specify if an empty set is a valid solution.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    3
    In the problem page http://www.cprogramming.com/challenges/array_sum.html
    the answer given is a 0 length sub array.

  4. #4
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Yes, the solution is wrong. And there is some inconsistencies in the question. But I'm not sure exactly who we should tell.
    I hate real numbers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Find max profit among input salary
    By hlam in forum C Programming
    Replies: 8
    Last Post: 11-16-2008, 10:30 AM
  2. Max Min Problem
    By smithc2005 in forum C Programming
    Replies: 7
    Last Post: 10-22-2008, 10:38 AM
  3. Overwriting all in array, why?
    By guesst in forum C Programming
    Replies: 7
    Last Post: 10-09-2008, 05:56 PM
  4. Ranged numbers
    By Desolation in forum Game Programming
    Replies: 8
    Last Post: 07-25-2006, 10:02 PM
  5. Game of life
    By JoshR in forum C++ Programming
    Replies: 30
    Last Post: 04-03-2005, 02:17 PM