Question: def is _ valid _ substring ( substring , s 2 ) : return substring in s 2 or substring [ :: - 1 ]
def isvalidsubstringsubstring s:
return substring in s or substring:: in s
def findsubstringss s:
substrings
i
j
while i lens:
found False
# Try to find the longest valid substring starting from i
for j in rangelens i:
substring si:j
if isvalidsubstringsubstring s:
substrings.appendsubstring
i j
found True
break
# If no valid substring is found, it's impossible
if not found:
return Impossible
return substrings
# Input
s inputstrip
s inputstrip
# Find and print the substrings
result findsubstringss s
printjoinresult
The time limit is exceeded it is showing when running the program
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
