Question: python t = Using slicing. Implement the function longest PalSubsA(s), which given a string s, returns a palindromic substring of s of maximal length. You
python
t = Using slicing. Implement the function longest PalSubsA(s), which given a string s, returns a palindromic substring of s of maximal length. You are asked to do this part using slicing (Problem 3 in Programming Assignment 3): to check if the substring s[i:j+1] is palindromic (recall that s[i: j +1] is the substring "s[i]s[i+1]...s[j]"), let s[i:j+1] and check if t = t[:: 1]. (Hint: Use variables start and end to keep track of the start and end of longest palindromic substring found so far. Loop over i = 0,...,n and j = i,..., n and, depnding on s[i : j +1], update start and end if needed. Appropriately initialize start and end.) Test script: Output: == print(longestPalSubsA ("aceexcivicgrfdds")) print(longestPalSubs A ("civicgrfdds")) print(longestPalSubsA ("aceexcivic")) print(longestPalSubsA ("civic")) print(longestPalSubsA ("123abba1")) print(longestPalSubs A ("abba1")) print(longestPalSubsA ("123abba")) print(longestPalSubsA ("12345")) print(longestPalSubsA("")) civic civic civic civic abba abba abba #1,2,3, 4, or 5 are all #empty line valid outputs
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
