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
- Maximum length prefix such that frequency of each character is atmost number of characters with minimum frequency
- 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
- Number formed by adding product of its max and min digit K times
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- 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
- Find the remainder when First digit of a number is divided by its Last digit
- Last digit of a number raised to last digit of N factorial
- 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 in the Array having frequency same as value
- Count the number of occurrences of a particular digit in a number
- 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
- Find the Number which contain the digit d
- Special two digit number
- Sum of digit of a number using recursion
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.