Check if there exists any sub | C ++ program to check if there exists at least 1 sub - sequence in a string which is not palindrome ; Function to check if there exists at least 1 sub - sequence in a string which is not palindrome ; use set to count number of distinct characters ; insert each character in set ; If there is more than 1 unique characters , return true ; Else , return false ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isAnyNotPalindrome ( string s ) { set < char > unique ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) unique . insert ( s [ i ] ) ; if ( unique . size ( ) > 1 ) return true ; else return false ; } int main ( ) { string s = " aaaaab " ; if ( isAnyNotPalindrome ( s ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }