Given a number N containing digits from 1 to 9 only. The task is to generate a new number using the number N such that the frequency of each digit in the new number is equal to the frequency of that digit in N multiplied by the digit itself.
Note: The digits in the new number must be in increasing order.
Input : N = 312
Output : 122333
Explanation : The output contains digit 1 once, digit 2 twice and digit 3 thrice.
Input : N = 525
Output : 225555555555
Explanation : The output contains digit 2 twice and digit 5 ten times. 5 is ten times because its frequency is 2 in the given integer.
The idea is to store the count or the frequency of the digits in the given number N using a counting array or hash. Now, for each digit add it to the new number, K number of times where K is equal to its frequency in the counting array multiplied by the digit itself.
Below is the implementation of the above approach:
- Maximum length prefix such that frequency of each character is atmost number of characters with minimum frequency
- Check if frequency of each digit is less than the digit
- Convert a number of length N such that it contains any one digit at least 'K' times
- Smallest integer greater than n such that it consists of digit m exactly k times
- Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
- Count of Binary Strings of length N such that frequency of 1's exceeds frequency of 0's
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Number of triplets such that each value is less than N and each pair sum is a multiple of K
- Count number of times each Edge appears in all possible paths of a given Tree
- Times required by Simple interest for the Principal to become Y times itself
- Count of N-digit numbers having digit XOR as single digit
- Number of times a number can be replaced by the sum of its digits until it only contains one digit
- Generate a string of size N whose each substring of size M has exactly K distinct characters
- Longest subsequence where each character occurs at least k times
- Count substrings with each character occurring at most k times
- Number formed by adding product of its max and min digit K times
- Largest index for each distinct character in given string with frequency K
- Check if frequency of each element in given array is unique or not
- Calculate the frequency of each word in the given string
- Generate k digit numbers with digits in strictly increasing order
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.