This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo minimumSwaps($arr); | |
function minimumSwaps($arr) { | |
$swaps = 0; # Default function value | |
if (gettype($arr) !== 'array' || !count($arr)) { | |
return $swaps; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$q = [2,1,5,3,4]; | |
minimumBribes($q); | |
function minimumBribes($q) { | |
$no_ans = 'Too chaotic'; | |
$ans = 0; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arr = [1,2,3,4,5]; | |
$d = 4; | |
var_dump(rotLeft($arr, $d)); | |
function rotLeft($a, $d) { | |
if (gettype($a) !== 'array' || !count($a)) { | |
return []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$s = 'kmretasscityylpdhuwjirnqimlkcgxubxmsxpypgzxtenweirknjtasxtvxemtwxuarabssvqdnktqadhyktagjxoanknhgilnm'; | |
$n = 736778906400; | |
echo repeatedString($s, $n); | |
function repeatedString($s, $n) { | |
Define('CHAR', 'a'); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$exampleClouds = [0,0,1,0,0,1,0]; | |
echo jumpingOnClouds($exampleClouds); | |
// Assumptions for jumpingOnClouds function: | |
// 1. Length: 2 <= count($c) <= 100 | |
// 2. Items: $c[$i] === 0 || $c[$i] === 1 | |
// 3. End-values: $c[0] === $c[ count($c) - 1 ] === 0 | |
function jumpingOnClouds($c) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$examplePath = 'DDUUUUDD'; | |
$len = strlen($examplePath); | |
echo countingValleys($len, $examplePath); | |
// Assumptions for countingValleys function: | |
// 1. $n: | |
// 1.a. Represents the number of steps that were taken | |
// 1.b. Is the actual length of $s (derived from strlen($s)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$exampleArray = [9, 10 , 20 , 20 ,10 ,10 ,30 ,50 ,10 ,20]; | |
$len = count($exampleArray); | |
echo sockMerchant($len, $exampleArray); | |
// Assumptions for sockMerchant function: | |
// 1. $n is the actual size of $ar (derived from count($ar)) | |
// 2. $ar values are: |