Snowflake OA | Oct 14th
Anonymous User
86

A super bitstring is a a bitstring made by flipping zero or more of the 0s in the bit string to 1.

Given k decimal integers, convert each to a bit string that has a given length n. Generate all possible super bit strings of each of the k bit strings. Finally, perfomr a union of the super bit strings of all the bit strings and determine its size. This is the number to return.

For example, the required bit string length, n=5, there are k=2 decimal integers, bitStrings = [10, 26] which when converted to strings equal [01010, 11010]. Note that the value 10 had to be padded with a zero to make it the required length.

Original bit string = 01010
Decimal 10

Flip 0: 01010
Flip 1: 11010
		01110
		01011
Flip 2: 11110
		11011
		01111
Flip 3: 11111


Original bit string = 11010
Decimal 26

Flip 0: 11010
Flip 1: 11110
	    11011
Flip 2: 11111

There are 8 super bit strings that can be formed from the first bit string and 4 that can be formed from the second. All of the super bit strings formed from 11010 appear in the set from 01010, so after the union, there are still only 8 super bit strings formed.

Constraints:
n <= 18
k <= 50,000
1 <= bitStrings[i] <= 262144

How would this be approached? Tried a backtracking solution that TLE'd and then tried to make a math-based solution through bitwise AND operators but couldn't figure out a correct formula. Any help would be appreciated.

Comments (1)