Count of all unique substrings with non | 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
function distinctSubstring ( P , N ) { var S = new Set ( ) ; for ( var i = 0 ; i < N ; ++ i ) { var freq = Array ( 26 ) . fill ( false ) ; var s = " " ; for ( var j = i ; j < N ; ++ j ) { var pos = P [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; if ( freq [ pos ] == true ) break ; freq [ pos ] = true ; s += P [ j ] ; S . add ( s ) ; } } return S . size ; } var S = " " ; var N = S . length ; document . write ( distinctSubstring ( S , N ) ) ;