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:
- Find the frequency of a digit in a number
- Check if frequency of each digit is less than the digit
- Number of times a number can be replaced by the sum of its digits until it only contains one digit
- Convert a number of length N such that it contains any one digit at least 'K' times
- Perform n steps to convert every digit of a number in the format [count][digit]
- Count of Numbers in Range where first digit is equal to last digit of the number
- Largest number less than N with digit sum greater than the digit sum of N
- Check if the Xor of the frequency of all digits of a number N is zero or not
- Largest number less than N whose each digit is prime number
- Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
- Generate k digit numbers with digits in strictly increasing order
- Number of n digit numbers that do not contain 9
- Special two digit number
- Sum of digit of a number using recursion
- Find the Number which contain the digit d
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.