description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:
word contains the first letter of puzzle.
For each letter in word, that letter is in puzzle.
For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage"; while invalid word... | class Solution:
def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]:
class TrieNode:
def __init__(self):
self.children = collections.defaultdict(TrieNode)
self.word_inds = []
def add(self, x, word_ind):
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR... |
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:
word contains the first letter of puzzle.
For each letter in word, that letter is in puzzle.
For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage"; while invalid word... | class Solution:
def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]:
cc = collections.Counter()
for w in words:
cc[tuple(sorted(set(list(w))))] += 1
res = []
for pzl in puzzles:
possible_sets = [set([pzl[0]])]
for i in... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR VAR VAR ASSIGN VAR FU... |
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:
word contains the first letter of puzzle.
For each letter in word, that letter is in puzzle.
For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage"; while invalid word... | class Solution:
def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]:
count = collections.Counter()
for word in words:
n = 0
for w in word:
n = n | 1 << ord(w) - ord("a")
count[n] += 1
result = []
for pu... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VA... |
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:
word contains the first letter of puzzle.
For each letter in word, that letter is in puzzle.
For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage"; while invalid word... | class Solution:
def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]:
wdict = defaultdict(int)
def getbitmask(word):
mask = 0
for w in word:
i = ord(w) - ord("a")
mask |= 1 << i
return mask
op ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL V... |
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:
word contains the first letter of puzzle.
For each letter in word, that letter is in puzzle.
For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage"; while invalid word... | class Solution:
def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]:
dic = {}
for word in words:
cur = dic
for c in word:
if c not in cur:
cur[c] = {}
cur = cur[c]
if "*" not in cur:... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR IF STRING VAR ASSIGN VAR STRING NUMBER VAR STRING NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR IF STRING VAR VAR VAR VAR VAR STRING FOR ... |
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:
word contains the first letter of puzzle.
For each letter in word, that letter is in puzzle.
For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage"; while invalid word... | class Solution:
def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]:
def generate(n):
res = [0]
cur = 1
while n:
if n & 1 == 1:
res += [(i + cur) for i in res]
n >>= 1
cur <... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING RETURN VAR ASSIGN VA... |
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:
word contains the first letter of puzzle.
For each letter in word, that letter is in puzzle.
For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage"; while invalid word... | class Solution:
def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]:
counter = {}
for word in words:
mask = self.to_int(word)
if mask not in counter:
counter[mask] = 0
counter[mask] += 1
output = []
for... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN... |
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:
word contains the first letter of puzzle.
For each letter in word, that letter is in puzzle.
For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage"; while invalid word... | class Solution:
def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]:
words = [frozenset(word) for word in words if len(set(word)) <= 7]
counter = Counter(words)
res = []
for p in puzzles:
pre = (p[0],)
t = set(p[1:])
t... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN 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 ... |
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:
word contains the first letter of puzzle.
For each letter in word, that letter is in puzzle.
For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage"; while invalid word... | class Solution:
def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]:
count = collections.Counter(frozenset(w) for w in words)
res = []
for p in puzzles:
subs = [p[0]]
for c in p[1:]:
subs += [(s + c) for s in subs]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR VAR |
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:
word contains the first letter of puzzle.
For each letter in word, that letter is in puzzle.
For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage"; while invalid word... | class Solution:
def conv(self, c):
return ord(c) - ord("a")
def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]:
first_letters = {chr(c): set([]) for c in range(ord("a"), ord("z") + 1)}
word_masks = {}
for i, w in enumerate(words):
mask ... | CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR LIST VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VA... |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
for i in range(1, n):
x = bin(i)[2:].count("1")
if i + x == n:
return 0
return 1 | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
low = 0
high = n
for i in range(n, 0, -1):
count = 0
mask = 1
num = i
while num:
if num & mask == 1:
count += 1
num >>= 1
if i + count == n:... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
for i in range(n):
cb = bin(i).count("1")
if i + cb == n:
return 0
return 1
if __name__ == "__main__":
T = int(input())
for i in range(T):
n = int(input())
ob = Solution()
ans = ob.is_bl... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FU... |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def setBits(self, N):
cnt = 0
while N != 0:
N = N & N - 1
cnt += 1
return cnt
def is_bleak(self, n):
for i in range(1, n):
b = self.setBits(i) + i
if b == n:
return 0
return 1 | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
dp = [0] * (n + 1)
for i in range(1, n):
if i % 2:
dp[i] = dp[i - 1] + 1
else:
dp[i] = dp[i // 2]
if i + dp[i] == n:
return 0
return 1 | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
m = len(bin(n)[2:])
for i in range(1, m + 1):
if sum(item == "1" for item in bin(n - i)[2:]) == i:
return 0
return 1 | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
for _ in range(n):
flag = 0
if n > 14:
s = n - 14
else:
s = 1
for i in range(s, n):
if i + bin(i)[2:].count("1") == n:
flag = 1
brea... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING VAR ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def setbit(self, i):
c = 0
while i:
i = i & i - 1
c += 1
return c
def is_bleak(self, n):
for j in range(n - 1, 0, -1):
a = self.setbit(j)
if n - a == j:
return 0
return 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
a = 1
i = 1
while a < n:
a *= 2
i += 1
for x in range(n - i, n):
if x + self.countSetBits(x) == n:
return 0
return 1
def countSetBits(self, x):
count = 0
while x >... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
def countSetbit(n):
count = 0
while n:
count += n & 1
n >>= 1
return count
a = n - 17
m = 1
for i in range(a, n):
if i > 0 and i + countSetbit(i) == n:
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def count_set(self, x):
count = 0
while x:
count += x & 1
x >>= 1
return count
def is_bleak(self, n):
for i in range(n, 0, -1):
if i + self.count_set(i) == n:
return 0
return 1 | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def set_bits(self, n):
cnt = 0
while n:
if n & 1:
cnt += 1
n = n >> 1
return cnt
def log2(self, n):
cnt = 0
n = n - 1
while n:
n = n >> 1
cnt += 1
return cnt
def is_blea... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VA... |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def check(self, x):
cnt = 0
while x:
x = x & x - 1
cnt += 1
return cnt
def is_bleak(self, n):
if n == 1:
return 1
ans = 1
for i in range(1, n):
if i + self.check(i) == n:
ans = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
z = n
c = 0
while z > 0:
z = z // 2
c = c + 1
mina = n - c
for i in range(n - c, n):
z = i
sb = 0
while z > 0:
a = z % 2
z = z // 2
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSI... |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
z = n
c = 0
while z > 0:
z = z // 2
c = c + 1
mina = n - c
for i in range(n - c, n):
z = i
sb = 0
while z > 0:
a = z % 2
z = z // 2
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSI... |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
def countSetBits(i):
a = "{0:b}".format(i)
return a.count("1")
for i in range(0, n):
if i + countSetBits(i) == n:
return 0
return 1
if __name__ == "__main__":
T = int(input())
for i in ran... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR RETURN FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_C... |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
num_bits = 32
def count_set_bits(self, x):
set_bits = 0
while x:
set_bits += 1
x = x & x - 1
return set_bits
def is_bleak(self, n):
x = max(1, n - self.num_bits)
while x < n:
if x + self.count_set_bits(x) == n:
... | CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR WHILE VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
def f(a):
cnt = 0
while a > 0:
cnt += 1
a = a & a - 1
return cnt
for i in range(n - 32, n):
if f(i) + i == n:
return 0
return 1 | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | def count_set_bits(n):
ret = 0
while n:
if n & 1:
ret += 1
n >>= 1
return ret
class Solution:
def is_bleak(self, n):
a = 0
for j in range(14, -1, -1):
if n > j:
a = j
break
for m in range(n - a, n):
... | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
for i in range(1, n + 1):
x = i
z = bin(i).replace("0b", "")
x1 = z.count("1")
if int(x1) + x == n:
return 0
else:
return 1 | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | def csb(n):
b = bin(n).replace("b", "")
return b.count("1")
class Solution:
def is_bleak(self, n):
if n == 1:
return 1
for i in range(n):
if i + csb(i) == n:
return 0
return 1 | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING RETURN FUNC_CALL VAR STRING CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
def findBits(x):
cnt = 0
while x:
x = x & x - 1
cnt += 1
return cnt
for i in range(1, n + 1):
if i + findBits(i) == n:
return 0
return 1 | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
l, r = 1, n
for i in range(1, n + 1):
if i + self.countSetBits(i) == n:
return 0
return 1
def countSetBits(self, num):
cnt = 0
while num != 0:
num = num & num - 1
cnt += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def countSetBits(self, x):
count = 0
while x:
x = x & x - 1
count = count + 1
return count
def ceilLog2(self, x):
count = 0
x = x - 1
while x > 0:
x = x >> 1
count = count + 1
return count
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL... |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
d = {}
for i in range(10**4):
temp = i
count = 0
ans = 0
while temp:
temp = temp & temp - 1
count += 1
ans = i + count
d[ans] = i
def is_bleak(self, n):
if n in self.d:
return 0
return 1 | CLASS_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
if n == 1:
return 1
else:
for i in range(n - 1, 0, -1):
t = i
count = 0
while t > 0:
t = t & t - 1
count = count + 1
if count + i ==... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def set_bits(self, n):
bin_num = bin(n).replace("Ob", "")
set_bits = str(bin_num).count("1")
return set_bits
def is_bleak(self, n):
for i in range(n):
if i + self.set_bits(i) == n:
return 0
return 1 | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def total_bits(self, m):
res = 0
while m:
res += 1
m //= 2
return res
def set_bits(self, m):
res = 0
while m:
res += m % 2
m //= 2
return res
def is_bleak(self, n):
for num in range(max... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
table = [(-1) for i in range(10**4 + 1)]
def countSetBits(self, n):
if self.table[n] != -1:
return self.table[n]
set_bits = 0
while n:
if n & 1:
set_bits += 1
n = n >> 1
self.table[n] = set_bits
return s... | CLASS_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMB... |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | def countSetBits(num):
count = 0
while num > 0:
mask = num - 1
num &= mask
count += 1
return count
class Solution:
def is_bleak(self, n):
for ele in range(n):
if ele + countSetBits(ele) == n:
return 0
else:
return 1 | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
for i in range(n - 1, 0, -1):
c = 0
t = i
while t > 0:
t = t & t - 1
c += 1
x1 = c
if n == x1 + i:
return 0
return 1 | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
res = 0
num = 1
while num < n:
res = 0
binary = str(bin(num)[2:])
ones = binary.count("1")
res = num + ones
if res == n:
return 0
num += 1
return 1
if __n... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR ... |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
flag = 1
for i in range(n, 0, -1):
b = self.setbit(i) + i
if b == n:
flag = 0
break
return flag
def setbit(self, n):
count = 0
while n > 0:
if n & 1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
c = 1
for i in range(n):
if i + bin(i).count("1") == n:
c = 0
break
return c | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR FUNC_CALL FUNC_CALL VAR VAR STRING VAR ASSIGN VAR NUMBER RETURN VAR |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def countSetBits(self, x):
k = bin(x).replace("b", "")
return k.count("1")
def is_bleak(self, n):
for x in range(n):
if self.countSetBits(x) + x == n:
return 0
return 1 | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING RETURN FUNC_CALL VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
dp = [0] * (10**4 + 1)
dp[1] = 1
dp[2] = 1
dp[3] = 2
for i in range(n):
dp[i] = dp[i // 2]
if i % 2:
dp[i] += 1
for i in range(n):
if i + dp[i] == n:
return 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR RETURN NUM... |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def sol(self, num):
ans = 0
while num:
num = num & num - 1
ans = ans + 1
return ans
def is_bleak(self, n):
for i in range(1, n):
if i + self.sol(i) == n:
return 0
return 1 | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | def setb(n):
return bin(n).count("1")
class Solution:
def is_bleak(self, n):
for i in range(1, n):
if i + setb(i) == n:
return 0
return 1 | FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
l = n // 2
r = n
ans = 1
while r:
mid_bits = setBits(r)
if n == r + mid_bits:
ans = 0
break
r -= 1
return ans
def setBits(n):
count = 0
while n:
n = n... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR ... |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
for i in range(n - 32, n, 1):
if i > 0 and n - i > 0 and bin(i).count("1") == n - i:
return 0
return 1 | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR STRING BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
for i in range(n - 1, 0, -1):
if i + self.count(i) == n:
return 0
return 1
def count(self, n):
cont = 0
while n:
cont += n & 1
n >>= 1
return cont | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR |
Given an integer, check whether it is Bleak or not.
A number n is called Bleak if it can be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is not equal to n for any non-negative number x.
Example 1:
Input: 4
Output: 1
Explanation: There is no any possible x
such that x + co... | class Solution:
def is_bleak(self, n):
for d in range(n // 2, n):
count = 0
x = d
while d > 0:
if d & (d & -d) > 0:
count += 1
d = d - (d & -d)
if x + count == n:
return 0
return 1 | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class TrieNode:
def __init__(self):
self.child = [0] * 2
class Trie:
def __init__(self):
self.root = TrieNode()
def insert(self, num):
curNode = self.root
for i in range(31, -1, -1):
setBit = 0
if 1 << i & num:
setBit = 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class TrieNode:
def __init__(self):
self.children = {}
class Trie:
def __init__(self):
self.root = TrieNode()
def insert(self, n):
temp = self.root
i = 31
while i >= 0:
bit = n >> i & 1
if bit not in temp.children:
temp.chi... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NU... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Trie:
def __init__(self):
self.left = None
self.right = None
def insert(n, l):
head = None
for i in range(n):
val = l[i]
current_node = head
for j in range(31, -1, -1):
present_bit = val >> j & 1
node = Trie()
if head is No... | CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE FUNC_DEF ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NU... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class node:
def __init__(self):
self.o = None
self.z = None
self.v = 0
class tri:
def __init__(self):
self.r = node()
def ins(self, a):
p = self.r
for i in range(31, -1, -1):
x = a & 1 << i
if x:
if p.o:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VA... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Solution:
def max_xor(self, arr, n):
xor = 0
ma = 0
s = set()
for i in range(30, -1, -1):
xor |= 1 << i
amax = ma | 1 << i
for j in range(n):
s.add(arr[j] & xor)
for j in s:
if j ^ amax in s:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR RET... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Solution:
def max_xor(self, nums, n):
m, mask = 0, 0
for i in range(32)[::-1]:
mask |= 1 << i
prefixes = {(n & mask) for n in nums}
tmp = m | 1 << i
if any(prefix ^ tmp in prefixes for prefix in prefixes):
m = tmp
return ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR RETURN VAR |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Trie:
def __init__(self):
self.root = {}
def put(self, num):
node = self.root
for i in range(30, -1, -1):
bit = num >> i & 1
if not bit in node:
node[bit] = {}
node = node[bit]
def get(self, num):
node = self.root
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASS... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class TrieNode:
def __init__(self):
self.bits = [None, None]
def ContainsKey(self, bit):
return self.bits[bit] != None
def Get(self, bit):
return self.bits[bit]
def PutKey(self, bit, node):
self.bits[bit] = node
class Trie:
def __init__(self):
self.node... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NONE NONE FUNC_DEF RETURN VAR VAR NONE FUNC_DEF RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Solution:
def max_xor(self, nums, n):
nums.sort(reverse=True)
m = len(str(bin(max(nums)))) - 2
dup_m = m
res = 0
bit = 1 << m - 1
for i in range(0, m):
dup_m, dic, temp = dup_m - 1, {}, []
temp = []
for i in range(0, n):
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER DICT LIST ASSIGN VAR LIST FOR VAR FUNC_CALL ... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class TrieNode:
def __init__(self):
self.zero = None
self.one = None
class Solution:
def max_xor(self, arr, n):
max_res = float("-inf")
root = TrieNode()
for ele in arr:
self.insertNode(ele, root)
for ele in arr:
max_res = max(max_res, ... | CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER IF V... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Node:
def __init__(self, val=None):
self.val = val
self.child = [None, None]
class Trie:
def __init__(self):
self.head = Node()
def insert(self, s):
def solve(head, s):
if len(s) == 0:
return
if head.child[int(s[0])] != None... | CLASS_DEF FUNC_DEF NONE ASSIGN VAR VAR ASSIGN VAR LIST NONE NONE CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN IF VAR FUNC_CALL VAR VAR NUMBER NONE ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NU... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class TrieNode:
def __init__(self):
self.children = [None] * 2
def insert(root, num):
curr = root
for i in range(31, -1, -1):
bit = num >> i & 1
if curr.children[bit] is None:
curr.children[bit] = TrieNode()
curr = curr.children[bit]
class Solution:
def ... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NONE ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR N... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class TrieNode:
def __init__(self):
self.child = {}
def increase(self, number):
cur = self
for i in range(31, -1, -1):
bit = number >> i & 1
if bit not in cur.child:
cur.child[bit] = TrieNode()
cur = cur.child[bit]
def findMax(se... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER I... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Solution:
def max_xor(self, nums, n):
overAllMax = 0
trie = Trie()
for num in nums:
trie.insert(num)
for num in nums:
currMax = trie.getMaxXor(num)
overAllMax = max(overAllMax, currMax)
return overAllMax
class Node:
def __init... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST NONE NONE FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_DEF RETURN NONE VAR VAR FUNC_DEF RETURN VAR VAR CL... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class node:
def __init__(self, data):
self.data = data
self.childs = {}
class trie:
def __init__(self):
self.head = node(0)
self.array = []
def insert(self, num):
curr = self.head
inbit = ""
for i in range(32, -1, -1):
if num & 1 << i:... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR DICT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR STRING IF STRING VAR ASSIGN VAR VAR STRING ASSIGN VAR STRING FUNC_CALL VAR STRING ... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class TrieNode:
def __init__(self):
self.bin_dict = {}
class Solution:
def Insert_Into_Trie(self, binary_str, root):
for bit in binary_str:
if bit in root.bin_dict:
root = root.bin_dict[bit]
else:
root.bin_dict[bit] = TrieNode()
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT CLASS_DEF FUNC_DEF FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | from sys import stdin
input = stdin.readline
class trie:
def __init__(self):
self.child = []
self.data = None
def insert(self, value):
self.child.append(trie())
self.child[-1].data = value
def make(self, value):
for x in self.child:
if x.data == valu... | ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NONE FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_DEF FOR VAR VAR IF VAR VAR RETURN VAR EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER FUNC_DEF NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER V... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class node:
def __init__(self, val=None):
self.val = val
self.one = None
self.zero = None
class Solution:
def __init__(self):
self.root = node(None)
def insert(self, x):
temp = self.root
for i in range(31, -1, -1):
bit = 1 << i & x
... | CLASS_DEF FUNC_DEF NONE ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR NONE FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR IF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN ... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Node:
def __init__(self):
self.children = dict()
def get(self, node):
return self.children[node]
def contains_key(self, key):
return key in self.children
def put(self, key):
self.children[key] = Node()
class Trie:
def __init__(self):
self.root = N... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_DEF RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Solution:
def max_xor(self, arr, n):
ans = 0
for i in range(31, -1, -1):
prefixs = set([(num >> i) for num in arr])
ans <<= 1
candidate = ans + 1
for pre in prefixs:
if candidate ^ pre in prefixs:
ans = candid... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR RETURN VAR |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Solution:
class Trie:
class TrieNode:
def __init__(self):
self.links = [None for i in range(2)]
def __init__(self):
self.root = self.TrieNode()
def getbit(self, num, ind):
return num >> ind & 1
def insert(self, num, maxl... | CLASS_DEF CLASS_DEF CLASS_DEF FUNC_DEF ASSIGN VAR NONE VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NONE ASSIG... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Solution:
def max_xor(self, arr, n):
prefix_mask = 0
ans = 0
for i in range(31, -1, -1):
prefix_mask |= 1 << i
prefixes = set([(prefix_mask & num) for num in arr])
newMax = ans | 1 << i
for pre in prefixes:
if pre ^ newMa... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR RETURN VAR |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Node:
def __init__(self):
self.zero = None
self.one = None
class Trie:
def __init__(self):
self.root = Node()
def insert(self, val):
tem = self.root
for i in range(31, -1, -1):
bit = val >> i & 1
if bit == 0:
if tem.z... | CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Solution:
def max_xor(self, arr, n):
r = 0
k = 0
for i in range(31, -1, -1):
m = r | 1 << i
s = set()
k = k | 1 << i
for j in arr:
l = j & k
s.add(l)
for pre in s:
if m ^ pre in... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER 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 ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR RETURN ... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class node:
def __init__(self):
self.c = {}
self.end = -1
class Trie:
def __init__(self):
self.r = node()
def insert(self, word, i):
iter = self.r
for c in word:
if c not in iter.c:
iter.c[c] = node()
iter = iter.c[c]
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR VAR STRING STRING STRING IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR ... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Trie:
def __init__(self):
self.children = {}
class Solution:
def __init__(self):
self.root = Trie()
def insert(self, num):
binary = bin(num)[2:].zfill(32)
curr = self.root
for c in binary:
if c not in curr.children:
curr.children... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR STRIN... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Solution:
def max_xor(self, arr, n):
trie = self.getTrie(arr, n)
freq = {}
for i in arr:
if i not in freq:
freq[i] = 1
else:
freq[i] += 1
ans = -1
for i in range(n):
num = arr[i]
binNum = b... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | SIZE = 19
class TrieNode:
def __init__(self):
self.children = [None] * 2
class Trie:
def __init__(self):
self.root = TrieNode()
def insert(self, N):
curr = self.root
for i in range(SIZE, -1, -1):
bit = N >> i & 1
if curr.children[bit] is None:
... | ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NONE ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR N... |
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array.
Example 1:
Input:
Arr = {25, 10, 2, 8, 5, 3}
Output: 28
Explanation:
The maximum result is 5 ^ 25 = 28.
Example 2:
Input :
Arr = {1, 2, 3, 4, 5, 6, 7}
Output : 7
Explanation :
The maximum result i... | class Solution:
def max_xor(self, arr, n):
ans = 0
mask = 0
for i in range(31, -1, -1):
mask |= 1 << i
temp = ans | 1 << i
s = set()
for j in arr:
num = j & mask
if num ^ temp in s:
ans = tem... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL 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... | def popcnt(x):
cnt = 0
while x != 0:
cnt += x & 1
x >>= 1
return cnt
class Solution:
def minVal(self, a, b):
nbits = popcnt(b)
x = a
mask = 1
while popcnt(x) < nbits:
x |= mask
mask <<= 1
mask = 1
while popcnt(x) ... | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER 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):
ans = 0
totalb = bin(b)[2:].count("1")
for i in range(31, -1, -1):
if totalb == 0:
return ans
if a & 1 << i:
ans |= 1 << i
totalb -= 1
for i in range(32):
if t... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR NUMBER RETURN VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER RETURN VAR IF BIN_OP VAR BIN_OP NUMBER 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 countSetBit(self, num):
i = 0
while num:
num = num & num - 1
i += 1
return i
def minVal(self, a, b):
i = self.countSetBit(b)
a = bin(a)[2:]
s = ""
for x in a:
if x == "1" and i != 0:
... | 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR NUMBER VAR STRING VAR NUMBER IF VAR STRING VAR STRING VAR STRING IF VAR NUMBER ASSIGN 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):
if b == 0:
return b
countb = 0
for i in bin(b).replace("0b", ""):
if i == "1":
countb += 1
z = 0
bina = bin(a).replace("0b", "")
for i in range(len(bina)):
if bina[i] == "1":
... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING FUNC_CAL... |
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_bits = 0
while b > 0:
set_bits += b % 2
b = b // 2
x = 0
for i in range(31, -1, -1):
if set_bits > 0 and a & 1 << i:
x = x ^ 1 << i
set_bits -= 1
if set_bits > 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN... |
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 bitcount(a):
c = 0
while a:
c += a & 1
a >>= 1
return c
def topBitsIn(a, n):
mask = 1
while mask < a:
mask <<= 1
res = 0
taken = 0
while taken < n:
if a & mask != 0:
res |= mask
taken += 1
mask >>= 1
if mask ==... | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR 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 countOnes(self, n):
res = 0
while n > 0:
if n % 2 == 1:
res += 1
n //= 2
return res
def minVal(self, a, b):
a1 = self.countOnes(a)
b1 = self.countOnes(b)
if a1 == b1:
return a
a2 = l... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL 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):
B = bin(b)[2:]
b_one = B.count("1")
A = bin(a)[2:]
ans = []
for i in range(len(A)):
if A[i] == "1":
if b_one:
ans.append("1")
b_one -= 1
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL 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):
set_bits = 0
while b > 0:
set_bits += b % 2
b = b // 2
s = []
for i in range(31, -1, -1):
bit = a & 1 << i
if bit and set_bits > 0:
s.append("1")
set_bits -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_... |
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 = bin(b)[2:]
z = x.count("1")
ans = []
for i in bin(a)[2:]:
if i == "0":
ans += [i]
elif z > 0:
ans += ["1"]
z -= 1
else:
ans += ["0"]
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR LIST VAR IF VAR NUMBER VAR LIST STRING VAR NUMBER VAR LIST 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):
if b == 0:
return 0
if a > b:
n = len(bin(a)) - 2
else:
n = len(bin(b)) - 2
a, b = bin(a)[2:], bin(b)[2:]
bc = b.count("1")
ac = a.count("1")
if ac == bc:
return int(a, 2)... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR RETURN F... |
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:]
a = "0" * (32 - len(a)) + a
x = bin(b)[2:].count("1")
ans = [(0) for _ in range(32)]
for i in range(32):
if x == 0:
break
if a[i] == "1":
ans[i] = 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER 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 minVal(self, a, b):
setbits = bin(b).count("1")
res = 0
for i in range(30, -1, -1):
if a & 1 << i and setbits:
res |= 1 << i
setbits -= 1
i = 0
while setbits:
if not res & 1 << i:
res... | 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 BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER 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):
l = []
c = 0
d = 0
y = a
while a != 0:
c += a % 2
l.append(str(a % 2))
a = a // 2
d = bin(b).count("1")
if d == c:
return y
elif d < c:
n = len(l)
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR 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 binaryToDecimal(self, binary_num):
dec_num = 0
m = 1
for i in range(len(binary_num) - 1, -1, -1):
digit = int(binary_num[i])
dec_num = dec_num + digit * m
m = m * 2
return dec_num
def minVal(self, A, B):
a = []
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP 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):
b = bin(b)[2:]
a = bin(a)[2:]
c = 0
for i in b:
if i == "1":
c += 1
arr = [(0) for i in range(len(a))]
i = 0
while i < len(a) and c > 0:
if a[i] == "1":
arr[i] = 1... | 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 NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER 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):
bit_a = 0
bit_b = 0
tmp_a = a
while tmp_a != 0:
bit_a += 1
tmp_a = tmp_a & tmp_a - 1
tmp_b = b
while tmp_b != 0:
bit_b += 1
tmp_b = tmp_b & tmp_b - 1
if bit_a == bit_b:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP 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):
B = b
A = a
count_set_bit_b = bin(b).count("1")
result = 0
i = 31
while i >= 0 and count_set_bit_b > 0:
if A & 1 << i > 0:
result |= 1 << i
count_set_bit_b -= 1
i -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP 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:
@staticmethod
def get_set_bit_indices(v: int):
indices, cur_index = [], 0
while v:
if v & 1:
indices.append(cur_index)
v >>= 1
cur_index += 1
return indices
def minVal(self, a: int, b: int):
if b == 0:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR LIST NUMBER WHILE VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.