description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def is_unique(self, s):
return len(set(s)) == len(s)
def maxLength(self, arr: List[str]) -> int:
dct = {}
maxVal = 0
for i in range(0, len(arr)):
v = frozenset(arr[i])
if self.is_unique(arr[i]):
maxVal = max(maxVal, len(v)... | CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER F... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
res = 0
def dfs(n, s, l, cur):
nonlocal res
if n == l:
if len(set(cur)) == len(cur):
res = max(res, len(cur))
return
for i in range(s, len(arr)):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr) -> int:
maxLen = 0
arr = sorted(arr, key=lambda x: len(x), reverse=True)
self.compatible = {}
for i in range(len(arr)):
currString = arr[i]
if self.noDupes(currString):
if currString not in self.compati... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR V... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
newarr = []
for w in arr:
if len(set(w)) == len(w):
newarr.append(w)
arr = newarr
n = len(arr)
res = 0
str_masks = [None] * n
for i in range(n):
wd = arr[i]
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FU... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution(object):
def maxLength(self, A):
for i in range(len(A) - 1, -1, -1):
if len(set(A[i])) != len(A[i]):
A.pop(i)
N = len(A)
B = []
for word in A:
ct = [0] * 26
for letter in word:
ct[ord(letter) - ord("a... | CLASS_DEF VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL ... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
letters_dict = {}
def dfs(letter_set, arr, i):
if i >= len(arr):
return 0
if (tuple(letter_set), i) not in letters_dict:
if len(set(arr[i]).intersection(letter_set)) == 0 and len(
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR ... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
arr.sort()
self.arr = arr
self.tmp = []
self.mlen = 0
self.len = 0
self.backtrack(0)
return self.mlen
def backtrack(self, pos):
if pos == len(self.arr):
if self.len > self.ml... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL V... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
def dfs(arr, path, res):
if self.checkUnique(path):
res.append(path)
for i in range(len(arr)):
dfs(arr[i + 1 :], path + arr[i], res)
concatenated_string, res = [], 0
dfs(arr... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR LIST NUMBER EXPR FUNC_CALL VAR VAR STRING VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR F... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
def isUniqueChars(s):
return len(set(s)) == len(s)
arr = [set(w) for w in arr if isUniqueChars(w)]
results = list(arr)
for w in arr:
temp = []
for r in results:
if not w... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER F... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
res = 0
arr = list([x for x in arr if len(set(x)) == len(x)])
arr = [set(x) for x in arr]
def dfs(n, s, l, cur):
nonlocal res
if n == l:
res = max(res, len(cur))
retu... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VA... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
dp = [set()]
for word in arr:
if len(word) != len(set(word)):
continue
curWord = set(word)
for used in dp[:]:
if len(used & curWord) == 0:
dp.append(us... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def recurse(self, letters, arr, csum):
keys_as_str = "".join(sorted(letters))
if keys_as_str not in self.visited:
self.visited.add(keys_as_str)
self.max_len = max(self.max_len, csum)
for i, new_letters in enumerate(arr):
if len(new... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR FUNC_DEF VAR ... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
dp = [set()]
length = 0
for word in arr:
if len(word) != len(set(word)):
continue
curr = set(word)
for used in dp[:]:
if not len(used & curr):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR VAR |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def get_max_length(self, sets, idx, cur_set):
if idx == len(sets):
return len(cur_set)
m = 0
for i in range(idx, len(sets)):
if not cur_set & sets[i]:
res = self.get_max_length(sets, i + 1, cur_set.union(sets[i]))
else:
... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUN... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | import itertools
class Solution:
def maxLength(self, arr):
def powerset(iterable):
import itertools
s = list(iterable)
return itertools.chain.from_iterable(
itertools.combinations(s, r) for r in range(len(s) + 1)
)
result = 0
... | IMPORT CLASS_DEF FUNC_DEF FUNC_DEF IMPORT ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIG... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
filtered = []
for string in arr:
seen = {}
good = True
for letter in string:
if letter in seen:
good = False
else:
seen[letter] = T... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR NUMBER VAR DICT VAR FUNC_DEF IF VAR RETURN VAR IF FUNC_CALL VAR VAR VAR RETURN... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
ret = [set()]
for string in arr:
curr = set(string)
if len(curr) == len(string):
for seen in ret:
if not seen & curr:
ret.append(seen | curr)
max_l... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
if len(arr) == 0:
return 0
currRes = []
for el in arr:
if self.isUnique(el):
currRes.append(el)
for el in arr:
for subSeq in currRes:
if self.isUnique(el +... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR V... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
self.maxLen = 0
def isUnique(s):
return len(s) if len(s) == len(set(s)) else -1
def dfs(i, s):
if i == len(candi) and isUnique(s) > self.maxLen:
self.maxLen = len(s)
return
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN IF VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def is_unique(self, word):
count = dict()
for char in "".join(word):
if char in count:
return False
else:
count[char] = 1
return True
def find_max(self, arr, output, current, start_index):
if self.is_unique... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL STRING VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR LIST VAR VAR BIN_OP ... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
d = {}
def helper(banned, start):
if start == len(arr):
return len(banned)
k = tuple(sorted(str(banned) + str(start)))
if k in d:
return d[k]
string = arr[sta... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
arr = [set(x) for x in arr if len(x) == len(set(x))]
mx = 0
def util(start, cur):
nonlocal mx
if start == len(arr):
mx = max(mx, len(cur))
for i in range(start, len(arr)):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
combinations = [set()]
for a in arr:
chars = set(a)
if len(chars) != len(a):
continue
for c in combinations:
if len(chars.intersection(c)) == 0:
combin... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | from itertools import combinations
class Solution:
def maxLength(self, arr: List[str]) -> int:
max_count = 0
for i in range(0, len(arr) + 1):
comb = combinations(arr, i)
for c in comb:
count = 0
bag = set()
s = "".join(c)
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CAL... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def __init__(self):
self._maxLength = 0
def maxLength(self, arr: List[str]) -> int:
self.uniqueLengths(arr, [])
return self._maxLength
def uniqueLengths(self, arr, concat):
result = "".join(concat)
if not self.hasUniqueChars(result):
ret... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR LIST RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr):
def isValid(chars):
if len(chars) == len(set(chars)):
return True
else:
return False
result = 0
currentSubset = set()
def iterate(idx):
nonlocal result, currentSubset
... | CLASS_DEF FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR ... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def uniquelen(self, cur):
if len(cur) == len(set(cur)):
return len(cur)
else:
return -1
def dfs(self, arr, index, cur):
if index == len(arr) and self.uniquelen(cur) > self.ans:
self.ans = self.uniquelen(cur)
return
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN IF VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
res = 0
unique = [""]
def isvalid(s):
return len(s) == len(set(s))
for word in arr:
for u in unique:
tmp = word + u
if isvalid(tmp):
unique.appen... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST STRING FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
if arr == None:
return
path = []
result = [0]
def hasUniqueLetters(word):
hash_set = set()
for c in word:
if c in hash_set:
return False
... | CLASS_DEF FUNC_DEF VAR VAR IF VAR NONE RETURN ASSIGN VAR LIST ASSIGN VAR LIST NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR ASSI... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
self.output = []
self.res = 0
self.dfs(arr)
return self.res
def checkUnique(self, s):
m = set()
for i in s:
if i not in m:
m.add(i)
else:
return F... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF NUMBER LIST ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
if len(arr) == 1:
if len(set(arr[0])) == len(list(arr[0])):
return len(set(arr[0]))
else:
return 0
all_combinations = []
max_ = 0
for r in range(1, len(arr) + 1):
... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution(object):
def maxLength(self, arr):
def get_max_len(arr):
dp = [set(x) for x in arr if len(set(x)) == len(x)]
for v in arr:
if len((a := set(v))) == len(v):
for b in dp:
if a & b:
... | CLASS_DEF VAR FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN FUN... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
def score(s):
return sum(1 << ord(c) - ord("a") for c in s)
def valid(s):
return collections.Counter(s).most_common()[0][1] <= 1
arr = [s for s in arr if valid(s)]
s = [score(s) for s in arr]
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBE... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
n = len(arr)
self.max = 0
def helper(idx, chars):
if idx >= n:
if len(chars) == len(set(chars)):
self.max = max(self.max, len(chars))
else:
helper(idx + 1... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL ... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
myQueue = collections.deque([("", 0)])
maxLen = 0
while myQueue:
word, start = myQueue.popleft()
for i in range(start, len(arr)):
newWord = word + arr[i]
if self.isUnique(newW... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR LIST STRING NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VA... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
return self.recursive(arr, "", 0)
def recursive(self, arr, curr_str, pick_idx):
if pick_idx == len(arr):
table = {}
for ch in curr_str:
if ch in table:
return 0
... | CLASS_DEF FUNC_DEF VAR VAR RETURN FUNC_CALL VAR VAR STRING NUMBER VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
newarr = []
for cur in arr:
newarr.append(collections.Counter(cur))
res = [0]
def helper(cur, index):
if index == len(arr):
res[0] = max(res[0], len(cur))
else:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
if not arr:
return 0
def isUnique(s):
return len(set(s)) == len(s)
def dfs(arr, res, curr):
if isUnique(curr):
res[0] = max(res[0], len(curr))
for i in range(len(arr... | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR ... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
uniqELements = [""]
maximum = 0
for i in range(len(arr)):
sz = len(uniqELements)
for j in range(sz):
x = arr[i] + uniqELements[j]
if len(x) == len(set(x)):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
def helper(arr, substring, i):
unique_length = len(set(substring))
if len(substring) == unique_length:
self.max_len = max(self.max_len, unique_length)
if i == len(arr) - 1:
retur... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR RETURN ASSIGN VAR NUMBER EXPR FUN... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
char_freq = {}
for i in range(len(arr)):
char_freq[i] = set()
for c in arr[i]:
if c not in char_freq[i]:
char_freq[i].add(c)
else:
del char_fre... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN V... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
def valid(s, baskets):
return all([(c not in baskets) for c in s])
def find_max_len_recursive(baskets, currIdx):
if currIdx == len(arr):
return len(baskets)
res1 = float("-inf")
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER R... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
N = len(arr)
charSets = [set()]
for s in arr:
currSet = set(s)
if len(currSet) != len(s):
continue
currSize = len(charSets)
for idx in range(currSize):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR FUNC_CA... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
self.res = 0
def walk(i, temp):
self.res = max(self.res, len(temp))
for j in range(i, len(arr)):
if all(
v <= 1 for v in list(collections.Counter(temp + arr[j]).values())
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRI... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
arr_sets = [set(x) for x in arr]
def buildSet(bitlist):
output = set()
for i, bit in enumerate(bitlist):
if bit:
output = output.union(arr_sets[i])
return output
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BI... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | def bo(i):
return ord(i) - ord("a")
class Solution:
def maxLength(self, arr: List[str]) -> int:
n = len(arr)
freq = []
ans = 0
for i in range(n):
s1 = set()
for j in arr[i]:
s1.add(bo(j))
if len(s1) == len(arr[i]):
... | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VA... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr):
prev = {(0): 0}
for word in arr:
seen = 0
duplicate = False
for char in word:
binaryC = 1 << ord(char) - ord("a")
if binaryC & seen != 0:
duplicate = True
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VA... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def is_unique(self, word):
letters = set()
for letter in word:
if letter in letters:
return False
letters.add(letter)
return True
def maxLength(self, arr: List[str]) -> int:
uniques = set()
for piece in arr:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR V... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
if len(arr) == 1:
return len(arr[0])
self.res = 0
def backtrack(start: int, path: set):
self.res = max(self.res, len(path))
if start == len(arr):
return
for i in rang... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
def digit_representation(s):
ans = 0
for c in s:
ans |= 1 << ord(c) - ord("a")
return ans
A = sorted(
[
(len(s), digit_representation(s))
for... | CLASS_DEF FUNC_DEF 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 VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR RETURN NUMBER ASSIGN VAR LIST FU... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
self.ans = 0
vis = set()
def help(s, i):
if len(s) == len(set(s)):
self.ans = max(self.ans, len(s))
if i >= len(arr):
return
for j in range(i, len(arr)):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR V... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
self.out = set()
self.visited = set()
opts = []
for sub in arr:
tmp = set()
omit = False
for ch in sub:
if ch in tmp:
omit = True
tmp.a... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF IF ... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
def isUnique(concatString):
concatSet = set()
for char in concatString:
if char in concatSet:
return False
concatSet.add(char)
return True
length = l... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER RETURN FOR VAR FUNC_CALL VAR BIN_OP ... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
def maxLength(i, string):
nonlocal ans
if i == len(arr):
s, invalid = set(), False
for ch in string:
if ch in s:
invalid = True
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR A... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
def unique_char_count(s):
chars = set()
for char in s:
if char in chars:
return -1
else:
chars.add(char)
return len(s)
def max_un... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR E... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
count = 0
def dfs(self, arr, i, visited):
for index in range(i + 1, len(arr)):
visit = True
for j in range(0, len(arr[index])):
if arr[index][j] in visited:
for k in range(0, j):
visited.remove(arr[index... | CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF VAR ASSIGN VAR FUNC_C... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
a = [set(i) for i in arr if len(set(i)) == len(i)]
n = len(a)
an = 0
for v in range(1, 2**n):
s = set()
i = 0
while v > 0:
if v & 1 == 1:
if s & a[i]:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR AS... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
d = [""]
for a in arr:
if len(set(a)) < len(a):
continue
else:
for x in d:
if set(x) & set(a):
continue
else:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST STRING FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
dp = defaultdict(lambda: set())
def dfs(index, cur):
if index == len(arr) or cur in dp[index]:
return len(cur)
dp[index].add(cur)
best = len(cur)
for x in range(index, len(ar... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR... |
Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.
Return the maximum possible length of s.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
Example ... | class Solution:
def maxLength(self, arr: List[str]) -> int:
self.array = arr
return max(self.recurse("", set(), 0, True), self.recurse("", set(), 0, False))
def recurse(self, prefix: str, letters: set, index: int, include: bool):
if index >= len(self.array):
return len(pref... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR STRING FUNC_CALL VAR NUMBER NUMBER VAR FUNC_DEF VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR IF VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN FUNC_... |
Childan is making up a legendary story and trying to sell his forgery — a necklace with a strong sense of "Wu" to the Kasouras. But Mr. Kasoura is challenging the truth of Childan's story. So he is going to ask a few questions about Childan's so-called "personal treasure" necklace.
This "personal treasure" is a multis... | from sys import stdin
def main():
n, m, q = map(int, input().split())
c = sz = 1 << n
costs, cnt = [0] * sz, [0] * sz
for w in map(int, input().split()):
c //= 2
for i in range(c, sz, c * 2):
for j in range(i, i + c):
costs[j] += w
for i, c in enumerate(... | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VA... |
Childan is making up a legendary story and trying to sell his forgery — a necklace with a strong sense of "Wu" to the Kasouras. But Mr. Kasoura is challenging the truth of Childan's story. So he is going to ask a few questions about Childan's so-called "personal treasure" necklace.
This "personal treasure" is a multis... | import sys
n, m, q = map(int, sys.stdin.readline().strip().split())
w = [int(x) for x in sys.stdin.readline().strip().split()]
mx = pow(2, n)
mask = mx - 1
sn = [0] * mx
for i in range(m):
s = sys.stdin.readline().strip()
si = int(s, 2)
sn[si] += 1
wu = [0] * mx
for i in range(mx):
for j in range(n):
... | IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC... |
Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
Input: nums = [1,2,3]
Output:
[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
] | class Solution:
def subsets(self, nums):
subsets = [[]]
for v in nums:
extra = []
for s in subsets:
extra.append(s + [v])
subsets += extra
return subsets | CLASS_DEF FUNC_DEF ASSIGN VAR LIST LIST FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR VAR RETURN VAR |
Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
Input: nums = [1,2,3]
Output:
[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
] | class Solution:
def subsets(self, nums):
result = [[]]
for num in nums:
result += self.get_subset(result, num)
return result
def get_subset(self, subsets, item):
new_subset_with_item = []
for subset in subsets:
new_subset_with_item.append(subset ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST LIST FOR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR RETURN VAR |
Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
Input: nums = [1,2,3]
Output:
[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
] | class Solution:
def subsets(self, nums):
def mask(x):
return 1 << x
exp = 1 << len(nums)
ans = []
for count in range(exp):
new = []
i = 0
while mask(i) <= count:
if mask(i) & count:
new.append(nums... | CLASS_DEF FUNC_DEF FUNC_DEF RETURN BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
self.ans, empty = 0, 0
m, n = len(grid[0]), len(grid)
def dfs(x, y, rest):
if x < 0 or x >= n or y < 0 or y >= m or grid[x][y] < 0:
return
if grid[x][y] == 2 and rest == 0:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LI... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
rows, cols = len(grid), len(grid[0])
non_obstacles = 0
start_row, start_col = 0, 0
for row in range(0, rows):
for col in range(0, cols):
cell = grid[row][col]
if cell ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
def traverse(row, col, spacesLeft):
if spacesLeft == 1 and grid[row][col] == 2:
self.results += 1
return
temp = grid[row][col]
grid[row][col] = "#"
spaces... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING VAR NUMBER FOR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR IF VAR VAR... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
def dfs(i, j, out, to_visit):
if (
i < 0
or j < 0
or i >= len(grid)
or j >= len(grid[0])
or grid[i][j] == "#"
or grid[i][j] ==... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR STRING VAR VAR VAR NUMBER RETURN IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUM... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
def fun(g, i0, i1, n1, t1, f2, row, col):
if n1 == t1:
if abs(f2[1] - i1) + abs(f2[0] - i0) == 1:
self.ans += 1
else:
if i1 + 1 != col and g[i0][i1 + 1] == 0:... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR ... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
def dfs(r, c, n):
if r < 0 or r >= R or c < 0 or c >= C or grid[r][c] == -1:
return 0
if grid[r][c] == 2:
return n == 0
grid[r][c] = -1
paths = (
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
self.ans, self.count = 0, 0
def go(cur, seen):
i, j = cur
if grid[i][j] == 2:
if len(seen) == self.count:
self.ans += 1
else:
retu... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER RETURN FOR VAR VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR N... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
nr = len(grid)
nc = len(grid[0])
all_cells = 0
start = 0, 0
res = 0
direction = [(0, 1), (0, -1), (1, 0), (-1, 0)]
for r in range(nr):
for c in range(nc):
if g... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
self.ret = 0
empty = 0
m = len(grid)
n = len(grid[0])
for i in range(m):
for j in range(n):
if grid[i][j] == 1:
sx = i
sy = j
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR V... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
rows, cols = len(grid), len(grid[0])
directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
start_cell, end_cell = None, None
empty_cells = {}
for i in range(rows):
for j in range(cols):
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR NONE NONE ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
self.ans = 0
m, n = len(grid), len(grid[0])
candidates = set()
for i in range(m):
for j in range(n):
if grid[i][j] == 1:
si, sj = i, j
elif grid[i]... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR VAR... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
count = 0
visited = set()
def dfs(i: int, j: int):
nonlocal count
nonlocal num_empty
if grid[i][j] == -1 or (i, j) in visited:
return
elif grid[i][j] == 2... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR RETURN IF VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL V... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
start = end = None
cnt = ans = 0
m, n = len(grid), len(grid[0])
for i in range(m):
for j in range(n):
if grid[i][j] == 1:
start = i, j
elif grid[i]... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NONE ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF IF VAR VAR VA... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
start = end = None
remain = 0
for m in range(len(grid)):
for n in range(len(grid[0])):
if grid[m][n] == 1:
start = m, n
elif grid[m][n] == 2:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR NONE VAR NONE RETURN NUMBER RETURN FUNC_CA... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid):
maxPath = 2
neighbors = [None] * (len(grid) * len(grid[0]))
visited = [False] * (len(grid) * len(grid[0]))
for x in range(len(grid)):
for y in range(len(grid[0])):
node = x * len(grid[0]) + y
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, A: List[List[int]]) -> int:
self.res = 0
rows = len(A)
cols = len(A[0])
empty = 1
for i in range(rows):
for j in range(cols):
if A[i][j] == 1:
x, y = i, j
elif A[i][j] ==... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VA... |
On a 2-dimensional grid, there are 4 types of squares:
1 represents the starting square. There is exactly one starting square.
2 represents the ending square. There is exactly one ending square.
0 represents empty squares we can walk over.
-1 represents obstacles that we cannot walk over.
Return the number of 4-dir... | class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
def dfs(i, j, N):
if N == -1 and grid[i][j] == 2:
return 1
grid[i][j] = -1
res = sum(
[
dfs(row, col, N - 1)
for x, y in dirs
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR LIST BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSI... |
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal su... | class Solution:
def canPartitionKSubsets(self, nums, k):
tot = sum(nums)
if k <= 0 or tot % k != 0:
return False
visited = [0] * len(nums)
def canPart(nums, visited, idx, curSum, k, target):
if k == 1:
return True
if curSum == tar... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL ... |
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal su... | class Solution:
def canPartitionKSubsets(self, nums, k):
if not nums:
return True
if sum(nums) % k != 0:
return False
target = sum(nums) / k
nums.sort()
if nums[-1] > target:
return False
while nums and nums[-1] == target:
... | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR RETURN NUMBER WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC... |
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal su... | class Solution:
def canPartitionKSubsets(self, nums, k):
quotient = sum(nums) / k
if quotient % 1 != 0:
return False
for num in nums:
if num > quotient:
return False
if num == quotient:
nums.remove(quotient)
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER FOR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST NUMBER FUNC_CALL VAR ... |
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal su... | class Solution:
def canPartitionKSubsets(self, nums, k):
total = sum(nums)
if total % k != 0:
return False
target = total / k
used = [False] * len(nums)
nums = sorted(nums)
def check(nums, k, cur, pos):
if k == 1:
return True
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR N... |
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal su... | class Solution:
def canPartitionKSubsets(self, nums, k):
if k <= 0:
return False
nums_sum = sum(nums)
if nums_sum % k != 0:
return False
visited = [False] * len(nums)
nums.sort(reverse=True)
return self.canPartition(nums, visited, k, 0, 0, num... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER BIN_OP VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR ... |
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal su... | class Solution(object):
def canPartitionKSubsets(self, nums, k):
he = sum(nums)
if he % k != 0:
return False
target = he // k
visit = [(0) for _ in range(len(nums))]
def dfs(k, ind, cur, cnt):
if k == 0:
return True
if cur... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC... |
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal su... | class Solution:
def canPartitionKSubsets(self, nums, k):
target, rem = divmod(sum(nums), k)
if rem or max(nums) > target:
return False
n = len(nums)
seen = [0] * n
nums.sort(reverse=True)
def dfs(k, index, current_sum):
if k == 1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL... |
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal su... | class Solution:
def canPartitionKSubsets(self, nums, k):
if sum(nums) % k or len(nums) < k:
return False
if k == 1:
return True
target, used = sum(nums) / k, [(False) for i in range(len(nums))]
def dfs(start, sum_, k):
if k == 1:
... | CLASS_DEF FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL... |
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal su... | class Solution:
def canPartitionKSubsets(self, nums, k):
target, rem = divmod(sum(nums), k)
if rem:
return False
def dfs(groups):
if not nums:
return True
v = nums.pop()
for i, group in enumerate(groups):
if gr... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR RETURN NUMBER FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR ... |
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal su... | class Solution:
def canPartitionKSubsets(self, nums, k):
total = sum(nums)
if total % k != 0:
return False
target = total // k
nums.sort()
if nums[-1] > target:
return False
while nums and nums[-1] == target:
nums.pop()
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR RETURN NUMBER WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CAL... |
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal su... | class Solution:
def canPartitionKSubsets(self, nums, k):
total = sum(nums)
if total % k != 0:
return False
subsetTotal = total // k
visited = [0] * len(nums)
return self.helper(k, 0, 0, visited, nums, k, subsetTotal)
def helper(self, remainingSets, index, s,... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR... |
Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.
Example 1:
Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4
Output: True
Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal su... | class Solution:
def partition(self, nums, target, current, pos, fill):
if fill == 0:
return True
for i in range(pos, len(nums)):
next = nums[:i] + nums[i + 1 :]
if current + nums[i] == target:
if self.partition(next, target, 0, 0, fill - 1):
... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR RETURN... |
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | class Solution:
def numSquarefulPerms(self, A: List[int]) -> int:
visited = collections.Counter(A)
ans = [0]
self.calc(A, visited, [], ans)
return ans[0]
def calc(self, A, visited, tmp, ans):
if len(tmp) == len(A):
ans[0] += 1
for i in list(visited.k... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR LIST VAR RETURN VAR NUMBER VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMB... |
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | class Solution:
def numSquarefulPerms(self, nums: List[int]) -> int:
self.ans = 0
def isSquare(v):
x = int(v**0.5)
return x * x == v
def dfs(pos):
if pos >= len(nums):
self.ans += 1
return
used = set()
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR... |
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | class Solution:
def numSquarefulPerms(self, A: List[int]) -> int:
n = len(A)
A = sorted(A)
g = [([0] * n) for _ in range(n)]
dp = [([0] * n) for _ in range(1 << n)]
for i in range(n):
for j in range(n):
if i == j:
continue
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR... |
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | class Solution:
def numSquarefulPerms(self, A: List[int]) -> int:
c = collections.Counter(A)
cand = {i: {j for j in c if int((i + j) ** 0.5) ** 2 == i + j} for i in c}
def dfs(x, left=len(A) - 1):
c[x] -= 1
count = sum(dfs(y, left - 1) for y in cand[x] if c[y]) if l... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR FUNC_DEF BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR N... |
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | class Solution:
def numSquarefulPerms(self, A: List[int]) -> int:
def get_valid():
ans = 0
seen = set()
visited = set()
while q:
cur, remaining = q.popleft()
if not remaining and cur not in seen:
ans += 1
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VA... |
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.
Return the number of permutations of A that are squareful. Two permutations A1 and A2 differ if and only if there is some index i such that A1[i] != A2[i].
Example 1:
Input: [1,17,... | class Solution:
def numSquarefulPerms(self, A: List[int]) -> int:
candidates = collections.Counter(A)
graph = {
x: [y for y in candidates if int((x + y) ** 0.5) ** 2 == x + y]
for x in candidates
}
graph[-1] = [x for x in candidates]
def dfs(node, no... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR VAR B... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.