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:
- Sum of the alphabetical values of the characters of a string
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Remove all non-alphabetical characters of a String in Java
- Check if the characters of a given string are in alphabetical order
- Average of ASCII values of characters of a given string
- Program to find the XOR of ASCII values of characters in a string
- Count characters in a string whose ASCII values are prime
- Minimum length substring with exactly K distinct characters
- Program to find the product of ASCII values of characters in a string
- Minimum operations to make frequency of all characters equal K
- Minimum deletions from string to reduce it to string with at most 2 unique characters
- Print common characters of two Strings in alphabetical order
- Program to check if first and the last characters of string are equal
- Length of the smallest sub-string consisting of maximum distinct characters
- Maximum length of balanced string after swapping and removal of characters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.