Solution to Max-Slice-Sum by codility

26 Jan


Question Name: MaxSliceSum

The classic maximum subarray problem. It should be the very first question in this lesson.

14 Replies to “Solution to Max-Slice-Sum by codility

  1. Here is my solution, somewhat similar 🙂 Python 100/100

    • In the lesson, the slice could be empty, whose sum is zero. Therefore the maximum slice sum would zeor or more.

      In the execise, the slice could NOT be empty. And the maximum slice sum might be negative.

      • I don’t think the key difference is whether the array can be empty. I think algorithm in the lessson is fundamentally wrong. Because it initialises both max_ending and max_slice to be 0, hence the algorithm in the lesson won’t work for a single negative array e.g. A = [-10]. What’s funy is in the lesson it did mention the array elements can be negative.

        I am really surprised that as of today (Nov 2016) Codility hasn’t really fixed this, probably because nobody bothers reporting it.

        • I believe the lesson is correct. When A = [-10], the result is 0, as the maximum slice is an empty slice [].

          As I said, in the lesson, empty slice is permitted, while it’s not in the practice.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!