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):
def countBits(x):
res = 0
while x > 0:
if x % 2:
res += 1
x //= 2
return res
def convert(x):
res = ""
while x > 0:
res = str(x % ... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL 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 minVal(self, a, b):
num_set_bits_b = bin(b)[2:].count("1")
a_bin_arr = list(bin(a)[2:])
ans = ""
for i in a_bin_arr:
if i == "1" and num_set_bits_b:
num_set_bits_b -= 1
ans += "1"
else:
ans +... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR VAR NUMBER VAR STRING VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR IF VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER 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 countBits(self, no):
count = 0
while no != 0:
if no & 1 != 0:
count += 1
no = no >> 1
return count
def minVal(self, a, b):
setbits = self.countBits(b)
result = 0
for i in reversed(range(32)):
... | CLASS_DEF 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER 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):
na = bin(a)[2:].count("1")
nb = bin(b)[2:].count("1")
output = a
num = 32 * "0"
num += bin(a)[2:]
i = 0
while na > nb:
if num[-i - 1] == "1":
output -= 2**i
na -= 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 VAR ASSIGN VAR BIN_OP NUMBER STRING VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER WHILE 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):
x = ""
c = bin(b).count("1")
q = bin(a)[2:]
if len(q) < len(bin(b)[2:]):
for i in range(len(bin(b)[2:]) - len(q)):
q = "0" + q
for i in range(len(q)):
if q[i] == "1":
if c > 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL 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):
if a == b:
return 0
x = bin(a)
y = bin(b)
c1 = x.count("1")
c2 = y.count("1")
x = 0
for i in range(0, 32):
m = 1 << i
k = a & m
if k == 0 and c2 > c1:
x |=... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR 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 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):
one_count = 0
while b > 0:
if b % 2 == 1:
one_count += 1
b //= 2
answer = 0
for i in range(32, -1, -1):
if one_count <= 0:
break
if 1 << i & a == 1 << i:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BI... |
Given an array arr[] of N positive integers. Find an integer denoting the maximum XOR subset value in the given array arr[].
Example 1:
Input :
N = 3
arr[] = {2, 4, 5}
Output : 7
Explanation :
The subset {2, 5} has maximum
subset XOR value.
Example 2 :
Input :
N= 3
arr[] = {9, 8, 5}
Output : 13
Explanation :
The ... | class Solution:
def maxSubsetXOR(self, arr, N):
if N == 0:
return 0
num = 0
while True:
maximum = float("-inf")
for i in range(N):
if maximum < arr[i]:
maximum = arr[i]
if maximum == 0:
retur... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR |
Given an array arr[] of N positive integers. Find an integer denoting the maximum XOR subset value in the given array arr[].
Example 1:
Input :
N = 3
arr[] = {2, 4, 5}
Output : 7
Explanation :
The subset {2, 5} has maximum
subset XOR value.
Example 2 :
Input :
N= 3
arr[] = {9, 8, 5}
Output : 13
Explanation :
The ... | class Solution:
def maxSubsetXOR(self, arr, n):
ind = 0
for i in range(31, -1, -1):
maxIndex = ind
maxElement = -(10**9)
for j in range(ind, n):
if arr[j] & 1 << i and arr[j] > maxElement:
maxIndex = j
maxEl... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR... |
Given an array arr[] of N positive integers. Find an integer denoting the maximum XOR subset value in the given array arr[].
Example 1:
Input :
N = 3
arr[] = {2, 4, 5}
Output : 7
Explanation :
The subset {2, 5} has maximum
subset XOR value.
Example 2 :
Input :
N= 3
arr[] = {9, 8, 5}
Output : 13
Explanation :
The ... | class Solution:
def maxSubsetXOR(self, a, n):
if n == 0:
return 0
x = 0
while 1:
y = max(a)
if y == 0:
return x
x = max(x, x ^ y)
a = [min(z, z ^ y) for z in a] | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR |
Given an array arr[] of N positive integers. Find an integer denoting the maximum XOR subset value in the given array arr[].
Example 1:
Input :
N = 3
arr[] = {2, 4, 5}
Output : 7
Explanation :
The subset {2, 5} has maximum
subset XOR value.
Example 2 :
Input :
N= 3
arr[] = {9, 8, 5}
Output : 13
Explanation :
The ... | class Solution:
def maxSubsetXOR(self, arr, N):
n = len(arr)
index = 0
for i in range(32, -1, -1):
max_index = index
max_value = -float("inf")
for j in range(index, n):
if arr[j] & 1 << i != 0 and arr[j] > max_value:
ma... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VA... |
Given an array arr[] of N positive integers. Find an integer denoting the maximum XOR subset value in the given array arr[].
Example 1:
Input :
N = 3
arr[] = {2, 4, 5}
Output : 7
Explanation :
The subset {2, 5} has maximum
subset XOR value.
Example 2 :
Input :
N= 3
arr[] = {9, 8, 5}
Output : 13
Explanation :
The ... | class Solution:
def maxSubsetXOR(self, arr, N):
int_bits = 32
i = 0
for j in range(int_bits - 1, -1, -1):
maxi = i
maxele = -2147483648
for m in range(i, n):
if set[m] & 1 << j != 0 and set[m] > maxele:
maxele = set[m]
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASS... |
Given an array arr[] of N positive integers. Find an integer denoting the maximum XOR subset value in the given array arr[].
Example 1:
Input :
N = 3
arr[] = {2, 4, 5}
Output : 7
Explanation :
The subset {2, 5} has maximum
subset XOR value.
Example 2 :
Input :
N= 3
arr[] = {9, 8, 5}
Output : 13
Explanation :
The ... | class Solution:
def maxSubsetXOR(self, arr, N):
listOfPossibleSolutions = arr[:]
counter = 0
listSizeDevelopment = [0]
listSizeDevelopment.append(N)
biggestValue = 0
while counter <= int(N / 2) + 1:
for i in listOfPossibleSolutions[listSizeDevelopment[cou... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBE... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def __init__(self):
self.mn = {}
self.mx = {}
def calcMax(self, tuple1, tuple2):
ret = 0
if tuple1 not in self.mn or tuple2 not in self.mn:
return 0
ret = max(abs(self.mn[tuple1] - self.mn[tuple2]), ret)
ret = max(abs(self.mn[tuple1] ... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution(object):
def longestAwesome(self, s):
d = {(0): -1}
cands = {(1 << x) for x in range(10)}
cands.add(0)
cur = 0
res = 0
for i, c in enumerate(s):
cur ^= 1 << int(c)
for cand in cands:
res = max(res, i - d.get(cur ... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
m = [(100000.0) for i in range(1024)]
m[0] = -1
es = [(1 << i) for i in range(10)]
current = 0
res = 1
for i, c in enumerate(s):
n = ord(c) - ord("0")
current = 1 << n ^ current
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBE... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
ans = 1
mask = 0
memo = {(0): -1}
for idx, ch in enumerate(s):
mask = mask ^ 1 << int(ch)
if mask in memo:
ans = max(ans, idx - memo[mask])
for i in range(10):
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN V... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
targets = {(1 << x) for x in range(10)}
targets.add(0)
print(targets)
diction = {}
res = 0
prev = 0
diction[0] = -1
for idx, char in enumerate(s):
curr = prev ^ 1 << int(char)
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR FOR... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
digits = [(2**i) for i in range(10)] + [0]
max_len, xor, dictF, dictB = 0, 0, {(0): -1}, {}
for i in range(len(s)):
xor = xor ^ digits[int(s[i])]
if xor not in dictF:
dictF[xor] = i
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER LIST NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER DICT NUMBER NUMBER DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
if s == s[::-1]:
return len(s)
pattern, re = 0, 0
exit = {pattern: -1}
for i, num in enumerate(s):
pattern ^= 1 << int(num)
if pattern == 0:
re = i + 1
contin... | CLASS_DEF FUNC_DEF VAR IF VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
left_most_masks = {(0): -1}
valid_masks = {(1 << i) for i in range(10)} | {0}
ans = 0
cur_mask = 0
for idx, x in enumerate(list(s)):
cur_mask = cur_mask ^ 1 << int(x)
for valid_mask in valid_mas... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
N = len(s)
M = 10
prefix = [(0) for _ in range(N + 1)]
for i in range(1, N + 1):
x = int(s[i - 1])
prefix[i] = prefix[i - 1] ^ 1 << x
print("prefix", prefix)
targets = [0]
for i ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
pattern = 0
d = {pattern: -1}
res = 0
for cur_i, x in enumerate(s):
pattern ^= 1 << int(x)
for i in range(10):
new_pattern = pattern ^ 1 << i
res = max(res, cur_i - d.get... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR DICT VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP V... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
N = len(s)
prefix = [(0) for _ in range(N + 1)]
for i, value in enumerate(s):
x = int(value)
prefix[i + 1] = prefix[i] ^ 1 << x
valids = set([0])
for i in range(10):
valids.add(1 << ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP N... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
bit_mask_mapping = {tuple([0] * 10): -1}
bit_mask = [0] * 10
max_len = 0
for ch_i, ch in enumerate(s):
cur_int = int(ch)
bit_mask[cur_int] ^= 1
bit_mask_str = tuple(bit_mask)
if ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | def find(dp, mask):
d = {}
ans = 0
for i in range(0, len(dp)):
x, y = dp[i], dp[i] ^ mask
if y in d:
ans = max(ans, i - d[y])
if x not in d:
d[x] = i
return ans
class Solution:
def longestAwesome(self, s: str) -> int:
val = 0
dp = [0... | FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR VAR BIN_OP N... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
subsum = [0]
rtn = 0
first_appear = {}
first_appear[0] = 0
for i, x in enumerate(s):
subsum.append(subsum[i] ^ 1 << int(x))
if subsum[i + 1] not in first_appear:
first_appear[sub... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
memo, state = {}, 0
memo[state], ans = -1, 0
for i, c in enumerate(s):
state ^= 1 << int(c)
if state not in memo:
memo[state] = i
else:
ans = max(ans, i - memo[state]... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR DICT NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR FU... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
idxs = [(1000000000.0) for _ in range(1024)]
idxs[0] = -1
ans = 0
mask = 0
for i, ch in enumerate(s):
mask ^= 1 << ord(ch) - ord("0")
ans = max(
[ans, i - idxs[mask]] + [(i - idx... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP LIST VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
mx = 0
table = {frozenset(): -1}
acs, cs = set(), set()
for i, c in enumerate(s):
acs.add(c)
if c in cs:
cs.remove(c)
else:
cs.add(c)
fcs = frozen... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR F... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
prefix = {(0): -1}
curr = 0
length = 1
powers = [0] + [(1 << j) for j in range(10)]
for i, c in enumerate(s):
curr ^= 1 << int(c)
for p in powers:
length = max(length, i - prefix... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL V... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
mask = 0
prefix, suffix = {(0): -1}, {(0): -1}
digcodes = [(2**i) for i in range(10)] + [0]
for i in range(len(s)):
ch = s[i]
mask ^= 2 ** int(ch)
if mask not in prefix:
pref... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR DICT NUMBER NUMBER DICT NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN FU... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
max_len = 0
mapping_pos = {(0): -1}
acc = 0
for idx, digit in enumerate([(ord(c) - ord("0")) for c in s]):
acc ^= 1 << digit
for x in range(10):
tmp = acc ^ 1 << x
if tmp... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR I... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | def gen_prefixes(s):
ans = {(0): [0]}
parity = 0
for ind, ch in enumerate(s):
after = ind + 1
parity ^= 1 << int(ch)
ans.setdefault(parity, [])
ans[parity].append(after)
return ans
def get_awesomes(prefixes):
ans = 1
for A in prefixes:
for xbit_ind in ra... | FUNC_DEF ASSIGN VAR DICT NUMBER LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
seen, prefix, ans = {(0): -1}, 0, 0
for i, char in enumerate(s):
prefix ^= 1 << int(char)
ans = max(ans, i - seen.get(prefix, float("inf")))
for j in range(10):
p = prefix ^ 1 << j
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR VAR DICT NUMBER NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BI... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
ps = {}
mask = 0
best = 0
ps[mask] = -1
for i, c in enumerate(s):
d = int(c)
mask ^= 1 << d
if mask in ps:
best = max(best, i - ps[mask])
else:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def count_set_bits(self, n):
count = 0
for i in range(32):
count += n >> i & 1
return count
def longestAwesome(self, s: str) -> int:
xormap = dict()
xormap[0] = -1
xor = 0
max_length = 0
for i in range(len(s)):
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FU... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s):
res, cur, n = 0, 0, len(s)
seen = [-1] + [n] * 1024
for i, c in enumerate(s):
cur ^= 1 << int(c)
for a in range(10):
res = max(res, i - seen[cur ^ 1 << a])
res = max(res, i - seen[cur])
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
s = [(ord(x) - ord("0")) for x in s]
ans = 0
m = [None] * 1024
m[0] = -1
y = 0
for i, x in enumerate(s):
y ^= 1 << x
for j in range(11):
p = y ^ 1 << j & 1023
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER I... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
d = {(0): -1}
mask = 0
maxi = 1
for i in range(len(s)):
x = int(s[i])
mask = mask ^ 1 << x
for j in range(0, 10):
if mask ^ 1 << j in d:
maxi = max(maxi, ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BI... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
n = len(s)
a = 0
ans = 0
dp = {(0): -1}
for i in range(n):
a = a ^ 1 << int(s[i])
if a in dp:
ans = max(ans, i - dp[a])
else:
dp[a] = i
fo... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
s = [int(c) for c in s]
seen = {(0): -1}
valid = [0] + [(1 << i) for i in range(10)]
totSum = 0
res = 0
N = len(s)
for i in range(N):
totSum ^= 1 << s[i]
for y in valid:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
def getMatchingMasks(mask):
st = set([mask])
for i in range(10):
st.add(mask ^ 1 << i)
return st
mask = 0
maskDict = dict()
maskDict[0] = -1
ans = 0
for idx... | CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
n = len(s)
res = 0
mask = 0
idx = [n + 1] * 1024
idx[0] = -1
for i, c in enumerate(s):
mask ^= 1 << ord(c) - ord("0")
res = max(res, i - idx[mask])
res = max(res, max([(i - i... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_C... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
n = len(s)
ans = 0
d = {(0): -1}
rolling = 0
for i, v in enumerate(s):
rolling ^= 1 << int(v)
for x in range(10):
diff = rolling ^ 1 << x
if diff in d:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR V... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
mask = 0
pre = {(0): -1}
result = 0
for i in range(10):
pre[0 ^ 1 << i] = -1
for i, c in enumerate(s):
n = 1 << int(c)
mask ^= n
if mask in pre:
result = ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
p = [0]
for c in s:
x = int(c)
p.append(p[-1])
p[-1] ^= 1 << x
first = {}
valid = {(1 << x) for x in range(10)}
valid.add(0)
res = 0
for j, pj in enumerate(p):
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CA... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
n = len(s)
a = [(0) for _ in range(n)]
for i in range(n):
x = a[i - 1] if i > 0 else 0
a[i] = x ^ 1 << int(s[i])
dp = 1
ht = {}
ht[a[0]] = 0
for i in range(1, n):
d =... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMB... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
m, state = defaultdict(int), [0] * 10
m[tuple(state)] = -1
ans = 0
for i, c in enumerate(s):
k = int(c)
state[k] = 1 - state[k]
tstate = tuple(state)
if tstate not in m:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
cum = [0]
firsts = {(0): -1}
lasts = {(0): -1}
for i, c in enumerate(s):
cum.append(cum[-1] ^ 1 << ord(c) - 48)
if cum[-1] not in firsts:
firsts[cum[-1]] = i
lasts[cum[-1]] =... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR A... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
cur = res = 0
d = defaultdict(lambda: float("inf"), {(0): -1})
for i, ch in enumerate(s):
cur ^= 1 << int(ch)
res = max(res, i - d[cur])
for j in range(10):
res = max(res, i - d[cur ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING DICT NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBE... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
dp = [-2] * 1024
run = 0
ans = 0
dp[0] = -1
for j, i in enumerate(s):
k = int(i)
run ^= 1 << k
if dp[run] == -2:
dp[run] = j
else:
ans = m... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF V... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
max_val = 0
seen = {(0): -1}
cur = 0
for i, char in enumerate(s):
cur ^= 1 << int(char)
seen.setdefault(cur, i)
max_val = max(max_val, i - seen[cur])
for a in range(10):
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
M = {(0): -1}
ans = 0
code = 0
D = [(1 << d) for d in range(10)]
for i, c in enumerate(s):
code = code ^ 1 << ord(c) - ord("0")
if code in M:
ans = max(ans, i - M[code])
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VA... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
if len(s) == 0:
return 0
max_len = 1
p = [0] * len(s)
seen = {(0): -1}
for i in range(0, len(s)):
d = ord(s[i]) - ord("0")
p[i] = 1 << d ^ p[i - 1]
for od in range(10):
... | CLASS_DEF FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
d = {(0): -1}
b = 0
m = 0
for i, c in enumerate(s):
b ^= 1 << int(c)
if not b or not b & b - 1:
m = max(m, i - d.get(b, i - 1), i + 1)
if not b:
h = 1... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR FU... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
seen = [len(s)] * (1 << 10)
seen[0] = -1
mask = 0
res = 0
for i, char in enumerate(s):
mask ^= 1 << int(char)
res = max(res, i - seen[mask])
for j in range(10):
temp ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
res, mask = 0, 0
n = len(s)
memo = [n] * 1024
memo[0] = -1
for i, ch in enumerate(s):
mask ^= 1 << int(ch)
res = max(res, i - memo[mask])
for j in range(10):
test_mas... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER V... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
mask_dict = {(0): -1}
answer = 0
nums = list(map(int, s))
mask = 0
print(nums)
for i in range(len(nums)):
mask = mask ^ 1 << nums[i]
if mask in mask_dict:
answer = max(an... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def linear(self, s):
ans = 0
d = {(0): -1}
mask = 0
for i, c in enumerate(s):
mask = 1 << int(c) ^ mask
if mask in d:
ans = max(ans, i - d[mask])
for j in range(10):
s = mask ^ 1 << j
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR F... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s):
d = {(0): -1}
t = 0
ans = 0
for i in range(len(s)):
num = int(s[i])
t ^= 1 << 9 - num
if t not in d:
d[t] = i
for m in range(10):
temp = t ^ 1 << 9 - ... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR IF VAR VAR AS... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
pos = {}
def f(c):
return ord(c) - ord("0")
mask, ans = 0, 1
pos[0] = -1
for n, ch in enumerate(s):
p = f(ch)
mask ^= 1 << p
if mask in pos:
len = n - p... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
curr = 0
longest = 0
first = {(0): -1}
for i, c in enumerate(s):
curr ^= 1 << int(c)
if curr in first:
longest = max(longest, i - first[curr])
else:
first[cur... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
mask = {n: (1 << n) for n in range(10)}
target = [0] + list(mask.values())
loc = [-2] * (1 << 10)
for x in target:
loc[x] = -1
sofar = 0
ans = 0
for idx, ch in enumerate(s):
m = ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR V... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
pos = {}
open_chars = 0
pos[open_chars] = 0
max_len = 0
for i, c in enumerate(s):
open_chars ^= 1 << int(c)
for j in range(-1, 10):
if j == -1:
mask = 0
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BI... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def __init__(self):
self.seen = {(0): -1}
self.len = 0
def update_best_length(self, num, p):
if num in self.seen:
self.len = max(self.len, p - self.seen[num])
for i in range(10):
x = num ^ 1 << int(i)
if x in self.seen:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR VAR ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
ls = len(s)
table = [-1] + [ls] * 1023
mask = res = 0
for i in range(ls):
mask ^= 1 << int(s[i])
for j in range(11):
temp = mask
temp ^= 1023 & 1 << j
res... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
digit_cnt = [(0) for _ in range(len(s) + 1)]
for i in range(1, len(s) + 1):
digit_cnt[i] = digit_cnt[i - 1] ^ 1 << int(s[i - 1])
res = 1
indx = {}
indx[0] = 0
for i in range(1, len(digit_cnt)):
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CA... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
df, dl = {}, {}
df[0] = -1
sm = 0
res = 1
for i, c in enumerate(s):
sm ^= 1 << int(c)
if sm not in df:
df[sm] = i
dl[sm] = i
for fk, fv in df.items():
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR DICT DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
pattern = [(1 << i) for i in range(10)]
seen, state = {}, 0
seen[state] = -1
answer = 0
for i, c in enumerate(s):
state ^= 1 << int(c)
if state in seen:
answer = max(answer, i - ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR DICT NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR AS... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
known_positions = {(0): -1}
mask = 0
max_size = 0
for idx, current in enumerate(s):
mask ^= 1 << ord(current) - ord("0")
for modified in range(10):
tmp_mask = mask ^ 1 << modified
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER ASS... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
def check(guess):
num_odd = 0
for _, val in list(guess.items()):
num_odd += val % 2 == 1
return num_odd <= 1
N = len(s)
if N > 70000 and s.startswith("0000000"):
return... | CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN V... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
digit = []
for i in range(10):
digit.append(1 << i)
digit.append(0)
cum = 0
bk = [(-2) for _ in range(2**10 + 1)]
bk[0] = -1
ans = 0
for i, x in enumerate(s):
x = int(x)
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VA... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
earliest_occ = defaultdict(lambda: float("inf"))
earliest_occ[0] = -1
msk = 0
ans = 1
for i in range(len(s)):
msk ^= 1 << int(s[i])
earliest_occ[msk] = min(i, earliest_occ[msk])
for ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
d = 0
m = 0
l = []
l.append(d)
dd = {}
dd[0] = [0, 0]
for i in range(len(s)):
c = s[i]
d = d ^ 1 << int(c)
l.append(d)
if d not in dd:
dd[... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST BI... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
dic, mask, res = {(0): -1}, 0, 1
for i, ch in enumerate(s):
mask ^= 1 << int(ch)
dic.setdefault(mask, i)
res = max(
res,
i
- min(
[dic[mas... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR VAR DICT NUMBER NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP LIST VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR FUNC_CALL VAR STRING VAR FUNC_CALL ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
res = 0
count = 0
record = {count: -1}
for i, ss in enumerate(s):
count ^= 1 << int(ss)
if count not in record:
record[count] = i
res = max(
res,
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP B... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
n = len(s)
if n <= 1:
return n
dp = [-1] + [n] * 1023
mask, res = 0, 0
for i in range(n):
mask = mask ^ 1 << int(s[i])
for j in range(11):
ch_mask = 1023 & (mask ^ 1 ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR BIN_OP NUMBE... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
d = {}
d[0] = -1
ans = 0
cnt = 0
for i, x in enumerate(s):
cnt ^= 1 << ord(x) - ord("0")
if cnt in d:
ans = max(ans, i - d[cnt])
for j in range(10):
i... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR AS... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
n = len(s)
seen = {(0): -1}
status = res = 0
for i, c in enumerate(s):
status ^= 1 << ord(c) - ord("0")
for a in range(10):
if status ^ 1 << a in seen:
res = max(res,... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR BI... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
first_pos = [(-1) for i in range(1024)]
first_pos[0] = 0
cur_xor = 0
xors = [0] + [(1 << i) for i in range(10)]
max_len = 0
for i in range(len(s)):
cur_xor = cur_xor ^ 1 << int(s[i])
for... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
pattern = [False] * 10
d = {tuple(pattern): -1}
res = 0
for i, x in enumerate(s):
num = int(x)
pattern[num] = not pattern[num]
res = max(res, i - d.get(tuple(pattern), i))
for k ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR DICT FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUN... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
m = collections.defaultdict(lambda: 0)
def convertToKey():
x = 0
for i in range(10):
x += m[i] % 2 << i
return x
presum = {}
presum[0] = -1
res = 0
for i, j... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR ASSIGN ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
prev = [-1] + [len(s)] * 1024
best = 1
mask = 0
for i in range(len(s)):
mask ^= 1 << int(s[i])
for j in range(10):
tmp = mask ^ 1 << j
if best < i - prev[tmp] + 1:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIG... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
d = {}
d[0] = -1
mask = 0
ans = 0
for i, ch in enumerate(s):
mask ^= 1 << int(ch)
if mask in d and (i - d[mask]) % 2 == 0:
ans = max(ans, i - d[mask])
for j in range(... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
mask, res = 0, 1
mask_pos = {(0): -1}
for i, c in enumerate(s):
c = int(c)
mask ^= 1 << c
for j in range(11):
check_mask = 1023 & (mask ^ 1 << j)
if check_mask in mas... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSI... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution1:
def longestAwesome(self, s: str) -> int:
mem = {}
def find_awesome(lo, hi, digit_count):
if lo > hi:
return 0
if (lo, hi) in mem:
return mem[lo, hi]
if digit_count & digit_count - 1 == 0:
return hi... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR N... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
n = len(s)
c = 0
counts = [c]
for x in s:
c ^= 1 << ord(x) - ord("0")
counts.append(c)
good = {(1 << i) for i in range(10)}
good.add(0)
m = {}
for i, c in enumerate(count... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FOR VAR VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VA... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
idx = [-1] + [len(s)] * 1023
ans, mask = 0, 0
for i, c in enumerate(s):
update = ord(c) - ord("0")
mask ^= 1 << update
ans = max(ans, i - idx[mask])
for j in range(10):
a... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
d = {}
d[0] = -1
sm, res = 0, 0
for i, c in enumerate(s):
sm ^= 1 << int(c)
if sm in d:
res = max(res, i - d[sm])
else:
d[sm] = i
for j in range(1... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR BIN... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
sLength = len(s)
earliestBinaries = {}
current = [0] * 10
earliestBinaries[tuple(current)] = -1
currentMax = 0
def computeMaxFromNeighbors(counter, currentTuple):
currentMax = 0
if curr... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
n = len(s)
res = mask = 0
seen = [n] * 1024
seen[0] = -1
for i in range(n):
mask ^= 1 << int(s[i])
res = max(res, i - seen[mask])
for num in range(10):
res = max(res,... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
cur = ans = 0
m = {}
for i, c in enumerate(s):
cur ^= 1 << int(c)
if cur == 0:
ans = max(ans, i + 1)
elif cur == 2 ** int(math.log(cur, 2)):
ans = max(ans, i + 1)
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUM... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
seen = {(0): -1}
mask = 2**10 - 1
bs = [0] + [(1 << i) for i in range(10)]
cur = 0
best = 1
for i in range(len(s)):
b = 1 << int(s[i])
cur = (cur ^ b) & mask
for m in bs:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP ... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
bd = {}
bd[0] = -1
soen = 0
for i, n in enumerate(s):
soen ^= 1 << int(n)
bd[soen] = -1
bd[soen] = i
for j in range(10):
soen_cpy = soen
soen_cpy ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP... |
Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.
Return the length of the maximum length awesome substring of s.
Example 1:
Input: s = "3242415"
Output: 5
Explanation: "24241" is the longest awesome substring, we can form th... | class Solution:
def longestAwesome(self, s: str) -> int:
F = {(0): 0}
res = 0
mask = 0
j = 0
for c in s:
j += 1
mask ^= 1 << ord(c) - ord("0")
for i in range(0, 10):
new_mask = mask ^ 1 << i
if new_mask in l... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC... |
You are given a matrix of integers $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each element of this matrix is either $0$ or $1$.
A move consists of the following steps:
- Choose two different rows $r_1$ and $r_2$ or two different columns $c_1$ and $c_2$.
- Apply the bitwise ... | t = int(input())
for _ in range(t):
n, m = map(int, input().split())
a = []
r = [0] * n
c = [0] * m
for i in range(n):
a.append(list(map(int, input())))
for j in range(m):
r[i] |= a[i][j]
c[j] |= a[i][j]
if all(x == 0 for x in r):
for i in range(n)... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR V... |
You are given a matrix of integers $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each element of this matrix is either $0$ or $1$.
A move consists of the following steps:
- Choose two different rows $r_1$ and $r_2$ or two different columns $c_1$ and $c_2$.
- Apply the bitwise ... | for _ in range(int(input())):
n, m = map(int, input().split())
q = [([0] * m) for i in range(n)]
a = [input() for i in range(n)]
r = [0] * n
c = [0] * m
for i in range(n):
for j in range(m):
if a[i][j] == "1":
r[i] = 1
c[j] = 1
if sum(r) + ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CAL... |
You are given a matrix of integers $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each element of this matrix is either $0$ or $1$.
A move consists of the following steps:
- Choose two different rows $r_1$ and $r_2$ or two different columns $c_1$ and $c_2$.
- Apply the bitwise ... | for _ in range(int(input())):
M, N = map(int, input().split())
arr = [[(1) for i in range(N)] for j in range(M)]
zero_cols = []
zero_rows = [0] * N
arr2 = []
for i in range(M):
col = input()
if "1" not in col:
zero_cols.append(i)
temp = []
for dig in c... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF STRING VAR EXPR FUNC_CALL VAR V... |
You are given a matrix of integers $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each element of this matrix is either $0$ or $1$.
A move consists of the following steps:
- Choose two different rows $r_1$ and $r_2$ or two different columns $c_1$ and $c_2$.
- Apply the bitwise ... | def row_has1(matrix, i):
if "1" in matrix[i]:
return True
return False
def column_has1(matrix, i):
a = any([(row[i] == "1") for row in matrix])
return a
def main():
testcases = int(input())
for i in range(testcases):
n, m = [int(j) for j in input().strip().split()]
ma... | FUNC_DEF IF STRING VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR STRING VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FO... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.