Skip to content

Instantly share code, notes, and snippets.

@asadali3210 asadali3210/test2.php Secret
Created May 31, 2017

Embed
What would you like to do?
function getSameSequence($arr){
$output = array();
// get size
$size = 0;
foreach($arr as $char){
$size++;
}
$rightLimit = $size/2;
$leftLimit = $rightLimit-1;
if ( $size%2 != 0 ){
$rightLimit++;
}
for ( ; $leftLimit >= 0; $leftLimit--, $rightLimit++){
$match = compareArrays($arr, $leftLimit, $rightLimit);
if ( $match){
break;
}
}
//output
for($count=0; $count <= $leftLimit; $count++){
$output[] = $arr[$count];
}
return $output;
}
function compareArrays($arr, $leftLimit, $rightLimit){
$matched = true;
for($count=0; $count <= $leftLimit; $count++){
if ( $arr[$count] == $arr[$rightLimit+$count] ){
$output[]=$arr[$count];
}
else {
$matched = true;
break;
}
}
return $matched;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.