description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
temp = bin(a).count("1") - bin(b).count("1")
ans = a
if temp == 0:
return ans
elif temp > 0:
for i in range(32):
if not temp:
break
if 1 << i & a:
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR IF BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR IF BIN_OP BIN_OP NUMBE... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
s1 = bin(a)[2:]
s2 = bin(b)[2:]
c1 = s1.count("1")
c2 = s2.count("1")
if c1 == c2:
return a
elif c1 > c2:
k = c2
d = ""
i = 0
while k and i < len(s1):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR STRING VAR STRIN... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def count(self, n):
count = 0
while n:
count, n = count + 1, n & n - 1
return count
def minVal(self, a, b):
a_count = self.count(a)
b_count = self.count(b)
a_bin = bin(a)[2:]
if b_count <= a_count:
a_bin = a_bin[::... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER STRING STRING BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CA... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
setbit = bin(b).count("1")
ans = 0
for i in range(31, -1, -1):
if setbit:
mask = 1 << i
if a & mask:
ans |= mask
setbit -= 1
for i in range(0, 31):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER RETUR... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
c = b
bit = 0
while c > 0:
bit += c & 1
c >>= 1
l = []
for i in range(30, -1, -1):
if 1 << i & a:
l.append(1)
else:
l.append(0)
l = l[::-1]
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST N... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def countSetBits(self, n):
count = 0
while n:
n = n & n - 1
count += 1
return count
def minVal(self, a, b):
x = a
diff = self.countSetBits(b) - self.countSetBits(a)
mask = 1
if diff >= 0:
while diff:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR IF VAR ... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
setBits = bin(b).count("1")
ans = 0
for i in range(30, -1, -1):
mask = 1 << i
s = a & mask
if s and setBits > 0:
ans |= 1 << i
setBits -= 1
for i in range(31):
if ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_O... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
m, n = a, b
c, d = 0, 0
lna = 0
while m:
if m & 1:
c += 1
m = m >> 1
lna += 1
while n:
if n & 1:
d += 1
n = n >> 1
if c == d:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def cout(self, a):
p = bin(a)[2:]
return p.count("1")
def minVal(self, a, b):
ma = self.cout(a)
mb = self.cout(b)
if ma == mb:
return a
elif ma > mb:
k = ma - mb
while k:
a = a - (a & ~(a - 1))
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR VAR AS... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
b1 = bin(b)
b1 = b1[2 : len(b1)]
count = 0
for i in b1:
if i == "1":
count += 1
a1 = bin(a)
a1 = a1[2 : len(a1)]
res = []
for i in a1:
res.append(i)
for i in range... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
n1 = bin(a)[2:]
ans = []
n2 = bin(b).count("1")
for i in n1:
if n2 == 0:
break
if i == "1":
ans.append("1")
n2 -= 1
else:
ans.append("0")
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING FOR VAR VAR IF VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
a_bin = []
b_bin = []
while a >= 1:
a_bin.append(a % 2)
a = a // 2
a_bin.reverse()
while b >= 1:
b_bin.append(b % 2)
b = b // 2
b_bin.reverse()
if a_bin.count(1) == b_bin.... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR VAR IF FU... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
def f(b):
cnt = 0
while b:
b &= b - 1
cnt += 1
return cnt
ans = []
bits = f(b)
l = list(bin(a)[2:])
for i in l:
if i == "1" and bits > 0:
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER VAR LIST STRING IF VAR STRING VAR NUMBER VAR STRING VAR NUMBER VAR LIST STRIN... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
def cnt(b):
c = 0
while b:
b = b & b - 1
c += 1
return c
ac = cnt(a)
ab = cnt(b)
d = abs(ac - ab)
if d == 0:
return a
elif ac > ab:
w... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER RETURN VAR IF VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
count_bit_b = 0
while b:
count_bit_b += b % 2
b //= 2
ans = 0
for i in range(31, -1, -1):
if a & 1 << i:
ans |= 1 << i
count_bit_b -= 1
if count_bit_b == 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP ... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | def count(num):
c = 0
while num > 0:
if num % 2 == 1:
c += 1
num = num // 2
return c
class Solution:
def minVal(self, a, b):
c1 = count(a)
c2 = count(b)
if c1 == c2:
return a
elif c1 > c2:
diff = c1 - c2
w... | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
a = bin(a)[2:]
b = bin(b)[2:]
count = 0
for i in b:
count += i == "1"
s = ["0" for i in range(len(a))]
for i in range(len(a)):
if a[i] == "1" and count > 0:
s[i] = "1"
cou... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR STRING ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
b_setbits = self.total_set_bits(b)
a_setbits = self.total_set_bits(a)
if a_setbits > b_setbits:
i = 0
remove_bits = a_setbits - b_setbits
while i < remove_bits:
a = a & a - 1
i += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR RET... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
set_in_b = bin(b)[2:].count("1")
set_in_a = bin(a)[2:].count("1")
bi_a = len(bin(a)[2:])
bi_b = len(bin(b)[2:])
if set_in_a == set_in_b:
return a
if set_in_a > set_in_b:
ans = list("0" * abs(bi_b - bi_a)... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR BI... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
ba = db(a)
c1 = ba.count("1")
c2 = db(b).count("1")
if c1 == c2:
return a
if c2 > c1:
n = ""
j = c2 - c1
n = [i for i in ba]
for i in range(len(ba) - 1, -1, -1):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR S... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def countBits(self, n):
cnt = 0
while n:
n &= n - 1
cnt += 1
return cnt
def minVal(self, a, b):
setbits = self.countBits(b)
ans = 0
for i in range(31, -1, -1):
bit = a & 1 << i
if bit:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN ... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
res = a
a1 = a
b1 = b
n = 0
m = 0
length = 0
while a1 > 0:
n += a1 % 2
length += 1
a1 //= 2
while b1 > 0:
m += b1 % 2
b1 //= 2
if n == m:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NU... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
a_bin = str(bin(a))
b_bin = str(bin(b))
a_bin = a_bin[2:]
b_bin = b_bin[2:]
cnt = 0
cnt1 = 0
for i in range(len(b_bin)):
if b_bin[i] == "1":
cnt = cnt + 1
for i in range(len(a_bin)):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR V... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
a1 = bin(a)[2:]
b1 = bin(b)[2:]
sb = 0
for i in b1:
if i == "1":
sb += 1
out = ""
f = 0
n = len(a1)
if sb >= n:
ans = 2**sb - 1
return ans
for i in ran... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | def countSetBits(num):
count = 0
while num > 0:
if num & 1 > 0:
count += 1
num = num >> 1
return count
def countNoOfBits(num):
count = 0
while num > 0:
num = num >> 1
count += 1
return count
class Solution:
def minVal(self, a, b):
setA... | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR 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 VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
sa, sb = 0, 0
na, nb = a, b
while na != 0:
sa += 1
na &= na - 1
while nb != 0:
sb += 1
nb &= nb - 1
na, nb = a, b
if sa == sb:
return a
elif sa > sb:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR B... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
a_setbits = bin(a)[2:].count("1")
b_setbits = bin(b)[2:].count("1")
diff = abs(a_setbits - b_setbits)
if a_setbits == b_setbits:
return a
elif a_setbits > b_setbits:
while diff:
a = a & a - 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR IF VAR VAR WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def count(self, a):
cnt = 0
while a:
a = a & a - 1
cnt += 1
return cnt
def fun(self, a, temp):
cnt = 0
i = 1
while temp > 0:
cnt += 1
if a & i > 0:
temp -= 1
i = i << 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP VAR BIN_OP NUMBER VAR FUNC_DEF AS... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
if b == 0:
return 0
setbit = 0
while b:
if b % 2:
setbit += 1
b = b // 2
flag = False
ans = 0
for i in range(31, -1, -1):
if not flag:
if setbit ==... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP NU... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
ca, cb = 0, 0
ba = [(0) for i in range(31)]
bb = [(0) for i in range(31)]
ans = [(0) for i in range(31)]
for i in range(31):
if b & 1 << i:
bb[i] = 1
cb += 1
if a & 1 << i:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NU... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def bitCount(self, a):
c = 0
for i in range(0, 34):
if a & 1 << i:
c += 1
return c
def minVal(self, a, b):
s = 0
x = self.bitCount(b)
for i in range(33, -1, -1):
if a & 1 << i and x != 0:
s ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER ... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
cb = 0
for i in range(32):
if 1 << i & b:
cb += 1
if cb == 0:
return 0
x = 0
for i in range(31, -1, -1):
if 1 << i & a:
x ^= 1 << i
cb -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER IF ... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def ones(self, n):
counter = 0
while n > 0:
counter += n % 2
n = n >> 1
return counter
def minVal(self, a, b):
o = self.ones(b)
bina = format(a, "b")
binb = format(b, "b")
binf = format(a, "b").zfill(max(len(binb),... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VA... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
c = 0
s1 = bin(a)
s2 = bin(b)
s1 = s1[2:]
s2 = s2[2:]
c = 0
for i in s2:
if i == "1":
c += 1
ans = 0
for i in range(31, -1, -1):
if i == c - 1:
ret... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP NUMBER B... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
setb = bin(b)[2:].count("1")
seta = bin(a)[2:].count("1")
ans = 0
for i in range(0, 32):
mask = 1 << i
set = a & mask
if set == 0 and setb > seta:
ans |= mask
setb -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR RETURN VAR |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
b1 = bin(a)
b2 = bin(b)
count2 = b2.count("1")
res = 0
x = b1[2:]
n = len(x)
count1 = x.count("1")
if count2 <= count1:
for i in range(n):
if count2 == 0:
break
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR STRING VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR N... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
x = 0
c = 0
k = 2**32
while k != 0:
if b & k == k:
c += 1
k = k >> 1
k = 2**32
while k != 0:
if a & k == k and c != 0:
x = x + k
c -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR... |
Given two integers A and B, the task is to find an integer X such that (X XOR A) is minimum possible and the count of set bit in X is equal to the count of set bits in B.
Example 1:
Input:
A = 3, B = 5
Output: 3
Explanation:
Binary(A) = Binary(3) = 011
Binary(B) = Binary(5) = 101
The XOR will be minimum when x = 3
i.e... | class Solution:
def minVal(self, a, b):
a = bin(a)[2:].zfill(32)
b = bin(b)[2:].zfill(32)
x = ["0" for i in range(32)]
cb = b.count("1")
i = 0
while cb and i < 32:
while i < 32 and a[i] == "0":
i += 1
if i == 32:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR STRING VA... |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
str_set = set()
for i in range(len(s) - k + 1):
str_set.add(str(s[i : i + k]))
for i in range(2**k):
formatter = "{0:0%sb}" % str(k)
if formatter.format(i) not in str_set:
retu... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER VAR |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
if k >= len(s):
return False
d = set()
num = 0
for i in range(k):
m = ord(s[i]) - ord("0")
num = num * 2 + m
d.add(num)
mask = (1 << k - 1) - 1
for i in range(k... | CLASS_DEF FUNC_DEF VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER FOR ... |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
def binary_code_of_length_k(k):
if k == 1:
return ["0", "1"]
t = binary_code_of_length_k(k - 1)
return [("0" + i) for i in t] + [("1" + i) for i in t]
k_string = binary_code_of_lengt... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR NUMBER RETURN LIST STRING STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP STRING VAR VAR VAR BIN_OP STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER VAR |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
if len(s) < k:
return False
substring_set = set()
need = 1 << k
for start in range(len(s) - k + 1):
ss = s[start : start + k]
if ss not in substring_set:
substring_set.... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER VAR |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
need = 2**k
_new = set()
for i in range(len(s) - k + 1):
var = s[i : i + k]
if var not in _new:
_new.add(var)
need -= 1
if need == 0:
return Tru... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER VAR |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
if len(s) < 2**k + k - 1:
return False
target = 2**k
seen = set()
cur_len = 0
for end in range(k, len(s) + 1):
chunk = s[end - k : end]
if chunk not in seen:
cu... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR... |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
nums = set()
for i in range(0, len(s) - k + 1):
nums.add(s[i : i + k])
if len(nums) == 2**k:
return True
return False | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER VAR |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
for i in range(2**k):
ss = bin(i)[2:].zfill(k)
if ss not in s:
return False
return True | CLASS_DEF FUNC_DEF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR RETURN NUMBER RETURN NUMBER VAR |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
st = set()
for i in range(k, len(s) + 1):
st.add(s[i - k : i])
if len(st) == 1 << k:
break
return len(st) == 1 << k | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
l = len(s)
r = set()
for i in range(0, l - k + 1):
r.add(s[i : i + k])
if len(r) == 2**k:
return True
for i in product(["0", "1"], repeat=k):
_ = "".join(i)
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR LIST STRING STRING VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VA... |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | from itertools import product
class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
p = product("01", repeat=k)
for sub in p:
if s.find("".join(sub)) == -1:
return False
return True | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER RETURN NUMBER RETURN NUMBER VAR |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
codes = set(format(i, f"0{k}b") for i in range(2**k))
found = [(False) for i in range(2**k)]
for i in range(len(s) - k + 1):
if s[i : i + k] in codes:
found[int(s[i : i + k], base=2)] = True
r... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR STRING VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR... |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
check = []
for kk in range(2**k):
t = bin(kk)[2:]
check.append("0" * (k - len(t)) + t)
ss = set()
for i in range(k, len(s) + 1):
ss.add(s[i - k : i])
for t in check:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR... |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
def Hash_Function(b):
num = list(b)
num.reverse()
total = 0
increment = 1
for item in num:
if item == "1":
total = total + increment
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR W... |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
arr_2 = ["0", "1"]
m = k - 1
while m != 0:
arr_2 = [("0" + i) for i in arr_2] + [("1" + i) for i in arr_2]
m -= 1
for i in range(2**k):
if arr_2[i] in s:
continue
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST STRING STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR VAR BIN_OP STRING VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR VAR RETURN NUMBER RETURN NUMBER VAR |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | def binary_strings(k):
res = []
stack = [""]
while stack:
s = stack.pop()
if len(s) == k:
res.append(s)
else:
stack.append(s + "0")
stack.append(s + "1")
return res
class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
s... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST STRING WHILE VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR STRING RETURN VAR CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL... |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
bins = {}
numbers = {}
st = s
print(k)
def bin2dec(a):
val = 0
for i in range(len(a)):
if a[i] == "1":
val += pow(2, len(a) - 1 - i)
return... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR N... |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
for i in range(2**k):
bin_value = (
bin(i)[2:]
if len(bin(i)[2:]) == k
else "0" * (k - len(bin(i)[2:])) + bin(i)[2]
)
if bin_value not in s:
ret... | CLASS_DEF FUNC_DEF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER VAR |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | from itertools import permutations
class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
from itertools import permutations
c = dict()
count = 0
for i in range(0, len(s) - k + 1):
out = ""
for j in range(i, i + k):
out = out + s[j]... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR NUMBER... |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
arr = list(s)
arr = [(ord(el) - 48) for el in arr]
length = 0
n = len(s)
curr = 0
h = {}
for i in range(n - 1, -1, -1):
length += 1
if length > k:
length -=... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBE... |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
codes = {format(i, f"0{k}b"): (False) for i in range(2**k)}
for i in range(len(s) - k + 1):
ss = s[i : i + k]
if ss in codes:
codes[ss] = True
return all(codes.values()) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING VAR STRING NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR |
Given a binary string s and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and... | class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
result = set()
for i in range(len(s) - k + 1):
val = s[i : i + k]
result.add(val)
if len(result) >= 2**k:
return True
else:
return False | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER VAR |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | n = int(input())
relMatrix = []
binArray = []
suggConn = 0
for i in range(0, n):
binValues = ["{0:04b}".format(int(x)) for x in input()]
relMatrix.append(binValues)
binArray.append(int("".join(binValues), 2))
for i in range(0, n):
for j in range(i, n):
if i != j and int(relMatrix[i][j]) == 0:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL... |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | n = int(input())
array = [input() for i in range(n)]
frndship = [int(x, 2) for x in array]
count = 0
limit = 0
for i in range(n):
for j in range(limit):
if array[i][j] == "0" and i != j and frndship[i] & frndship[j]:
count += 2
limit += 1
print(count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | import sys
i = int(sys.stdin.readline())
arr = []
comp = [0] * i
count = 0
for _ in range(i):
p = input()
arr.append(list(p))
comp[_] = int(p, 2)
for t in range(i):
for a in range(t):
if arr[t][a] == "0":
if comp[t] & comp[a]:
count += 2
print(count) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF B... |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | def check(a, b, n):
if a & b:
return True
return False
n = int(input())
l = []
ll = []
for _ in range(n):
x = input()
l.append(list(x))
ll.append(int(x, 2))
req = 0
for i in range(n):
for j in range(1 + i, n):
if l[i][j] == "0" and check(ll[i], ll[j], n):
req += 1
p... | FUNC_DEF IF BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL ... |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | n = int(input())
l = []
l2 = []
c = 0
m = []
for i in range(n):
f = input()
sub = set()
l2.append(f)
m.append(int(f, 2))
for i in range(n - 1):
for j in range(i + 1, n):
if l2[i][j] == "0" and m[i] & m[j] != 0:
c += 2
print(c) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR... |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | n = int(input())
a = [[(0) for _ in range(n)] for _ in range(n)]
bi = [(0) for _ in range(n)]
for i in range(n):
k = input()
a[i] = k
bi[i] = int(k, 2)
count = 0
for i in range(n):
for j in range(i + 1, n):
if a[i][j] == "0":
if bi[i] & bi[j]:
count += 1
print(count *... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN... |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | a = []
b = []
res = 0
n = int(input())
for i in range(n):
s = input()
a.append(list(s))
b.append(int(s, 2))
for i in range(n):
for j in range(i + 1, n):
if a[i][j] == "0" and b[i] & b[j] != 0:
res += 1
print(res * 2) | ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR STRING BIN_OP ... |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | t = int(input())
l = []
l1 = []
for i in range(t):
s = input()
l.append(s)
l1.append(int(s, 2))
j = 0
k = 0
cout = 0
while j < t - 1:
k = j + 1
while k < t:
if l[j][k] == "0" and l1[j] & l1[k] >= 1:
cout = cout + 2
k = k + 1
j = j + 1
print(cout) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR... |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | n = int(input())
arr = []
a = []
for a0 in range(n):
arr.append(input())
for i in arr:
a.append(int(i, base=2))
ans = 0
for i in range(len(a) - 1):
for j in range(i + 1, len(a)):
if arr[i][j] == "0":
if a[i] & a[j] != 0:
ans += 2
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF V... |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | a = int(input())
c = []
d = []
for i in range(a):
now = input()
c.append(now)
d.append(int(now, 2))
i = 0
for k in range(a):
for j in range(k + 1, a):
if c[k][j] != "1":
if int(d[k]) & int(d[j]):
i = i + 2
print(i) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR STRING IF BIN_OP FUNC_CALL V... |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | N = int(input())
matrix = []
is_friend = []
for i in range(0, N):
row = []
line = input()
is_friend.append(line)
matrix.append(int(line, 2))
count = 0
for i in range(0, N):
for j in range(i + 1, N):
if is_friend[i][j] != "1" and matrix[i] & matrix[j] > 0:
count += 2
print(count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VA... |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | n = int(input())
B = []
for _ in range(n):
x = input()
B.append(int(x, 2))
count = 0
J = 1 << n
for i in range(n):
j = 1
p = n - 1
while j != J:
if p == i:
j <<= 1
p -= 1
continue
if not B[i] & j:
if B[i] & B[p]:
count +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF ... |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | import sys
n = int(sys.stdin.readline())
adj_mat = []
ints = []
for ln_i in range(n):
adj_mat.append(sys.stdin.readline())
ints.append(int(adj_mat[ln_i], 2))
requests = 0
for i in range(n):
for j in range(i):
if adj_mat[i][j] == "0":
if ints[i] & ints[j]:
requests += 2
s... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR F... |
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. Ilya wants the world to be as connected as possible, so he wants t... | total = 0
friends = int(input())
adjmat = [0] * friends
binreps = [0] * friends
for line in range(friends):
sa = input()
adjmat[line] = sa
binreps[line] = int(sa, 2)
for i in range(friends - 1):
for j in range(i + 1, friends):
if adjmat[i][j] != "1":
if binreps[i] & binreps[j] != 0:
... | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR I... |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
def check(res, arr):
count = 0
for i in range(len(arr)):
if arr[i] & res == res:
count += 1
return count
ans = 0
for i in range(16, -1, -1):
res = ans | 1 << i
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
ans = 0
for i in range(21, -1, -1):
k = 1 << i
k = k | ans
cnt = 0
for i in range(N):
if arr[i] & k == k:
cnt += 1
if cnt >= 2:
ans = k
r... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
res = 0
for setbit in range(31, -1, -1):
x = res | 1 << setbit
c = 0
for i in arr:
if x & i == x:
c += 1
if c >= 2:
res = res | 1 << setbit
return re... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
lis = []
for i in range(31, -1, -1):
bitn = 1 << i
l = []
for j in arr:
if j & bitn:
l.append(j)
if len(l) >= 2:
lis.append(i)
arr = l
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def countAND(self, arr, N, X):
count = 0
for i in range(N):
if arr[i] & X == X:
count += 1
return count
def maxAND(self, arr, N):
res = 0
j = 16
while j + 1 > 0:
x = 1 << j
x += res
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, g, n):
ans = 0
st = len(bin(max(g))[2:])
for i in range(st, -1, -1):
k = 0
for x in g:
if x & 1 << i != 0 and x & ans == ans:
k += 1
if k > 1:
ans += 1 << i
retur... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
res = 0
count = 0
for i in range(32):
k = res | 1 << 31 - i
count = self.countKSetBit(arr, k)
if count >= 2:
res = k
return res
def countKSetBit(self, arr, k):
c = 0
fo... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
m = 1
res = 0
i = 31
while i >= 0:
res = res | m << i
count = 0
for ele in arr:
if res & ele == res:
count += 1
if count < 2:
res = res & res... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def checkBit(self, pattern, arr, N):
c = 0
for i in range(N):
if pattern & arr[i] == pattern:
c += 1
return c
def maxAND(self, arr, N):
res = 0
arr.sort()
k = int(math.log(arr[N - 1], 2))
for bit in range(k, -1... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR V... |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
def pat(pattern, arr, n):
count = 0
for i in arr:
if i & pattern == pattern:
count = count + 1
return count
res = 0
for i in range(31, -1, -1):
out = pat(res | 1 <... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
c = 1
res = 0
q = 0
for i in range(16, -1, -1):
c = 1 << i
d = 0
for j in arr:
if (res | c) & j == res | c:
d = d + 1
if d >= 2:
res = res | ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def checkIfTwoExists(self, arr, pattern):
count = 0
for num in arr:
if num & pattern == pattern:
count += 1
return count >= 2
def maxAND(self, arr, N):
ans = 0
for place in range(16, -1, -1):
pattern = ans | 1 << p... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
maxand = 0
maxbit = max(arr)
maxbit = maxbit.bit_length()
for bit in range(maxbit, -1, -1):
count = 0
for n in arr:
pattern = maxand | 1 << bit
if n & pattern == pattern:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF NUMBER VAR IF NUMBER VAR VAR BIN_OP NUMBER VAR RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | def checkBit(pattern, arr, n):
count = 0
for i in range(0, n):
if pattern & arr[i] == pattern:
count = count + 1
return count
def maxAN(arr, n):
res = 0
for bit in range(18, -1, -1):
count = checkBit(res | 1 << bit, arr, n)
if count >= 2:
res = res |... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR RETURN V... |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
if N <= 1:
return 0
m = arr[0]
for x in arr[1:]:
m = max(m, x)
numBits = 0
while m > 0:
numBits += 1
m //= 2
mask = 0
while numBits > 0:
mask |= 1 << numBits... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR N... |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
m = max(arr)
while m & m - 1 > 0:
m = m & m - 1
val = 0
j = m
while m > 0:
count = 0
for i in arr:
if j & i == j:
count += 1
if count > 1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN V... |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
max1 = 0
for i in range(31, -1, -1):
count = 0
z = max1 | 1 << i
for j in arr:
if j & z == z:
count += 1
if count >= 2:
max1 |= 1 << i
return max1 | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
def check(pattern, arr, n):
count = 0
for i in range(n):
if arr[i] & pattern == pattern:
count += 1
return count
res = 0
m = max(arr)
key = 0
for i in range(31... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBE... |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
val = 0
for i in range(16, -1, -1):
count = 0
for j in arr:
if j & val >= val and j & 1 << i:
count += 1
if count >= 2:
val += 1 << i
return val | 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 VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, n):
res = 0
for i in range(31, -1, -1):
if self.checkBit(res | 1 << i, arr, n):
res |= 1 << i
return res
def checkBit(self, pattern, arr, n):
count = 0
for i in range(n):
if pattern & arr[i] =... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
res = 0
for bits in range(16, -1, -1):
count = self.checkBits(res | 1 << bits, arr, N)
if count >= 2:
res |= 1 << bits
return res
def checkBits(self, pattern, arr, N):
count = 0
for i in a... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
if N == 1:
return 0
ans = ""
newArr = arr.copy()
for i in range(18):
flag = False
cnt = 0
arr = newArr.copy()
for ii in range(len(arr)):
if arr[ii] & 1 << 18 - i - 1... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP NUMBER V... |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
for i in range(31, -1, -1):
l = []
for j in arr:
if j & 1 << i != 0:
l.append(j)
if len(l) > 1:
arr = l
if len(arr) > 1:
ma = arr[0]
for i in arr... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR RETURN NUMBER |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
numbits = 0
mx = 0
for i in range(N):
mx = max(mx, arr[i])
while mx > 0:
numbits += 1
mx >>= 1
mask = 0
for i in range(numbits - 1, -1, -1):
mask = mask | 1 << i
cou... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_... |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, arr, N):
ans = 0
for i in range(16, -1, -1):
power = 1 << i
count = 0
for num in arr:
if num & ans == ans and num & power:
count += 1
if count >= 2:
ans += power
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR RETURN VAR |
Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair(arr_{i, }arr_{j}) from the array such that i != j.
Note: AND is bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8,12) has the Maximum AND Value 8.
Example 2:
I... | class Solution:
def maxAND(self, a, N):
res = 0
x = max(a)
h = math.floor(math.log2(x)) + 1
for i in range(h - 1, -1, -1):
pattern = res | 1 << i
count = 0
for j in range(len(a)):
if a[j] & pattern == pattern:
c... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR N... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.