<p>Given a string <code>s</code>, return <em>the longest</em> <span data-keyword="palindromic-string"><em>palindromic</em></span> <span data-keyword="substring-nonempty"><em>substring</em></span> in <code>s</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;babad&quot;
<strong>Output:</strong> &quot;bab&quot;
<strong>Explanation:</strong> &quot;aba&quot; is also a valid answer.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;cbbd&quot;
<strong>Output:</strong> &quot;bb&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 1000</code></li>
	<li><code>s</code> consist of only digits and English letters.</li>
</ul>

class Solution {
public:
     int getPalindromFromMiddle(string s, int start, int end)
       {
           if (s == "" || start > end) 
               return 0;
           auto size = s.length();
           
           while (start >= 0 && end < size && s[start] == s[end])
           {
        
               start--;
               end++;
           }
           return end - start -1;
       }
    string longestPalindrome(string s) {
      
       int i = 0;
       int size = s.length();

       int start = 0, end = 0;
        int len1 = 0;
        int len2 = 0;
        int current_len = 0;
       while (i<size-1)
       {
           if (size -i < current_len/2)
               break;
           len1 = getPalindromFromMiddle(s, i,i );
           len2 = getPalindromFromMiddle(s, i,i+1 );
           
           len1 = max(len1, len2);
           if (len1 >  current_len)
           {
               start = i - (len1-1)/2;
               end = i + len1/2;
               current_len = end -start +1;
           }
        
           
   
           i++;
       }
       return s.substr(start, end-start+1);
    }
};

119855