Code : 02


 Question 2

The smallest palindrome

You are given a string s. you are required to find a palindromic subsequence of this string. If there exists multiple such strings, you must determine a lexicographically smallest string.

Example

Consider s= “fsged”.

·        The lexicographically smallest subsequence which is a palindrome is ‘d’.

Function description

Complete the palindromic subsequence function provided in the editor. This function take the given string as parameter:

·        S: represents the given string value

Input format

Note: this is the input format that you must use to provide custom input(available above the Compile and Test button).

·        The only line of input contains a string s.

 

Output format

Print a palindromic string that is a subsequence of string s. if multiple answers exists, then print the lexigraphically smallest string

 

Print – 1 if no such subsequence are available in the string.

Constraints

1≤|s|≤106

Code snippets(also called starter code/boilerplate code)

This question has code snippets for C, CPP, Java, and Python.


Explanation

The only subsequence of the given is the string itself that is palindromic.

No comments:

Post a Comment