Skip to content

Instantly share code, notes, and snippets.

View barakpinchovski's full-sized avatar

barakpinchovski

View GitHub Profile
<?php
echo minimumSwaps($arr);
function minimumSwaps($arr) {
$swaps = 0; # Default function value
if (gettype($arr) !== 'array' || !count($arr)) {
return $swaps;
}
<?php
$q = [2,1,5,3,4];
minimumBribes($q);
function minimumBribes($q) {
$no_ans = 'Too chaotic';
$ans = 0;
<?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 [];
<?php
$s = 'kmretasscityylpdhuwjirnqimlkcgxubxmsxpypgzxtenweirknjtasxtvxemtwxuarabssvqdnktqadhyktagjxoanknhgilnm';
$n = 736778906400;
echo repeatedString($s, $n);
function repeatedString($s, $n) {
Define('CHAR', 'a');
<?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) {
<?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))
<?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: