Company: Mathworks_31july
Difficulty: medium
Sub-Palindrome Problem Description A palindrome is a string that reads the same forwards and backwards, such as 121 or tacocat. A substring is a continuous sequence of characters within a string. Given a string s , how many unique substrings of s are palindromes? Complete the function palindrome in the editor below. The function palindrome has the following parameter(s): string s : a string Returns: int : the number of distinct palindromes Examples Example 1: Input: s = "mokkori" Explanation: Some of its substrings are [m, o, k, r, i, mo, ok, mok, okk, kk, okkoi. There are 7 distinct palindromes [m, o, k, r, i, kk, okko]. Example 2: Input: s = "aabaa" Output: 5 Explanation: Palindromic substrings are ['a', 'aa', 'aabaa', 'aba', 'b']. The substring 'a' occurs 4 times, but is counted only once. Similarly, the substring 'aa' occurs twice but counts as one distinct palindrome. The number of distinct palindromes is 5. Example 3: Input: s = "abcdcdcbabcdcdcbabcdcdcb" Output: 27 Explanation: