Untitled

mail@pastecode.io avatar
unknown
plain_text
22 days ago
774 B
1
Indexable
Never
#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;
}
Leave a Comment