-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalindrome Index.php
58 lines (43 loc) · 9.39 KB
/
Palindrome Index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* @author: syed ashraf ullah
* date: 30/04/2020
* problem: https://www.hackerrank.com/challenges/palindrome-index/problem
*
*/
/// Todo: Not passed 100% test case. Will solve it later.
// Complete the palindromeIndex function below.
function palindromeIndex($s) {
$s = str_split($s);
// $isPossible = isPalindromeString($s);
// if (!$isPossible) return -1;
$size = sizeof($s);
for ($i=0, $j=$size-1; $i < $size/2; $i++,$j--) {
if ($s[$i] != $s[$j]) {
if ($s[$i+1] == $s[$i]) {
return $j;
}
return $i;
}
}
return -1;
}
/**
* Sample #1
*/
// $s = 'aaab';
$s = 'ijfyrvmkioryptjxuykvvmaeplcbgihprpqknewvuoukiejeetcciegxpkbvtlnnbhxqlwminjuwogdubhyllimdspbmbpdeydukbjuotpniwsfacelpmasiqwwtoaynevafguvakkkjfpjivxxjxttoqqlfrksvgudopyoclymrqxanvxyurslkjwpdjkysfchwewapxohrmjflkgieyvpkthofspxxuixyhxofoyydkeoukwaltrypynwrfxsagqynqqufruicyaxmyaauryksokluiguowwcppwwhthjthjihlicfkpyyamvisryrqbhgaepulbqvlbfylhfvygxbutlnnkhgnqmowclkeegrflssvarwgpyblmqaxxilqvcnapygthabvtuttmqdergpfxrfxbsryxfbngkkqmnmgkidybidvovdopipqdjrbovpxgcospdcblhcopgkgenxtvpnayfdndunjwefphhsuoukgdumhlmejcrlbyprdkfmkktatburrrcxvynfkcjufbggdvagjgutspvosqglkklgkbmuexrjayrdwslibgcvxakrstdeeqkosymwxegafaffuqnvystxsfpmbuqfldwedjbdpjdxmidhbsealxxhfptimmoyplfswhxmsbmflrnmltnytngceakqmbrfmxajhyyaalimexyrroqndxpjadcpeuuruudcveewsolwmmqgehuhhmsipwxutuoortsoyxnrmbqcnhitqfbysvhithdnetfvoxmnxahnbxprhalxgpwynghhpnxthdsvbflcgspjqfdafryljxkwhuhwihtrkmqnrcpavhmomrpujqguotsxqcvyjrsvejlxmebklnybhqvrjeoyxhyolupwolssuhtjlwvymxatovnybdabmysywkvlvrhtydfmaclmamgokuplxrpkrilqukcrclndospqubdupmmbheohwetqoihksleuxrxokpgisjdjvrmfwbotilkwttjofplfhluubbdtmidldpsatkvcvibrclijbtplfkignnccxinbajdttyxrjalnntxqnpesambpadrylicmrgglhffthqhukflxuqswftogwjhjrlxlteyclevsudpflefiwxictwkqitcagclajkeuqcqligstmxejxoormyluvpxeslecylypnpevywrnxwxvloqapexltxpolwqkisdxkhulgmaeladaotcexcstcijohcyrucqilntsctyovcqkxurxamscweqfiswgwpojdiegfdwbgpogkifkuanregwoywuwojgsumbapxdxntfacmlwmbrsjohjndgdooxjbylswrrmlymonancbfunwewmjfpytpkwoyrlqlacknsanhcrowfnecbnjsofjccxbvmtimvsartqbxkpvpecthpdahijlmioiwisjgmmxifbgptefagbhyghiqrtfcinbsjmyvyaggbovuvdueeefmmndgjiktylmiaogcqoitffrbkogptneicionsbirowconiqgwabfhsgrhojbdojhyaurdfkrfojuxacwcdcjxlcfanjfcumbxkvbrgtywduufyuieytckxhnmssqoiumuqnmyjmvojtuiofmnyqbxxoktjdirxwmomcnyqmnagkkupykrplppccjmftgeqtugvlfoxuoegbbxalppahfelrqrlxxftslrgqgelwitxluxxkpauwegoxadxairvtjcmrhaorwmermeecgybmiqkkvinecjannofwovrnixfwckyklbwvtkhpuwvxgvnvmttdrnrblwanjaavdwryjbqfxmfgksdwoyahmrixrinbknwpmrowsfettjaeefbtgebsvlspvirjvqyliqkexoxsaaweibaofbkdmftjolumctxnmkrlbrebtdiceitlmepyjjkaufnycnmoygcaaieumoysysflwwnjgajdiyeknrbmaeobmsxbjwujqcwpykbhnnkvmoiaijolpgofymglldwehtuihxpulcqytbbemspdyekasqlfwijefgnmffhsiarcbvinqyspfdrbwegtoratbniivpbervisrqjkrcaxiryfxhbpbblerumnmotfkeaewjopoqpykqglahbdkmiejurwjncvrcapoqhdjweupkgprjsevdjgydfkrhhlljbcdkhmjlhyvpqpymuxpggojlcbujnisqlvcsllfunbletmqqmjwsaggckblamhqxfuqqhxouccbvoumcelwgrejehwetgvtmsnfaltwnvblnvapcloigsrkbrpwxnrkgfsjqoihnjubfvshjhsrdkdecubbkunsaietxnblyxohvjogsjavufcyagcmbsgcbmxbaymaydhvmxegkeehkhgmnlaoeishuqjxrxarcjnqjtytaebklkayvcpcmjljcuhuvjmxscqfvqyvwdjinljlnypakbjnwtiudwswblcwcduyggjtruhhuwhhytwxnhsqenpfyteeacfgkrddmkkjkutjqqjeycwdrplslpwltfufwxklkuvwrpgigpohtmlleyfpqecllwqiwbwjxshskpbsgsbchoqlnvbecfpociybjvlkqudbkguqyvvgkmrakvembwdgfdjpywcqrftdlovnmrvyeqyqmeepbhximiaofcfahydvqylfthfaxermkvfnfdwunwjvcqvlryhiauotdvudcoqpmxdrbcorcxngolrhmcrmwgjcegghuywhwcbafqrjqhpgshnflhujoelumtchuyqrcrujkmscwkiptxvgfsrvwdrlatsuvlpxdkhoycsvobokbmqifkheoypquklsvdqbnarpeknsnegoqwavihcyitpfedychrewsvoyjduwhbobxoyivcjgvbldhkfoflnakdytitqrufsvtsgrusxstmxdwgteriecnexvxpnvwhrtaxlwqmrnyqqxwndqvhtjnthojukhecdgcqftdxjeqcfnpiglrcwiwgwgehpijsrlmwhpuqwnvcblmiagkyojglqksiseemsqkaihthvpjydxjdfwdtgjgwtbiogmcyfobnvwvrohrsgdvlabhhkpggroxadcbiqeyocwjqedjmgiahjiowaudrkdtnfuyxcxpeuyubchoirorbygxacetojoerldpndftagrciystqjltjuulwyhnivtckasadaughmkrndngoaaauultvtjhrdjedehjfcroqcigfwmtyoutkipieypwecdkgkvnmnefpnnwkcslrpfeywmdxdccfgmnqkcgxgnpvcmgegrxvycwxpdvuhycnnphytpybdpyhcgokamjcpiahlwctxgjnvsmsiovoeuvidmvecfitpkbejfajljxjdmclbxcftyqwnmdptnjlympkrpudasnffpshqvokwfhmtndnboaacrltigxkynrgfknvidihksufgxuhowkqpvlaelkfbeliqafafpjpiewoeuyttjklhxlllxqmcevtedvlufeemduqxvmsfxemxsakssyxxureapqvuwcjaybyvntdnasousyooammvgsxvlvsixdlagmvviykirygnaueajqxplynauikvnvvtitqqsdcneidefhgoafgnetnbeywsusogmhyikbxqlduqmcfmjnaphqqopojmjxsyiujuvhmimhbylhnwupmfgevvsflefgdnbmjxvviifjjtswqqnevtitsdyeheknumcemycujhgtbasusgyqdjkxojcvpolmdospnumyfvuixodqwehcnracdebuvmiydbrsygsgepocguueycinvlrypswlihnlihfjpapuphwwcsdbwlotwhupcrdkyswkaevqeolvvksxfxydkqyjavbcqhpraocbsbrypfulpqjxokdbbcnbxogovvhwklafoteeyyrqrdqhotirxxvwpcnlawkklmpagvhhwbbpfrwvmhpkiljxpalpywckltnspwcpxdffvebknrwvfjtvlgnkfsxqmnlfkowkrcqpitcxlcwtlqpyyfjgxjanwlujcruwvnmghrevtbphuhgvmrdnefbdqxnvpksnahthyafucucyekurfahjfkmyicuaonnoujywjerncwmgjiaokhaqtppcrkehatvudwtpcmdelsmubnmnwmerevtwgbgiuegbcaqeovkaowxrkmgibmagjvdrwjbuppubjwrdvjgambigmkrxwoakvoeqacbgeuigbgwtveremwnmnbumsledmcptwduvtahekrcpptqahkoaijgmwcnrejwyjuonnoauciymkfjhafrukeycucufayhthanskpvnxqdbfendrmvghuhpbtverhgmnvwurcjulwnajxgjfyypqltwclxctipqcrkwokflnmqxsfknglvtjfvwrnkbevffdxpcwpsntlkcwyplapxjlikphmvwrfpbbwhhvgapmlkkwalncpwvxxritohqdrqryyeetofalkwhvvogoxbncbbdkoxjqplufpyrbsbcoarphqcbvajyqkdyxfxskvvloeqveakwsykdrcpuhwtolwbdscwwhpupapjfhilnhilwspyrlvnicyeuugcopegsgysrbdyimvubedcarnchewqdoxiuvfymunpsodmlopvcjoxkjdqygsusabtghjucymecmunkeheydstitvenqqwstjjfiivvxjmbndgfelfsvvegfmpuwnhlybhmimhvujuiysxjmjopoqqhpanjmfcmqudlqxbkiyhmgosuswyebntengfaoghfediencdsqqtitvvnvkiuanylpxqjaeuangyrikyivvmgaldxisvlvxsgvmmaooysuosandtnvybyajcwuvqpaeruxxysskasxmexfsmvxqudmeefulvdetvecmqxlllxhlkjttyueoweipjpfafaqilebfklealvpqkwohuxgfuskhidivnkfgrnykxgitlrcaaobndntmhfwkovqhspffnsaduprkpmyljntpdmnwqytfcxblcmdjxjljafjebkptifcevmdivueovoismsvnjgxtcwlhaipcjmakogchypdbyptyhpnncyhuvdpxwcyvxrgegmcvpngxgckqnmgfccdxdmwyefprlsckwnnpfenmnvkgkdcewpyeipiktuoytmwfgicqorcfjhedejdrhjtvtluuaaaogndnrkmhguadasakctvinhywluujtljqtsyicrgatfdnpdlreojotecaxgybroriohcbuyuepxcxyufntdkrduawoijhaigmjdeqjwcoyeqibcdaxorggpkhhbalvdgsrhorvwvnbofycmgoibtwgjgtdwfdjxdyjpvhthiakqsmeesiskqlgjoykgaimlbcvnwquphwmlrsjiphegwgwiwcrlgipnfcqejxdtfqcgdcehkujohtnjthvqdnwxqqynrmqwlxatrhwvnpxvxenceiretgwdxmtsxsurgstvsfurqtitydkanlfofkhdlbvgjcviyoxbobhwudjyovswerhcydefptiychivawqogensnkepranbqdvslkuqpyoehkfiqmbkobovscyohkdxplvustalrdwvrsfgvxtpikwcsmkjurcrqyuhctmuleojuhlfnhsgphqjrqfabcwhwyuhggecjgwmrcmhrlognxcrocbrdxmpqocduvdtouaihyrlvqcvjwnuwdfnfvkmrexafhtflyqvdyhafcfoaimixhbpeemqyqeyvrmnvoldtfrqcwypjdfgdwbmevkarmkgvvyqugkbduqklvjbyicopfcebvnlqohcbsgsbpkshsxjwbwiqwllceqpfyellmthopgigprwvuklkxwfuftlwplslprdwcyejqqjtukjkkmddrkgfcaeetyfpneqshnxwtyhhwuhhurtjggyudcwclbwswduitwnjbkapynljlnijdwvyqvfqcsxmjvuhucjljmcpcvyaklkbeatytjqnjcraxrxjquhsieoalnmghkheekgexmvhdyamyabxmbcgsbmcgaycfuvajsgojvhoxylbnxteiasnukbbucedkdrshjhsvfbujnhioqjsfgkrnxwprbkrsgiolcpavnlbvnwtlafnsmtvgtewhejergwlecmuovbccuoxhqqufxqhmalbkcggaswjmqqmtelbnufllscvlqsinjubcljoggpxumypqpvyhljmhkdcbjllhhrkfdygjdvesjrpgkpuewjdhqopacrvcnjwrujeimkdbhalgqkypqopojweaekftomnmurelbbpbhxfyrixacrkjqrsivrebpviinbtarotgewbrdfpsyqnivbcraishffmngfejiwflqsakeydpsmebbtyqclupxhiuthewdllgmyfogplojiaiomvknnhbkypwcqjuwjbxsmboeambrnkeyidjagjnwwlfsysyomueiaacgyomncynfuakjjypemltiecidtberblrkmnxtcmulojtfmdkbfoabiewaasxoxekqilyqvjrivpslvsbegtbfeeajttefswormpwnkbnirxirmhayowdskgfmxfqbjyrwdvaajnawlbrnrdttmvnvgxvwuphktvwblkykcwfxinrvowfonnajcenivkkqimbygceemremwroahrmcjtvriaxdaxogewuapkxxulxtiwlegqgrlstfxxlrqrlefhapplaxbbgeouxoflvgutqegtfmjccpplprkypukkganmqyncmomwxridjtkoxxbqynmfoiutjovmjymnqumuioqssmnhxkctyeiuyfuudwytgrbvkxbmucfjnafclxjcdcwcaxujofrkfdruayhjodbjohrgshfbawgqinocworibsnoicientpgokbrfftioqcgoaimlytkijgdnmmfeeeudvuvobggayvymjsbnicftrqihgyhbgafetpgbfixmmgjsiwioimljihadphtcepvpkxbqtrasvmitmvbxccjfosjnbcenfworchnasnkcalqlryowkptypfjmwewnufbcnanomylmrrwslybjxoodgdnjhojsrbmwlmcaftnxdxpabmusgjowuwyowgernaukfikgopgbwdfgeidjopwgwsifqewcsmaxruxkqcvoytcstnliqcurychojictscxectoadaleamgluhkxdsikqwlopxtlxepaqolvxwxnrwyvepnpylycelsexpvulymrooxjexmtsgilqcquekjalcgactiqkwtcixwifelfpdusvelcyetlxlrjhjwgotfwsquxlfkuhqhtffhlggrmcilyrdapbmasepnqxtnnlajrxyttdjabnixccnngikflptbjilcrbivcvktaspdldimtdbbuulhflpfojttwklitobwfmrvjdjsigpkoxrxuelskhioqtewhoehbmmpudbuqpsodnlcrckuqlirkprxlpukogmamlcamfdythrvlvkwysymbadbynvotaxmyvwljthusslowpuloyhxyoejrvqhbynlkbemxljevsrjyvcqxstougqjuprmomhvapcrnqmkrthiwhuhwkxjlyrfadfqjpsgclfbvsdhtxnphhgnywpgxlahrpxbnhaxnmxovftendhtihvsybfqtihncqbmrnxyostrooutuxwpismhhuhegqmmwlosweevcduuruuepcdajpxdnqorryxemilaayyhjaxmfrbmqkaecgntyntlmnrlfmbsmxhwsflpyommitpfhxxlaesbhdimxdjpdbjdewdlfqubmpfsxtsyvnquffafagexwmysokqeedtsrkaxvcgbilswdryajrxeumbkglkklgqsovpstugjgavdggbfujckfnyvxcrrrubtatkkmfkdrpyblrcjemlhmudgkuoushhpfewjnudndfyanpvtxnegkgpochlbcdpsocgxpvobrjdqpipodvovdibydikgmnmqkkgnbfxyrsbxfrxfpgredqmttutvbahtgypancvqlixxaqmlbypgwravsslfrgeeklcwomqnghknnltubxgyvfhlyfblvqblupeaghbqryrsivmayypkfcilhijhtjhthwwppcwwougiulkoskyruaaymxayciurfuqqnyqgasxfrwnypyrtlawkuoekdyyofoxhyxiuxxpsfohtkpvyeigklfjmrhoxpawewhcfsykjdpwjklsruyxvnaxqrmylcoypodugvskrflqqottxjxxvijpfjkkkavugfavenyaotwwqisamplecafswinptoujbkudyedpbmbpsdmillyhbudgowujnimwlqxhbnnltvbkpxgeiccteejeikuouvwenkqprphigbclpeamvvkyuxjtpyroikmvryfji';
$result = palindromeIndex($s);
echo $result;
return;
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%d\n", $q);
for ($q_itr = 0; $q_itr < $q; $q_itr++) {
$s = '';
fscanf($stdin, "%[^\n]", $s);
$result = palindromeIndex($s);
fwrite($fptr, $result . "\n");
}
fclose($stdin);
fclose($fptr);