![]() |
VOOZH | about |
Given a string s consisting of lowercase characters, the task is to check if there exists any subsequence in the string which is not a palindrome. If there is at least 1 such subsequence, then return true, otherwise return false.
Examples:
Input : str = "abaab"
Output: Yes
Explanation: Subsequences "ab" , "abaa" , "aab", are not a palindrome.Input : str = "zzzz"
Output: NO
Explanation: All possible subsequences are palindrome.
The idea is to generate all possible subsequences of the given string and check each one to see if it's not a palindrome. If we find even one subsequence that is not a palindrome, we return true; otherwise, we return false.
Yes
The idea is to recognize that a subsequence is not a palindrome if and only if the string contains at least two different characters. This is because any subsequence with all same characters is always a palindrome, and any subsequence with at least two different characters can be arranged to form a non-palindrome.
Step by step approach:
Yes