description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): xor = 0 for num in nums: xor ^= num bit = 0 while xor % 2 == 0: xor //= 2 bit += 1 group1 = [] group2 = [] for num in nums: if (num >> bit) % 2 == 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): sums = 0 for i in range(0, len(nums)): sums = sums ^ nums[i] sums = sums & -sums sum1 = 0 sum2 = 0 for i in range(0, len(nums)): if nums[i] & sums > 0: sum1 = sum1 ^ nums[i] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR RETURN F...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): xor = 0 for i in nums: xor = i ^ xor listt1 = [] listt2 = [] num = 0 a = xor while xor > 0: if xor % 2 == 1: break else: num += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR RETU...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): hmap = {} for i in range(len(nums)): if nums[i] in hmap: hmap[nums[i]] += 1 else: hmap[nums[i]] = 1 result = [] for item in nums: if hmap[item] == 1: res...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): val = nums[0] for i in range(1, len(nums)): val = val ^ nums[i] rsb = val & -val num1 = 0 num2 = 0 for i in nums: if i & rsb == 0: num1 = num1 ^ i else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, arr): res = 0 for elm in arr: res ^= elm res = bin(res)[2:] pos = -1 for i in range(-1, -len(res) - 1, -1): if res[i] == "1": pos = i break res = int(res, 2) new = ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): xor = nums[0] for i in nums[1:]: xor = xor ^ i ans = [] right_bit = xor & ~(xor - 1) x = 0 y = 0 for i in range(len(nums)): if nums[i] & right_bit: x = x ^ nums[i] ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR V...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, arr): xorOfAllElements = arr[0] for i in range(1, len(arr)): xorOfAllElements ^= arr[i] rightSetBit = xorOfAllElements & ~(xorOfAllElements - 1) x = 0 y = 0 for i in range(len(arr)): if arr[i] & rightSetB...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR VAR E...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): xor = 0 for i in nums: xor ^= i xor = xor & ~(xor - 1) a = 0 b = 0 for i in nums: if xor & i == 0: a ^= i else: b ^= i if a > b: retu...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR RETURN LIST VAR VAR RETURN LIST VAR VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): xr = 0 for i in nums: xr ^= i a = [] b = [] i = 0 while 1: if xr & 1 << i: break i += 1 v = 1 << i for i in nums: if v & i: a...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, n): m = 0 for i in n: m = m ^ i i = 0 while m > 0: if m & 1 == 1: break m = m >> 1 i = i + 1 l = [] r = [] for j in n: if j & 1 << i: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR AS...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): nums.sort() count = 0 ini = nums[0] listt = [] for i in nums: if i == ini: count += 1 else: if count % 2 == 1: listt.append(ini) ini = i ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER VAR NUMBER
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): c = [] d = {} for i in nums: if i in d: c.remove(i) else: c.append(i) d[i] = 1 c.sort() return c
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): hash = {} res = [] for n in nums: if hash.get(n, None) == None: hash[n] = 1 else: hash[n] += 1 for key, value in hash.items(): if value == 1: res.append(...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NONE NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): nums.sort() c = 0 a = [] for h in nums: if c == 0: c ^= h elif c == h: c = 0 else: a.append(c) c = h if c != 0: a.app...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): res = 0 for num in nums: res = res ^ num bRes = bin(res)[2:] pos = -1 for i in range(len(bRes) - 1, -1, -1): if bRes[i] == "0": pos -= 1 else: break temp...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP NU...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): nums.sort(reverse=True) res = [] while nums: if len(nums) == 1: res.append(nums[0]) break curr1 = nums.pop() curr2 = nums.pop() if curr1 != curr2: re...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST WHILE VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): if len(nums) == 0: return if 1 > len(nums) > 10**6: return final = [] nums_set = list(set(nums)) for i in nums_set: if 1 <= i <= 50 * 10**6 and nums.count(i) == 1: final.append(...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN IF NUMBER FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER RETURN ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): nums.sort() output = [] i = 0 while i < len(nums): if i == len(nums) - 1: output = output + [nums[i]] break if nums[i] != nums[i + 1]: output = output + [nums[i]] ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR LIST VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): bitmask = 0 for num in nums: bitmask ^= num diff = bitmask & -bitmask x = 0 for num in nums: if num & diff: x ^= num y = bitmask ^ x return [x, y] if x < y else [y, x]
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR VAR LIST VAR VAR LIST VAR VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): d = dict() for i in nums: if i in d: d[i] += 1 else: d[i] = 1 c = [] for i in d: if d[i] == 1: c.append(i) if c[0] > c[1]: c[0], c[1]...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): d = {} l = [] for i in nums: try: d[i] += 1 l.remove(i) except: d[i] = 1 l.append(i) return sorted(l)
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): sum = 0 for i in range(len(nums)): sum = sum ^ nums[i] right = sum & ~(sum - 1) x, y = 0, 0 for i in range(len(nums)): if nums[i] & right > 0: x = x ^ nums[i] else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): h = {} ans = [] for i in nums: if str(i) in h.keys(): h[str(i)] += 1 else: h.update({str(i): 1}) for i in h.keys(): if h[str(i)] == 1: ans.append(int(i))...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR DICT FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, s): freq = {} for ch in s: freq[ch] = freq.get(ch, 0) + 1 unique_chars = [ch for ch in freq if freq[ch] == 1] return sorted(unique_chars)
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): res = 0 for i in nums: res = res ^ i setbit = 0 setbit = res & ~(res - 1) res1 = 0 res2 = 0 for i in nums: if i & setbit: res1 = res1 ^ i else: r...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RET...
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): xor = 0 for n in nums: xor ^= n x = 0 y = 0 rmsb = xor & ~(xor - 1) for n in nums: if n & rmsb == rmsb: x ^= n else: y ^= n return sorted([x, y])
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR LIST VAR VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): hash_map = {} for i in nums: if i not in hash_map: hash_map[i] = 1 else: hash_map.pop(i) ans = [] for key in hash_map: ans.append(key) ans.sort() return ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): temp_set = set() for i in range(len(nums)): if nums[i] in temp_set: temp_set.remove(nums[i]) else: temp_set.add(nums[i]) return sorted(temp_set)
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): nl = {} for x in nums: if nl.get(x): nl.pop(x) else: nl[x] = 1 result = list(nl.keys()) if result[0] > result[1]: return result[::-1] else: return re...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER RETURN VAR NUMBER RETURN VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): res = [] for n in nums: if n in res: res.remove(n) else: res.append(n) res.sort() return res
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): ans = 0 for i in nums: ans ^= i ans = ans & ~(ans - 1) set1, set2 = 0, 0 for i in nums: if i & ans: set1 ^= i else: set2 ^= i res = [] if set1 > ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR RETURN VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): res = [] dic = {} for i in nums: dic[i] = dic.get(i, 0) + 1 for i, j in dic.items(): if j == 1: res.append(i) if len(res) == 2: return sorted(res)
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def singleNumber(self, nums): summ = 0 for i in nums: summ = summ ^ i summ = summ & -summ a = 0 b = 0 for i in nums: if i & summ > 0: a = a ^ i else: b = b ^ i if a > b: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN LIST VAR VAR RETURN LIST VAR VAR
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct. Find the other two numbers. Return in increasing order. Example 1: Input: N = 2 arr[] = {1, 2, 3, 2, 1, 4} Output: 3 4 Explanation: 3 and 4 occur exactly once. ...
class Solution: def ithBitSet(self, n: int, i: int) -> bool: return n & 1 << i != 0 def singleNumber(self, nums): xor = 0 for num in nums: xor ^= num i = 0 while xor & 1 == 0: xor = xor >> 1 i += 1 res1 = 0 res2 = 0 ...
CLASS_DEF FUNC_DEF VAR VAR RETURN BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR ...
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): st = 0 for i in range(len(s)): if st == 0: if s[i] == "1": st = 1 elif st == 1: if s[i] == "1": st = 0 else: st = 2 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): x = len(s) - 1 summ = 0 j = 0 for i in range(x, -1, -1): summ = summ + (1 << i) * int(s[j]) j = j + 1 if summ % 3 == 0: return 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): res = 0 for i in range(len(s)): if s[i] == "1": if i % 2 == 0: res += 1 else: res += 2 if res % 3 == 0: return 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): n = len(s) j = 0 ans = 0 for i in range(n - 1, -1, -1): if s[i] == "1": ans += 2 << j else: ans += 0 j += 1 if ans % 3 == 0: return 1 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): c = str(int(s, 2)) d = 0 for i in c: d = d + int(i) if d % 3 == 0: return 1 else: return 0
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, S): oddPosition, evenPosition = 0, 0 for i in range(len(S)): if i % 2 and S[i] == "1": oddPosition += 1 if i % 2 == 0 and S[i] == "1": evenPosition += 1 return 1 if abs(oddPosition - evenPosition) ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR STRING VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): od, ev = 0, 0 for i in range(len(s)): if s[i] == "1": if i & 1: od += 1 else: ev += 1 ans = abs(od - ev) if ans % 3 == 0: return 1 return...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): e = 0 o = 0 for i in range(len(s)): if i & 1 == 0 and s[i] == "1": e += 1 if i & 1 and s[i] == "1": o += 1 if (e - o) % 3 == 0: return 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): num = 0 for i in s: num = num * 2 + int(i) return int(num % 3 == 0) def isDivisible(self, s): return int(int(s, 2) % 3 == 0) def isDivisible(self, s): pos, even, odd = 0, 0, 0 for i in s: if ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER IF VAR VAR ST...
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): n = len(s) even_sum = odd_sum = 0 for i in range(n - 1, -1, -1): if s[i] == "1": if (n - i - 1) % 2 == 0: even_sum += 1 else: odd_sum += 1 return (abs(even_s...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): oddsetbits, evensetbits = 0, 0 n = len(s) for i, c in enumerate(s): if c == "1": if i & 1: oddsetbits += 1 else: evensetbits += 1 return 1 if not abs(oddsetb...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): i = 0 n = len(s) s = s[::-1] ans = 0 j = 1 num = 1 while i < n: if s[i] == "1": ans += num i += 1 if num == 1: num = 2 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER NUMBER NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): e = 0 o = 0 for i in range(len(s)): if i % 2 == 0: e += int(s[i]) else: o += int(s[i]) diff = abs(e - o) if diff % 3 == 0: return 1 else: return ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): number = 0 k = len(s) - 1 for i in range(len(s)): number = number + int(s[i]) * (1 << k) k = k - 1 if number % 3 == 0: return 1 else: return 0
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER
Given a number in its binary form find if the given binary number is a multiple of 3. It is recommended to finish the task using one traversal of input binary number. Example 1: Input: S = "0011" Output: 1 Explanation: "0011" is 3, which is divisible by 3. Example 2: Input: S = "100" Output: 0 Explanation: "100"'s deci...
class Solution: def isDivisible(self, s): num = 0 for i in s: num = num * 2 + int(i) return int(num % 3 == 0) def isDivisible(self, s): return int(int(s, 2) % 3 == 0)
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,3,2] Output: 3 Example 2: Input: [0,1,...
class Solution: def singleNumber(self, nums): if not nums: return 0 seen = set([]) counts = {} for num in nums: if num in seen: counts[num] += 1 else: counts[num] = 1 seen.add(num) for key in...
CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR NUMBER RETURN VAR RETURN NUMBER
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,3,2] Output: 3 Example 2: Input: [0,1,...
class Solution: def singleNumber(self, nums): nums.sort() if len(nums) < 3: return nums[0] for i in range(0, len(nums) - 1, 3): if nums[i] != nums[i + 2]: return nums[i] return nums[-1]
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR RETURN VAR NUMBER
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,3,2] Output: 3 Example 2: Input: [0,1,...
class Solution: def singleNumber(self, nums): counts = {} for num in nums: if num not in counts: counts[num] = 1 else: counts[num] += 1 for k, v in list(counts.items()): if v == 1: return k
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER RETURN VAR
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,3,2] Output: 3 Example 2: Input: [0,1,...
class Solution: def singleNumber(self, nums): zero = 0 one = 0 for num in nums: one, zero = (one ^ num & zero) & ~(~zero & one & num), (zero ^ num) & ~( ~zero & one & num ) return zero
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,3,2] Output: 3 Example 2: Input: [0,1,...
class Solution: def singleNumber(self, nums): a = b = 0 for c in nums: a, b = a & ~b & ~c | ~a & b & c, ~a & b & ~c | ~a & ~b & c return a | b
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP VAR VAR
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,3,2] Output: 3 Example 2: Input: [0,1,...
class Solution: def singleNumber(self, nums): dict = {} for i in nums: if i in dict: dict[i] = dict[i] + 1 else: dict[i] = 1 for i in list(dict.keys()): if dict[i] == 1: return i return -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR NUMBER RETURN VAR RETURN NUMBER
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,3,2] Output: 3 Example 2: Input: [0,1,...
class Solution: def singleNumber(self, nums): res = {} for i in nums: if str(i) not in res: res[str(i)] = 1 else: res[str(i)] += 1 for i in res: if res[i] == 1: return int(i)
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER RETURN FUNC_CALL VAR VAR
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,3,2] Output: 3 Example 2: Input: [0,1,...
class Solution: def singleNumber(self, nums): if len(nums) == 1: return nums[0] seen = set() for a in nums: if a not in seen: seen.add(a) s1 = sum(nums) s2 = sum(seen) return int(s2 - (s1 - s2) / 2)
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,3,2] Output: 3 Example 2: Input: [0,1,...
class Solution: def singleNumber(self, nums): ones, twos = 0, 0 for i in nums: ones = ones ^ i & ~twos twos = twos ^ i & ~ones return ones
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,3,2] Output: 3 Example 2: Input: [0,1,...
class Solution: def singleNumber(self, nums): _dict = {} for num in nums: if num not in _dict: _dict[num] = 1 elif _dict[num] == 1: _dict[num] += 1 else: del _dict[num] return list(_dict.keys())[0]
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,3,2] Output: 3 Example 2: Input: [0,1,...
class Solution: def singleNumber(self, nums): ans = 0 for i in range(32): count = 0 for num in nums: if num >> i & 1: count += 1 ans |= count % 3 << i if ans >= 2**31: ans -= 2**32 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER NUMBER RETURN VAR
Given an array arr[ ] of positive integers, the task is to find the maximum XOR value of the elements from all the possible subsets. Example 1: Input: N = 3, arr[] = {2, 4, 5} Output: 7 Explanation: Subset {2, 5} has maximum xor Example 2: Input: N = 1, arr[] = {1} Output: 1 Explanation: Subset {1} has maximum xor Your...
class Solution: def maxXor(self, a, n): start = 0 for pos in range(16, -1, -1): bit = 1 << pos choose = None for i in range(start, n): if a[i] & bit: choose = i break if choose is not None: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR N...
Given an array arr[ ] of positive integers, the task is to find the maximum XOR value of the elements from all the possible subsets. Example 1: Input: N = 3, arr[] = {2, 4, 5} Output: 7 Explanation: Subset {2, 5} has maximum xor Example 2: Input: N = 1, arr[] = {1} Output: 1 Explanation: Subset {1} has maximum xor Your...
class Solution: def maxXor(self, a, n): index = 0 for i in range(31, -1, -1): maxindex = index maxele = -999999999 for j in range(index, n): if a[j] & 1 << i != 0 and a[j] > maxele: maxele = a[j] maxindex = ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VA...
Given an array arr[ ] of positive integers, the task is to find the maximum XOR value of the elements from all the possible subsets. Example 1: Input: N = 3, arr[] = {2, 4, 5} Output: 7 Explanation: Subset {2, 5} has maximum xor Example 2: Input: N = 1, arr[] = {1} Output: 1 Explanation: Subset {1} has maximum xor Your...
class Solution: def maxXor(self, arr, n): j = 0 for i in range(31, -1, -1): for k in range(j, n): if arr[k] & 1 << i: arr[k], arr[j] = arr[j], arr[k] break if arr[j] & 1 << i: for k in range(j + 1, n): ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR...
Given an array arr[ ] of positive integers, the task is to find the maximum XOR value of the elements from all the possible subsets. Example 1: Input: N = 3, arr[] = {2, 4, 5} Output: 7 Explanation: Subset {2, 5} has maximum xor Example 2: Input: N = 1, arr[] = {1} Output: 1 Explanation: Subset {1} has maximum xor Your...
class Solution: def maxXor(self, a, n): ix = 0 for i in range(31, -1, -1): mx = -1 * float("inf") mxIx = -1 for j in range(ix, n): if a[j] >> i & 1 and a[j] > mx: mx = a[j] mxIx = j el = a[mxIx] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ...
Given an array arr[ ] of positive integers, the task is to find the maximum XOR value of the elements from all the possible subsets. Example 1: Input: N = 3, arr[] = {2, 4, 5} Output: 7 Explanation: Subset {2, 5} has maximum xor Example 2: Input: N = 1, arr[] = {1} Output: 1 Explanation: Subset {1} has maximum xor Your...
class Solution: def maxXor(self, a, n): array = list(a) if not array: return 0 x = 0 while True: y = max(array) if y == 0: return x x = max(x, x ^ y) array = [min(z, z ^ y) for z in array]
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR
Given an array arr[ ] of positive integers, the task is to find the maximum XOR value of the elements from all the possible subsets. Example 1: Input: N = 3, arr[] = {2, 4, 5} Output: 7 Explanation: Subset {2, 5} has maximum xor Example 2: Input: N = 1, arr[] = {1} Output: 1 Explanation: Subset {1} has maximum xor Your...
class Solution: def maxXor(self, a, n): idx = 0 for i in range(31, -1, -1): maxidx, maxval = idx, -1 for j in range(idx, n): if a[j] & 1 << i != 0 and a[j] > maxval: maxval, maxidx = a[j], j if maxval < 0: conti...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR V...
Given an array arr[ ] of positive integers, the task is to find the maximum XOR value of the elements from all the possible subsets. Example 1: Input: N = 3, arr[] = {2, 4, 5} Output: 7 Explanation: Subset {2, 5} has maximum xor Example 2: Input: N = 1, arr[] = {1} Output: 1 Explanation: Subset {1} has maximum xor Your...
class Solution: def maxXor(self, a, n): start = 0 for i in range(18, -1, -1): ma = -1 k = -1 for j in range(start, n): if a[j] & 1 << i and (ma == -1 or ma < a[j]): ma = a[j] k = j if k == -1: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL...
Given an array arr[ ] of positive integers, the task is to find the maximum XOR value of the elements from all the possible subsets. Example 1: Input: N = 3, arr[] = {2, 4, 5} Output: 7 Explanation: Subset {2, 5} has maximum xor Example 2: Input: N = 1, arr[] = {1} Output: 1 Explanation: Subset {1} has maximum xor Your...
class Solution: def maxXor(self, a, n): BITS = 32 ind = 0 offset = 0 for offset in range(BITS - 1, -1, -1): maxInd = ind maxVal = -1 for i in range(ind, n): val = a[i] if val > 0 and 1 << offset & val != 0 and val >...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VA...
Given an array arr[ ] of positive integers, the task is to find the maximum XOR value of the elements from all the possible subsets. Example 1: Input: N = 3, arr[] = {2, 4, 5} Output: 7 Explanation: Subset {2, 5} has maximum xor Example 2: Input: N = 1, arr[] = {1} Output: 1 Explanation: Subset {1} has maximum xor Your...
class Solution: def maxXor(self, a, n): index = 0 for i in range(31, -1, -1): max_ind = index max_ele = -2147483648 for j in range(index, n): if a[j] & 1 << i and a[j] > max_ele: max_ele = a[j] max_ind = j ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CAL...
Given an array arr[ ] of positive integers, the task is to find the maximum XOR value of the elements from all the possible subsets. Example 1: Input: N = 3, arr[] = {2, 4, 5} Output: 7 Explanation: Subset {2, 5} has maximum xor Example 2: Input: N = 1, arr[] = {1} Output: 1 Explanation: Subset {1} has maximum xor Your...
class Solution: def maxXor(self, a, n): index = 0 for i in range(31, -1, -1): el = -99999999 mi = index for j in range(index, n, 1): sb = a[j] >> i & 1 if sb != 0 and el < a[j]: el = a[j] mi ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VA...
Given an array arr[ ] of positive integers, the task is to find the maximum XOR value of the elements from all the possible subsets. Example 1: Input: N = 3, arr[] = {2, 4, 5} Output: 7 Explanation: Subset {2, 5} has maximum xor Example 2: Input: N = 1, arr[] = {1} Output: 1 Explanation: Subset {1} has maximum xor Your...
class Solution: def maxXor(self, a, n): currIndex = 0 for bit in range(31, -1, -1): maxElement, maxIndex = float("-inf"), currIndex for k in range(currIndex, n): if a[k] & 1 << bit and a[k] > maxElement: maxElement = a[k] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VA...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): mod = pow(10, 9) + 7 total = 0 for i in range(0, 32): count = 0 for v in A: if v & 1 << i: count += 1 total = (total + count * (N - count) * 2) % mod return total
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR RETURN VAR
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): ans = 0 bit1s = [0] * 32 for i in range(N): j = 0 k = j while A[i] > 0: bit1s[k] += A[i] & 1 A[i] = A[i] >> 1 k = k + 1 for i in range(32): ans ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_O...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): ans = 0 for i in range(31, -1, -1): count_1 = 0 count_0 = 0 for ele in A: binary_no = bin(ele)[2:] l = len(binary_no) zero_str = "" for _ in range(32 - l): ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR VAR STR...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): res = 0 for i in range(32): count1 = 0 for j in range(N): bit = 1 << i if A[j] & bit == 0: count1 += 1 res += count1 * (N - count1) * 2 return res % (10**9 + 7)
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
def countNoOfBits(num): count = 0 while num > 0: num = num >> 1 count += 1 return count class Solution: def countBits(self, N, A): maxBits = countNoOfBits(max(A)) count1 = 0 count0 = 0 mask = 1 ans = 0 while maxBits > 0: for ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMB...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): ans = 0 for mask in range(31): ones = 0 zeros = 0 for i in range(N): if A[i] & 1 << mask: ones += 1 else: zeros += 1 ans = ans + 2 * (on...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, n, arr): ans = 0 for i in range(0, 32): count = 0 for j in range(0, n): if arr[j] & 1 << i: count += 1 ans += count * (n - count) * 2 return ans % 1000000007
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR NUMBER
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): mod = 1000000007 ans = 0 for i in range(31): count = 0 for j in A: if j & 1 << i: count += 1 ans += count * (N - count) * 2 ans %= mod return ans
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR RETURN VAR
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, nums): mask = 1 ans = 0 for i in range(32): cnt = 0 for num in nums: if num & mask: cnt += 1 ans += 2 * (cnt * (N - cnt)) mask <<= 1 return ans % int(10**9 + 7)
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR BIN_OP VAR VAR VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
MOD = 10**9 + 7 class Solution: def countBits(self, N, A): def _calc(bit): c1 = c0 = 0 for v in A: if v & bit: c1 += 1 else: c0 += 1 return c1 * c0 * 2 ans = 0 maxv = max(A) ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NU...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): maxi = 1000000000.0 + 7 ans = 0 for i in range(0, 32): cnt = 0 for j in range(N): if A[j] & 1 << i != 0: cnt += 1 ans = (ans + cnt * (N - cnt) * 2) % maxi return int(an...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR IF VAR STRING ASSIG...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, n, x): bits = 32 z = [(0) for i in range(32)] for i in x: s = bin(i)[2:].zfill(32) for j in range(32): if s[j] == "1": z[j] += 1 ans = 0 mo = 10**9 + 7 for i in x: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VA...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def f(self, n): s = 0 for i in range(32): if n & 1 == 1: s += 1 n >>= 1 return s def countBits(self, N, A): s = 0 MAX = 1000000007 for i in range(32): c = 0 for j in range(N): ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): res = 0 for i in range(0, 32): count = 0 for val in A: if val & 1 << i != 0: count += 1 off = N - count diff = count * off * 2 res += diff return res % ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN BIN_OP VAR NUMBER
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): M = 1000000000.0 + 7 res = 0 for i in range(32): z = 0 for j in range(N): if A[j] & 1 << i: z += 1 res += z * (N - z) * 2 return int(res % M)
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): bits = [[(0) for i in range(32)], [(0) for i in range(32)]] for i in A: power = 0 while i > 1: bits[i % 2][power] += 1 i //= 2 power += 1 bits[1][power] += 1 fo...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FU...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
from itertools import combinations class Solution: def countBits(self, N, A): s = 0 mod = 10**9 + 7 for i in range(0, 32): count = 0 for j in range(0, N): if A[j] & 1 << i: count += 1 s += count * (N - count) * 2 % mo...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR VAR RETURN VAR
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
MOD = int(1000000000.0 + 7) class Solution: def countBits(self, N, A): ans = 0 for i in range(31, -1, -1): setbits = 0 for j in A: if j & 1 << i: setbits += 1 ans += 2 * setbits * (N - setbits) ans %= MOD ...
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR VAR VAR RETURN VAR
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): i = 0 count = 0 while i < 32: setbits = 0 for ele in A: if ele & 1 << i: setbits += 1 count += setbits * (N - setbits) * 2 i += 1 return count % (10**9 + 7)
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): arr = [0] * 35 for i in A: pos = 0 while i: if i & 1: arr[pos] += 1 pos += 1 i = i >> 1 count = 0 for i in arr: count = (count + i * (N ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER RETURN VAR
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): ans = 0 for bit in range(32): count = 0 for i, el in enumerate(A): if el & 1 << bit: ans += (i - count) % (10**9 + 7) count += 1 else: ans +...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NU...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, n, arr): ans = 0 mod = 1000000000.0 + 7 for i in range(32): zero, one = 0, 0 for num in arr: if num & 1 << i: one += 1 else: zero += 1 ans += int(o...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP NUMBER V...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): m = 1000000007 cnt = 0 maxi = max(A) z = len(bin(maxi)[2:]) li = [bin(x)[2:].zfill(z) for x in A] l = [(0) for i in range(z)] for x in li: i = 0 for ch in x: if ch == "0": ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR VAR NUMBER VAR NUMBER FOR VA...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): mod = 10**9 + 7 res = 0 for i in range(32): cur = 1 << i ones = 0 for j in A: if j & cur: ones += 1 res += 2 * ones * (N - ones) return res % mod
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): max_ele = max(A) pos = 0 while max_ele > 0: max_ele = max_ele >> 1 pos += 1 final_count = 0 p = 10**9 + 7 for i in range(pos): zero_count = 0 mask = 1 << i for ele ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR B...
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): c = 0 m = pow(10, 9) + 7 for i in range(32): set0 = 0 set1 = 0 for i in range(N): if A[i] & 1: set1 += 1 else: set0 += 1 A[i...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): ans = 0 for i in range(31, -1, -1): count_1 = 0 count_0 = 0 for ele in A: if ele & 1 << i: count_1 += 1 else: count_0 += 1 ans = ans + c...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER
We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since binary representation of 2 and 7 are 010 and 111, respectively. The first and the third bit differ, so f (2, 7) = 2. You are given an array A of N integers, A_{1}, A_{2} ,…, A_{N}. Find sum...
class Solution: def countBits(self, N, A): res = 0 MOD = 10**9 + 7 for i in range(32): bt = 1 << i c = 0 for v in A: if v & bt: c += 1 res = (res + 2 * c * (N - c)) % MOD return res % MOD
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR VAR RETURN BIN_OP VAR VAR