Skip to content

Instantly share code, notes, and snippets.

@clintonmedbery
Last active April 2, 2018 02:56
Show Gist options
  • Save clintonmedbery/ca9ef85d2532b7ce14f6ebbabe2b0941 to your computer and use it in GitHub Desktop.
Save clintonmedbery/ca9ef85d2532b7ce14f6ebbabe2b0941 to your computer and use it in GitHub Desktop.
PHP Learning
//https://www.hackerrank.com/challenges/birthday-cake-candles/problem
function birthdayCakeCandles($n, $ar) {
/*
* Write your code here.
*/
//Splice the array into the size we need
array_splice($ar, $n);
//Get the Max value
$maxValue = max($ar);
//Get the max count of all values
// $maxCountArray = array_count_values($ar);
//Get count of the max value
// $maxCount = $maxCountArray[$maxValue];
// return $maxCount;
//Shorten it up
return array_count_values($ar)[$maxValue];
}
https://www.hackerrank.com/challenges/ctci-making-anagrams/problem
function anagramDifference($string1, $string2){
$array1 = str_split($string1);
$array2 = str_split($string2);
foreach($array1 as $key1=>$value1){
foreach($array2 as $key2=>$value2){
if($value1 == $value2){
unset($array1[$key1]);
unset($array2[$key2]);
break;
}
}
}
$arrayCount = count($array1) + count($array2);
print_r($arrayCount);
}
anagramDifference($a, $b);
https://www.hackerrank.com/challenges/mini-max-sum/problem
function miniMaxSum($arr) {
sort($arr);
$highToLow = array_reverse($arr);
$lowestSum = arraySumToCount(4, $arr);
$highestSum = arraySumToCount(4, $highToLow);
echo "$lowestSum $highestSum";
}
function arraySumToCount($numToSum, $array) {
return array_sum(array_slice($array, 0, $numToSum));
}
https://www.hackerrank.com/challenges/staircase
function staircase($n) {
foreach(range(1, $n) as $index){
$whiteSpace = str_repeat(" ", $n - $index);
$stairs = str_repeat("#", $index);
echo "$whiteSpace$stairs\r\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment