49
2
Given a string s
, return the smallest contiguous substring you can remove to create a palindrome.
Examples:
800233008 -> 2
racecarFOOL -> FOOL
abcdedcba -> (empty string)
ngryL Myrgn -> "L " (or " M")
123456789 -> 12345678 (or 23456789)
aabcdbaa -> c (or d)
[[]] -> [[ (or ]])
a -> (empty string)
Test case suggestions from users (if you find an edge case not listed, please post a comment):
aabaab -> b | Suggested by Zgarb, some returned "aa".
Rules
- Only printable ASCII characters will appear in the input (no newlines, keep it simple).
- Not really a rule, but note
<>
,/\
,()
,[]
and{}
are not palindromes.
This is code-golf, smallest byte-count wins.
+100 bounty has been claimed by Adnan
3Tesf case:
aabaab
– Zgarb – 2017-11-06T17:46:17.43314I think it will help keep questions accessible to more visitors if ingroup jargon like “CMC” is avoided (looking it up, it appears to stand for “chat mini challenge”, which I imagine means a small challenge posted in the chat room associated with this site). – ShreevatsaR – 2017-11-06T20:43:31.353
Isn't
[[]]
a palindrome? – Carl – 2017-11-07T01:46:27.5134@Carl It may look like one, but when you reverse the characters, you get
]][[
. Consider thataabb
is the same thing, just different characters. – Conor O'Brien – 2017-11-07T03:25:38.253@ConorO'Brien oooh, yes :) – Carl – 2017-11-07T03:28:12.570
@ShreevatsaR fixed. – Magic Octopus Urn – 2017-11-07T14:35:33.633
What about
qrabbapo
? Then you need to remove from two sides,gr
andpo
to obtainabba
, or it would be considered as removingqrabbap
orrabbapo
? – Java Gonzar – 2017-11-08T17:05:54.607@JavaGonzalezArribas the answer would be
qrabbap
orrabbapo
, you must remove a *single, contiguous substring*. – Magic Octopus Urn – 2017-11-08T17:48:27.5307/12? if that is 2017-12-07, what kind of locale are you using? If that is 2018-07-12, that is a long way off... – NH. – 2017-11-08T18:44:18.710
@NH 7/12 is dec 7 in many european countries. Mine for instance – edc65 – 2017-11-10T07:59:23.980
1"(will be awarded 7/12)" huh? – Erik the Outgolfer – 2017-11-10T09:12:12.843
see? I'm not the only one confused. You didn't specify a locale, so please use a less ambiguous date (like the ISO 8601 version: 2017-12-07) – NH. – 2017-11-10T15:39:28.273
@EriktheOutgolfer HE MUST GO BACK IN TIME TO CLAIM THIS REWARD. Kidding, no idea what the heck I did there. – Magic Octopus Urn – 2017-11-10T15:56:24.433
@NH. No, it's not that. 7/12 can either mean December 7 or July 12, both of which can't be applicable in any case. ;) – Erik the Outgolfer – 2017-11-10T16:03:54.750