Skip to content
DeepForgeby svx
All problems
EasyData Structuresds-308

Set Union with Bitset

Problem

List the set members of the union of two bitsets.

a and b are non-negative integers used as bitsets. Return the sorted positions of the set bits in a | b.

Hint

Shift the union right one bit at a time and record the positions where the low bit is set.

Test cases

case 1
in: [5,3]
expected: [0,1,2]
case 2
in: [0,0]
expected: []
case 3
in: [255,1]
expected: [0,1,2,3,4,5,6,7]
case 4
in: [10,12]
expected: [1,2,3]
Starter codePython
def bitset_union_members(a, b):
    # Your code here
    pass

4 test cases · run your code against them in the editor