Count of all unique substrings with non | Java 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
import java . util . * ; class GFG { static int distinctSubString ( String P , int N ) { HashSet < String > S = new HashSet < String > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { boolean [ ] freq = new boolean [ 26 ] ; String s = " " ; for ( int j = i ; j < N ; ++ j ) { int pos = P . charAt ( j ) - ' a ' ; if ( freq [ pos ] == true ) break ; freq [ pos ] = true ; s += P . charAt ( j ) ; S . add ( s ) ; } } return S . size ( ) ; } public static void main ( String [ ] args ) { String S = " abba " ; int N = S . length ( ) ; System . out . print ( distinctSubString ( S , N ) ) ; } }