- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Find the lexicographically largest palindromic Subsequence of a String in Python

Suppose we have a string S; we have to find the lexicographically largest palindromic subsequence of that string.

So, if the input is like "tutorialspointtutorial", then the output will be "uu"

To solve this, we will follow these steps −

ans := blank string

max_val := s[0]

for i in range 1 to size of s, do

max_val := maximum of max_val, s[i]

for i in range 0 to size of s, do

if s[i] is same as max_val, then

ans := ans + s[i]

return ans

## Example

Let us see the following implementation to get better understanding −

def largest_palindromic_substr(s): ans = "" max_val = s[0] for i in range(1, len(s)): max_val = max(max_val, s[i]) for i in range(0, len(s)): if s[i] == max_val: ans += s[i] return ans s = "tutorialspointtutorial" print(largest_palindromic_substr(s))

## Input

"tutorialspointtutorial"

## Output

uu

- Related Questions & Answers
- Program to find lexicographically smallest non-palindromic string in Python
- Program to find length of longest palindromic subsequence in Python
- Program to find lexicographically smallest subsequence of size k in Python
- Program to find out the length of longest palindromic subsequence using Python
- Longest Palindromic Subsequence
- Find a palindromic string B such that given String A is a subsequence of B in C++
- Program to find lexicographically largest mountain list in Python
- Count all Palindromic Subsequence in a given String in C++
- Counting all possible palindromic subsequence within a string in JavaScript
- Longest Palindromic Subsequence in C++
- Find the count of palindromic sub-string of a string in its sorted form in Python
- Program to find out the palindromic borders in a string in python
- Program to Find Out the Largest K-Divisible Subsequence Sum in Python
- Find all distinct palindromic sub-strings of a given String in Python
- Program to construct the lexicographically largest valid sequence in Python

Advertisements