Untitled
unknown
plain_text
2 years ago
774 B
7
Indexable
#include <bits/stdc++.h>
int uniqueSubstrings(string input)
{
//Write your code here
int i,j,n,max_len,start,end;
max_len = 0;
n = input.size();
start = 0;
end = n;
unordered_map<int,int> mpp;
i = 0; j = 0;
while( j < n ){
mpp[input[j]] += 1;
if( max_len < mpp.size()){
max_len = mpp.size();
start = i;
end = j;
}
else{
if( mpp[input[i]] == 1){
mpp.erase(input[i]);
}
else{
mpp[input[i]] -= 1;
}
i++;
}
j++;
}
return end - start + 1;
}Editor is loading...
Leave a Comment