<jupyter_start><jupyter_text>Longest Palindromic Substring[The Original Question](https://mp.weixin.qq.com/s/LP6Q8LD1R4WMHqXxZSwABg)  QuestionA palindrome is a sequence of characters that reads the same backwards and forwards.Given a string, s, find the longest palindromic substring in s.  Example```Input: "banana"Output: "anana"Input: "million"Output: "illi"```<jupyter_code>def longestPal(string: str) -> str:
    
    # The whole string is a palindrome.
    if (len(string) < 2) or (string == string[::-1]):
        return string
    
    n = len(string)
    
    # Define the start index and max length of palindrome.
    (start, maxlen) = (0, 1)
    
    # Start from 1 directly,
    # because (i = 0) have no posibilities larger than maxlen. 
    for i in range(1, n):
        
        # Slice i and (maxlen + 2) characters before i.
        # len(odd) = maxlen + 2
        odd = string[i - maxlen - 1:i + 1]
        
        # Slice i and (maxlen + 1) characters before i.
        # len(even) = maxlen + 1
        even = string[i - maxlen:i + 1]
        
        # Check if there exists a palindromic string.
        if i - maxlen - 1 >= 0 and odd == odd[::-1]:
            start = i - maxlen - 1
            maxlen += 2
            continue
            pass
        if i - maxlen >= 0 and even == even[::-1]:
            start = i - maxlen
            maxlen += 1
            pass
        pass
    return string[start:start + maxlen]


if __name__ == '__main__':
    print(longestPal('banana'))
    print(longestPal('million'))
    pass<jupyter_output>anana
illi
{'fraction_non_alphanumeric': 0.11195928753180662, 'fraction_numerical': 0.01653944020356234, 'mean_word_length': 2.108695652173913, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '52619', 'license': 'MIT', 'n_tokens_mistral': 539, 'n_tokens_neox': 511, 'n_words': 162, 'path': 'January/Week1/3.ipynb', 'repo_name': 'Dragon1573/Daily-Problem', 'size': '1572'}