Given an integer N, the task is to find the minimum length string whose sum of each character (As a = 1, b = 2, … z = 26) equals to N.
Input: N = 5 Output: e 5 can be represented as "aac" or "ad" or "e" etc But we will take e as it is the minimum length Input: N = 34 Output: zj
- To minimise the length of the String, Greedy Approach will be used.
- By Greedy Approach, the solution will be very simple.
- The minimum length of the String will be
N/26 + 1 => if N % 26 != 0 N/26 => if N % 26 == 0
- And the minimum string can be found as
(N/26 times z) + (N%26) => if N % 26 != 0 (N/26 times z) => if N % 26 == 0
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sum of the alphabetical values of the characters of a string
- Remove all non-alphabetical characters of a String in Java
- Check if the characters of a given string are in alphabetical order
- Print common characters of two Strings in alphabetical order
- Python code to print common characters of two Strings in alphabetical order
- Check whether the vowels in a string are in alphabetical order or not
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Split a given string into substrings of length K with equal sum of ASCII values
- Find alphabetical order such that words can be considered sorted
- Reorder the position of the words in alphabetical order
- Print the frequency of each character in Alphabetical order
- Minimum cost to remove the spaces between characters of a String by rearranging the characters
- Sort a String in decreasing order of values associated after removal of values smaller than X
- Length of longest Palindromic Subsequence of even length with no two adjacent characters same
- Minimize length of prefix of string S containing all characters of another string T
- Calculate Sum of ratio of special characters to length of substrings of the given string
- Minimum flips required to convert given string into concatenation of equal substrings of length K
- Character whose frequency is equal to the sum of frequencies of other characters of the given string
- Average of ASCII values of characters of a given string
- Program to find the product of ASCII values of characters in a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.