Given two integers A and B, the task is to check whether the given numbers are anagrams of each other or not. Just like strings, a number is said to be an anagram of some other number if it can be made equal to the other number by just shuffling the digits in it.
Input: A = 204, B = 240
Input: A = 23, B = 959
Approach: Create two arrays freqA and freqB where freqA[i] and freqB[i] will store the frequency of digit i in a and b respectively. Now traverse the frequency arrays and for any digit i if freqA[i] != freqB[i] then the numbers are not anagrams of each other else they are.
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.
- Check if two strings are k-anagrams or not
- Check if a String contains Anagrams of length K which does not contain the character X
- Check if the given array contains all the divisors of some integer
- Check for integer overflow on multiplication
- Check if an integer can be expressed as a sum of two semi-primes
- Given a sequence of words, print all anagrams together | Set 2
- Find the word with most anagrams in a given sentence
- Given a sequence of words, print all anagrams together using STL
- Given a sequence of words, print all anagrams together | Set 1
- Number of index pairs such that s[i] and s[j] are anagrams
- Minimum decrements to make integer A divisible by integer B
- Count of anagrams of each string in an array present in another array
- Blum Integer
- Smallest integer which has n factors or more
- Count even and odd digits in an Integer
- Find One's Complement of an Integer
- Find whether a given integer is a power of 3 or not
- Greatest Integer Function
- Minimum positive integer value possible of X for given A and B in X = P*A + Q*B
- Square root of an integer
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.