Smallest string which not a subsequence of the given string

by admin

  

#embrace <bits/stdc++.h>

utilizing namespace std;

  

string ShortestSubsequenceNotPresent(string str)

{

  

    

    

    string shortestString;

  

    

    int N = str.size();

  

    

    unordered_set<char> subsegments;

  

    

    for (int i = 0; i < N; i++) {

  

        

        

        subsegments.insert(str[i]);

  

        

        

        if (subsegments.measurement() == 26) {

  

            

            

            shortestString.push_back(str[i]);

  

            

            

            subsegments.clear();

        }

    }

  

    

    for (char ch = 'a'; ch <= 'z'; ch++) {

  

        

        

        if (subsegments.depend(ch) == 0) {

            shortestString.push_back(ch);

  

            

            return shortestString;

        }

    }

    return shortestString;

}

  

int most important()

{

  

    

    string str

        = "abcdefghijklmnopqrstuvwxyzaabbccdd";

  

    cout << ShortestSubsequenceNotPresent(str);

    return 0;

}

Related Posts

Leave a Comment