3v4l.org

run code in 300+ PHP versions simultaneously
<?php function findMaxCrossingSubarray(&$A, $low, $mid, $high){ $leftSum = -PHP_INT_MAX; $sum = 0; for($i = $mid; $i >= 0; $i--) { $sum = $sum + $A[$i]; if ($sum > $leftSum) { $leftSum = $sum; $maxLeft = $i; } } $rightSum = -PHP_INT_MAX; $sum = 0; for($j = $mid + 1; $j <= $high; $j++) { $sum = $sum + $A[$j]; if ($sum > $rightSum) { $rightSum = $sum; $maxRight = $j; } } return [ $maxLeft, $maxRight, $leftSum + $rightSum, ]; } function findMaximumSubarray(&$A, $low, $high) { if ($low === $high) { return [ $low, $high, $A[$low], ]; } else { $mid = floor(($low + $high) / 2); list($leftLow, $leftHigh, $leftSum) = findMaximumSubarray($A, $low, $mid); list($rightLow, $rightHigh, $rightSum) = findMaximumSubarray($A, $mid + 1, $high); list($crossLow, $crossHigh, $crossSum) = findMaxCrossingSubarray($A, $low, $mid, $high); if ($leftSum >= $rightSum && $leftSum >= $crossSum) { return [ $leftLow, $leftHigh, $leftSum, ]; } else if ($rightSum >= $leftSum && $rightSum >= $crossSum) { return [ $rightLow, $rightHigh, $rightSum, ]; } else { return [ $crossLow, $crossHigh, $crossSum, ]; } } } $A = [13,-3,-25,20,-3,-16,-23,18,20,-7,12,-5,-22,15,-4,7]; print_r(findMaximumSubarray($A, 0, 15));
Output for git.master_jit
Fatal error: Out of memory (allocated 18874368 bytes) (tried to allocate 262144 bytes) in /in/A3dLe on line 40 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for git.master, rfc.property-hooks
Fatal error: Out of memory (allocated 35651584 bytes) (tried to allocate 262144 bytes) in /in/A3dLe on line 40 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
143.15 ms | 407 KiB | 5 Q