rrubiorr81 rrubiorr81 - 1 year ago 86
PHP Question

Codility worng answer on TapeEquilibrium for php

I just coded a solution for the TapeEquilibrium problem in php. The thing is i`m getting some wrong answers for the automatic code revitions provided by Codility.
The link to the finished test is


Any idea whats the

two elements
wrong answer error?
Is it necessary to type (typecast) the variables in php for this test? i mean, how do u tell the compiler X variable is double or int in php? Thx a lot!

Answer Source

Two elements test case is probably {-1000, 1000}. This array can be splited only in one place and the distance is |-1000-1000| = 2000. Your program for this input returns 0, because in the second iteration of the for loop $arr_h is 0 and $sum_total is also 0.

Simply change condition in loop for ($i = $count_-1; $i > 0 ; $i--) to get 100%.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download