Remove K words from string to make it lexographically highest

 // Online C++ compiler to run C++ program online

#include <iostream>

#include <string>

using namespace std;


int remov(string str){

    int min=999;

    int k=0;

    for (int i=0;i<str.size();i++){

        if (min>str[i]){

            k=i;

            min=str[i];

        }

        

        

    }

    return k;

}

int main() {

    string str="zzzzzzzyyyyyyyyabc";

    cout<<str;

    int k=3;

    while(k>0){

    int idx=remov(str);

    //cout<<idx<<endl;

    str.erase(idx,1);

    cout<<endl;

    cout<<str;

    k--;

    }

    



    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings