def two_single_numbers(nums): # Find the XOR of the two unique numbers bitwise_xor = 0 for num in nums: bitwise_xor ^= num # Find a bitmask to isolate the rightmost set bit in bitwise_xor bitwise_mask = bitwise_xor & -bitwise_xor # Initialize variables to store the two unique numbers result = 0 # Iterate through all elements of the array for num in nums: # Check if the rightmost set bit in bitwise_xor is set in num if num & bitwise_mask: # num has the rightmost set bit, XOR it with result result ^= num # Return a list containing the two unique numbers return [result, bitwise_xor ^ result] # Driver code def main(): inputs_arr = [[1, 2, 2, 3], [4, 4, 3, 2, 3, 5], [1, 1, 7, 4, 5, 5, 8, 8], [1, 0], [9, 8, 8, 7, 6, 6, 4, 4]] for i in range(len(inputs_arr)): print(i + 1, ". \t Input list: ", inputs_arr[i], sep="") print("\t Two Singles numbers in a list: ", two_single_numbers(inputs_arr[i]), sep="") print("-" * 100) if __name__ == '__main__': main()