Lexicographically smallest numeric string having odd digit counts | C ++ program for the above approach ; Function to construct lexicographically smallest numeric string having an odd count of each characters ; Stores the resultant string ; If N is even ; Otherwise ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string genString ( int N ) { string ans = " " ; if ( N % 2 == 0 ) { ans = string ( N - 1 , '1' ) + '2' ; } else { ans = string ( N , '1' ) ; } return ans ; } int main ( ) { int N = 5 ; cout << genString ( N ) ; return 0 ; }