Given a positive number ‘N’, the task is to find whether ‘N’ is balanced or not. Output ‘YES’ if ‘N’ is a balanced number else ‘NO’.
A number is balanced if the frequency of all the digits in it is same i.e. all the digits appear the same number of times.
Input: N = 1234567890 Output: YES The frequencies of all the digits are same. i.e. every digit appears same number of times. Input: N = 1337 Output: NO
- Create an array
freqof size 10 which will store the frequency of each digit in ‘N’.
- Then, check if all the digits of ‘N’ have the same frequency or not.
- If yes then print ‘
YES‘ or ‘
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum digits to be removed to make either all digits or alternating digits same
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Check if the Xor of the frequency of all digits of a number N is zero or not
- Check if frequency of all characters can become same by one removal
- Check if the sum of digits of number is divisible by all of its digits
- Maximum length prefix such that frequency of each character is atmost number of characters with minimum frequency
- Largest subarray with frequency of all elements same
- Count different numbers possible using all the digits their frequency times
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Maximum difference between frequency of two elements such that element having greater frequency is also greater
- Count of Binary Strings of length N such that frequency of 1's exceeds frequency of 0's
- Check if two numbers have same number of digits
- Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Find smallest possible Number from a given large Number with same count of digits
- Count of numbers with all digits same in a given range
- Find the Largest number with given number of digits and sum of digits
- Number of digits in the nth number made of given four digits
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Find smallest number with given number of digits and sum of digits under given constraints
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.