Lexicographically smallest subsequence possible by removing a character from given string | C ++ program for the above approach ; Function to find the lexicographically smallest subsequence of length N - 1 ; Generate all subsequence of length N - 1 ; Store main value of string str ; Erasing element at position i ; Sort the vector ; Print first element of vector ; Driver Code ; Given string S ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void firstSubsequence ( string s ) { vector < string > allsubseq ; string k ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { k = s ; k . erase ( i , 1 ) ; allsubseq . push_back ( k ) ; } sort ( allsubseq . begin ( ) , allsubseq . end ( ) ) ; cout << allsubseq [ 0 ] ; } int main ( ) { string S = " geeksforgeeks " ; firstSubsequence ( S ) ; return 0 ; }