You are viewing a single comment's thread. Return to all comments →
Here is my solution in PHP
s); arr); arr); res);
`$resCount = count($`res); $result = -1; if($resCount == 1) { $result = -1; } else if(`$resCount == $`arrSum) { $result = -1; } else if(`$arr == $`arrRev) { $result = -1; } else { $equal = 'yes'; $oddPair = ''; $min = 0; foreach (`$res as $`key => $value) { if($value%2 !==0) { $equal = 'no'; `$oddPair = $`key; if(`$value <$`min) { `$min = $`value; `$oddPair = $`key; } } } `$len = count($`arr); if ($equal == 'no') { $findIndex = ''; for (`$i=0; $`i < `$len ; $`i++) { if(`$arr[$`i] == $oddPair) { `$string = implode('', $`arr); `$part1 = substr($`string, 0,$i); `$part2 = substr($`string,`$i+1,$`len-1); `$str1 = $`part1.$part2; `$str2 = strrev($`str1); if(`$str1 === $`str2) { `$findIndex =$`i; break; } } } `$result = $`findIndex; } } return $result;
Seems like cookies are disabled on this browser, please enable them to open this website
Palindrome Index
You are viewing a single comment's thread. Return to all comments →
Here is my solution in PHP
s); arr); arr); res);