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:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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
- Split a given string into substrings of length K with equal sum of ASCII values
- 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
- Count characters in a string whose ASCII values are prime
- Program to find the XOR of ASCII values of characters in a string
- Minimum length substring with exactly K distinct characters
- Program to find the product of ASCII values of characters in a string
- Minimum characters to be deleted from the end to make given two strings equal
- Minimum operations to make frequency of all characters equal K
- Print common characters of two Strings in alphabetical order
- Minimum characters to be deleted from the beginning of two strings to make them equal
- Minimum deletions from string to reduce it to string with at most 2 unique characters
- Program to check if first and the last characters of string are equal
- Python code to print common characters of two Strings in alphabetical order
- Maximum length of balanced string after swapping and removal of characters
- Length of the smallest sub-string consisting of maximum distinct characters
- Total length of string from given Array of strings composed using given 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 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.