Skip to content

Instantly share code, notes, and snippets.

View gpfiel's full-sized avatar

Gabriel Pinheiro Fiel gpfiel

View GitHub Profile
<?php
function solution($X, $A) {
foreach ($A as $key => $value) {
$part1 = array_slice($A, 0, $key);
$part2 = array_slice($A, $key, count($A) - 1);
$arrayPart1Indexes = array();
$arrayPart2Indexes = array();
foreach ($part1 as $part1key => $part1Value) {
<?php
function test($v, $arr1) {
$arr2 = [];
while(1){
$count1 = isset(array_count_values($arr1)[$v]) ? array_count_values($arr1)[$v] : 0;
$count2 = isset(array_count_values($arr2)[$v]) ? array_count_values($arr2)[$v] : 0;
if(count($arr1) == 0 || $count1 == count($arr2) - $count2) {
return count($arr1);
}
$arr2[] = array_shift($arr1);
@gpfiel
gpfiel / Question1Toptal.php
Created April 20, 2016 20:50
Question1Toptal
<?php
function solution($K, $L, $M, $N, $P, $Q, $R, $S) {
//get inputs to check intersection
$leftSide = max($K, $P);
$rightSide = min($M, $R);
$bottomSide = max($L, $Q);
$topSide = min($N, $S);
//the area of the sum of the rectangles
$sum = (($M - $K) * ($N - $L)) + (($R - $P) * ($S - $Q));
@gpfiel
gpfiel / Question3Toptal.php
Created April 20, 2016 21:05
Question3Toptal
<?php
function solution($A)
{
$sum = 0;
while (count($A)) {
// remove the last part
array_pop($A);
@gpfiel
gpfiel / miamed.php
Created May 18, 2017 15:57
Miamed Refactor
<?php
namespace Com\Company\System;
use \Com\Company\Interfaces;
class VerifyHelper
{
/**