python - Palindromic substrings -


given 2 strings a , b , each consisting of lower case alphabets, possible choose non empty strings s1 , s2 s1 substring of a, s2 substring of b such s1 + s2 palindromic string. here '+' denotes concatenation between strings.

for example:

case 1:  a='abc' b='abc' 

solution 1 possible way of choosing s1 & s2 s1 = "ab", s2 = "a" such s1 + s2 i.e "aba" palindrome.

case 2: a='a' b='b' 

solution:there no possible way choose s1 & s2 such s1 + s2 palindrome.

note: if possible , print 'yes' else print 'no' algorithm finding palindromic substring between 2 strings ?

it necessary (and sufficient) 2 strings have 1 letter in common.

def test(a, b):     return not set(a).isdisjoint(set(b)) 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -