#455 · Bit manipulation · Expert · 230 XP · about 40 min
Choose any subset of the list nums and combine its numbers with XOR (^); the empty subset gives 0. Many different subsets give the same result. Write xor_values(nums) that returns a tuple (count, largest): how many different values these XORs can take, and the largest of them.
xor_values([1, 2, 3]) # returns (4, 3) xor_values([6, 10, 12]) # returns (4, 12) xor_values([5, 5]) # returns (2, 5) xor_values([]) # returns (1, 0)
In the first example the eight subsets give 0, 1, 2, 3, 1 ^ 2 = 3, 1 ^ 3 = 2, 2 ^ 3 = 1 and 1 ^ 2 ^ 3 = 0: only four different values. In the second, 6 ^ 10 is already 12, so 12 adds nothing new.
0 <= len(nums) <= 20,0000 <= nums[i] < 2**60First solves only, ranked by stars and then time.