Count of all unique substrings with non | C # program to find the count of all unique sub - Strings with non - repeating characters ; Function to count all unique distinct character subStrings ; Hashmap to store all subStrings ; Iterate over all the subStrings ; Boolean array to maintain all characters encountered so far ; Variable to maintain the subString till current position ; Get the position of the character in the String ; Check if the character is encountred ; Add the current character to the subString ; Insert subString in Hashmap ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int distinctSubString ( String P , int N ) { HashSet < String > S = new HashSet < String > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { bool [ ] freq = new bool [ 26 ] ; String s = " " ; for ( int j = i ; j < N ; ++ j ) { int pos = P [ j ] - ' a ' ; if ( freq [ pos ] == true ) break ; freq [ pos ] = true ; s += P [ j ] ; S . Add ( s ) ; } } return S . Count ; } public static void Main ( String [ ] args ) { String S = " abba " ; int N = S . Length ; Console . Write ( distinctSubString ( S , N ) ) ; } }