#K34262. Longest Substring with Matching Ends

    ID: 25271 Type: Default 1000ms 256MiB

Longest Substring with Matching Ends

Longest Substring with Matching Ends

Given a string s and a character char, find the longest substring in s that starts and ends with char.

If char is not present in s, return an empty string. If char appears only once, return that single character.

Note: The solution should correctly handle edge cases (e.g., empty strings or when the character appears only once).

inputFormat

The input is read from stdin and consists of two lines:

  • The first line is the string s.
  • The second line is the character char (guaranteed to be a single character or empty).

outputFormat

Print to stdout the longest substring of s that starts and ends with the character char. If no such substring exists, output an empty string.

## sample
abacabad
a
abacaba