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
using System ; using System . Collections . Generic ; class GFG { static bool isAnyNotPalindrome ( String s ) { HashSet < char > unique = new HashSet < char > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) unique . Add ( s [ i ] ) ; if ( unique . Count > 1 ) return true ; else return false ; } public static void Main ( String [ ] args ) { String s = " aaaaab " ; if ( isAnyNotPalindrome ( s ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }