Minimum length String with Sum of the alphabetical values of the characters equal to N | C ++ program to find the Minimum length String with Sum of the alphabetical values of the characters equal to N ; Function to find the minimum length ; Function to find the minimum length String ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minLength ( int n ) { int ans = n / 26 ; if ( n % 26 != 0 ) ans ++ ; return ans ; } string minString ( int n ) { int ans = n / 26 ; string res = " " ; while ( ans -- ) { res = res + " z " ; } if ( n % 26 != 0 ) { res = res + ( char ) ( ( n % 26 ) + 96 ) ; } return res ; } int main ( ) { int n = 50 ; cout << minLength ( n ) << endl << minString ( n ) ; return 0 ; }