From 339bd395e0044c9729084e21cc44bf565df044e4 Mon Sep 17 00:00:00 2001 From: Drew Date: Fri, 30 Jun 2017 14:54:02 -0700 Subject: [PATCH 1/2] Uploaded Solution to Booj codetest --- EquilibriumIndex.php | 46 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/EquilibriumIndex.php b/EquilibriumIndex.php index 020dd2b..c98f309 100644 --- a/EquilibriumIndex.php +++ b/EquilibriumIndex.php @@ -1,9 +1,45 @@ $v){ + # Remove the current element from the right sum + $sum_r -= $v; + # Check if left sum equals right sum and update output array + if($sum_l === $sum_r){ + $output[] = $k; + } + # Add the current element to the left sum + $sum_l += $v; + } + return $output; } - From 8d578774863699a92e615feb9b67ecf94ff4f33a Mon Sep 17 00:00:00 2001 From: Drew Date: Sat, 1 Jul 2017 20:27:56 -0700 Subject: [PATCH 2/2] Missing */ added to first comment --- EquilibriumIndex.php | 1 + 1 file changed, 1 insertion(+) diff --git a/EquilibriumIndex.php b/EquilibriumIndex.php index c98f309..4cbf38b 100644 --- a/EquilibriumIndex.php +++ b/EquilibriumIndex.php @@ -14,6 +14,7 @@ * work without throwing any errors as long as an array is given * with numeric or numeric convetable (e.g. true, null, '0', etc.) * values. + */ /** * Finds and returns the equilibrium indices of the provided array.