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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int distinctSubstring ( string & P , int N ) { unordered_set < string > S ; for ( int i = 0 ; i < N ; ++ i ) { vector < bool > freq ( 26 , false ) ; 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 . insert ( s ) ; } } return S . size ( ) ; } int main ( ) { string S = " abba " ; int N = S . length ( ) ; cout << distinctSubstring ( S , N ) ; return 0 ; }