Connection Status:
Competition Arena > LongestPalindrome
Rookie SRM 5 · 2021-05-12 · by t-mac · String Manipulation
Class Name: LongestPalindrome
Return Type: int
Method Name: longestLength
Arg Types: (string)
Problem Statement

Problem Statement

A palindrome is a string that reads the same forwards and backwards. For instance, ABBA is a palindrom, but ABCBB is not. You are given a String s. Return the length of the longest substring of s that is a palindrome.

Notes

  • A substring is a set of contiguous characters that form part of the string. For example, BCD is a substring of ABCDE, but BD is not, since B and D are not contiguous in ABCDE.

Constraints

  • s will contain between 1 and 50 characters, inclusive.
  • Each character of s will be between 'A' and 'Z', inclusive.
Examples
0)
"ABAA"
Returns: 3

"ABA" is a palindrome.

1)
"ABB"
Returns: 2

The best we can do is "BB".

2)
"ABCBCA"
Returns: 3

"BCB" or "CBC" works, either is the same length.

3)
"ABCDEFG"
Returns: 1
4)
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX"
Returns: 1

Submissions are judged against all 79 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class LongestPalindrome with a public method int longestLength(string s) · 79 test cases · 2 s / 256 MB per case

Submitting as anonymous