Given a number N, find all binary sequences of length 2*N such that sum of first N bits is same as the sum of last N bits.
Input: N = 2
Input: N = 1
Note: The recursive approach to this problem can be found here.
A simple approach to run a loop from 0 to 22*N and convert into the binary form and check whether the sum of first half is equal to the sum of the second half.
If the above condition is true, then print that number, else check for the next one.
Below is the implementation of the above approach:
0000 0101 0110 1001 1010 1111
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Program to find whether a no is power of two
- Program to find parity
- Write an Efficient C Program to Reverse Bits of a Number
- Find minimum number to be divided to make a number a perfect square
- Find whether a given number is a power of 4 or not
- Count of Binary Digit numbers smaller than N
- Find Union and Intersection of two unsorted arrays
- Print all sequences of given length
- To find sum of two numbers without using any operator
- Find day of the week for a given date
- Given a number, find the next smallest palindrome
- Find the element that appears once
- Find the largest multiple of 2, 3 and 5
- Program to find amount of water in a given glass
- Find the maximum distance covered using n bikes
- Find if two rectangles overlap
- Find the smallest number whose digits multiply to a given number n
- Check if binary representation of a number is palindrome
- Find next greater number with same set of digits
- Find n'th number in a number system with only 3 and 4
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.