Skip to content

Instantly share code, notes, and snippets.

@flymio
Created January 3, 2019 18:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flymio/9dbfda905f197c36e7053e99b69e512c to your computer and use it in GitHub Desktop.
Save flymio/9dbfda905f197c36e7053e99b69e512c to your computer and use it in GitHub Desktop.
<?php
// Complete the sockMerchant function below.
function sockMerchant($n, $ar) {
$arnew = array();
$cnt=0;
foreach($ar as $val){
if (isset($arnew[$val])){
$cnt++;
unset($arnew[$val]);
}
else{
$arnew[$val]=1;
}
}
return $cnt;
}
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%d\n", $n);
fscanf($stdin, "%[^\n]", $ar_temp);
$ar = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY));
$result = sockMerchant($n, $ar);
fwrite($fptr, $result . "\n");
fclose($stdin);
fclose($fptr);
@fordarnold
Copy link

How??? does this work? It passes all tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment