From 0047d6259d5364a774ed8674fc93989174479ab6 Mon Sep 17 00:00:00 2001 From: Kavinda Lakmal Bandara Date: Sun, 17 Mar 2019 12:09:51 +0530 Subject: [PATCH 1/2] Upgrade code of cyclicRotation --- cyclicRotation.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cyclicRotation.php b/cyclicRotation.php index 698a160..4f81c74 100644 --- a/cyclicRotation.php +++ b/cyclicRotation.php @@ -1,17 +1,17 @@ $v){ - if($k+$timesToRotate $v) { + if (($i+$K) < $arrayLenth) { + $index = $i+$K; + } else { + $index = ($i+$K)%$arrayLenth; + } + $resultArray[$index] = $v; + } + + return $resultArray; } \ No newline at end of file From d7682659cd3359198d6bf2bffa4791abc48bb840 Mon Sep 17 00:00:00 2001 From: Kavinda Lakmal Bandara Date: Sun, 17 Mar 2019 21:23:15 +0530 Subject: [PATCH 2/2] Added solution 3 --- PermMissingElem.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/PermMissingElem.php b/PermMissingElem.php index 5d65f43..31a197a 100644 --- a/PermMissingElem.php +++ b/PermMissingElem.php @@ -2,8 +2,22 @@ echo solution([2,3,4,1]); function solution($A){ /* - * Solution 2: Correctness 100%; performance 100% + * Solution 3: Correctness 100%; performance 100% */ + $arrayCount = count($A); + $lastNumber = $arrayCount+1; + $firstNumber = 1; + + //Sum of given array + $sumA = array_sum($A); + // Sum of arithmetic series + $sumOfSeries = (($arrayCount+1)*($firstNumber + $lastNumber)) / 2; + + return (int)($sumOfSeries - $sumA); + + /* + * Solution 2: Correctness 100%; performance 100% + * sort($A); for($i=0;$i