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:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Check if two strings are k-anagrams or not
- Check for integer overflow on multiplication
- Check if the given array contains all the divisors of some integer
- Check if an integer can be expressed as a sum of two semi-primes
- Given a sequence of words, print all anagrams together using STL
- Number of index pairs such that s[i] and s[j] are anagrams
- Given a sequence of words, print all anagrams together | Set 2
- Given a sequence of words, print all anagrams together | Set 1
- Minimum decrements to make integer A divisible by integer B
- Blum Integer
- Replace all ‘0’ with ‘5’ in an input Integer
- Count even and odd digits in an Integer
- Convert given integer X to the form 2^N - 1
- Greatest Integer Function
- Find whether a given integer is a power of 3 or not
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.