Given two integer A and B, the task is to check whether the binary representation of B can be generated by permuting the binary digits of A.
Input: A = 3, B = 9
Binary(3) = 0011 and Binary(9) = 1001
Input: A = 6, B = 7
Approach: The idea is to count the number of set bits in the binary representations of both the numbers, now if they are equal then the answer is Yes or else the answer is No.
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.
- Largest palindromic number by permuting digits
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Count of numbers upto N digits formed using digits 0 to K-1 without any adjacent 0s
- Sum of all numbers that can be formed with permutations of n digits
- Find maximum number that can be formed using digits of a given number
- Maximum possible time that can be formed from four digits
- Count of alphabets whose ASCII values can be formed with the digits of N
- Greatest number less than equal to B that can be formed from the digits of A
- Find the count of numbers that can be formed using digits 3, 4 only and having length at max N.
- Find the largest number that can be formed by changing at most K digits
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Minimum digits to be removed to make either all digits or alternating digits same
- Check if the number formed by the last digits of N numbers is divisible by 10 or not
- Check if a right-angled triangle can be formed by the given coordinates
- Check if a right-angled triangle can be formed by moving any one of the coordinates
- Check if N rectangles of equal area can be formed from (4 * N) integers
- Check whether a straight line can be formed using N co-ordinate points
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Check if the sum of digits of number is divisible by all of its digits
- Check if a given number can be represented in given a no. of digits in any base
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.