Web Projects Consulting

MaxSliceSum Demo Task at Codility.com

Excellent solutions for codility demo tasks

Codility.com Tests 100/100 Solutions

Lesson 7 – Maximum slice problem – MaxSliceSum demo task solution code written in php. Gives 100/100 score at the time of publishing.

The description of the problem is copyrighted, so please see the following link for it:  https://codility.com/demo/take-sample-test/max_slice_sum

Solution in php:

function solution($A) {
    $cnt = count($A);
    $max_ending_here = $A[0];
    $max_so_far = $A[0];
    for($i = 1; $i < $cnt; $i++){
        $max_ending_here = max($A[$i], $max_ending_here + $A[$i]);
        $max_so_far = max($max_so_far, $max_ending_here);
    }
    return $max_so_far;
}

Given “AS IS”, can be ported from other languages from solutions found on the internet, please use with care.

Please note: we think that codility.com does not give a correct assessment of your real-world programming skills. For instance, reading the below would bring more understanding why: http://x20x.co.uk/2014/02/why-i-refuse-to-use-codility-and-so-should-you/

Web Projects Consulting
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.