description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
if len(s) == 1:
return 1
def splitter(str):
for i in range(1, len(str)):
start = str[0:i]
end = str[i:]
yield start, end
for split in splitter(end):
... | CLASS_DEF FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR EXPR FUNC_CALL VAR VAR EXPR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FU... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
max_len = [1]
def helper(i, s, vis):
if i == len(s) and i != s:
max_len[0] = max(max_len[0], len(vis))
return
j = i
while j < len(s):
if s[i : j + 1] not in ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
options = []
options = self.recursiveSplit(s)
bestcount = 0
for option in options:
count = 0
encountered = {}
valid = True
for substr in option:
if substr not in ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN LIS... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str, mem=None, seen=None) -> int:
if mem is None:
mem = {}
if seen is None:
seen = set()
res = 0
for i in range(0, len(s)):
if s[0 : i + 1] in seen:
continue
seen.add(s[0 : i ... | CLASS_DEF FUNC_DEF VAR NONE NONE IF VAR NONE ASSIGN VAR DICT IF VAR NONE ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR N... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
seen = set()
def helper(start):
nonlocal seen, s
length = len(s)
if start == length:
return 0
max_split, cur_split = 0, 0
for split in range(start + 1, length):
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def helper(start):
if len(s[start:]) == 0:
return 0
res = -math.inf
for i in range(start + 1, len(s) + 1):
if s[start:i] not in seen:
seen.add(s[start:i])
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VA... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s)
mx = 1
m = n - 1
total = 1 << m
state = 0
for state in range(total):
seen = set()
lo = 0
for i in range(m + 1):
if state & 1 << i:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUM... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
book = set()
def maxUniqueSplit(self, s):
result = 0
for i in range(1, len(s) + 1):
curr = s[:i]
if curr not in self.book:
self.book.add(curr)
result = max(result, 1 + self.maxUniqueSplit(s[i:]))
self.book.r... | CLASS_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
prev = [[s[0]]]
for elm in s[1:]:
current = []
for sub in prev:
copy = list(sub)
copy[-1] = copy[-1] + elm
current.append(copy)
copy = list(sub)
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST LIST VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR F... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
return self.dp(s, 0, 0, [])
def dp(self, s, start, pos, ans):
if pos == len(s):
return len(ans)
a = 0
b = self.dp(s, start, pos + 1, list(ans))
if s[start : pos + 1] not in ans:
ans.append(... | CLASS_DEF FUNC_DEF VAR RETURN FUNC_CALL VAR VAR NUMBER NUMBER LIST VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s)
@lru_cache(None)
def dp(i, cur):
nonlocal ans
if len(cur) + n - i < ans:
return
if i >= n:
ans = max(ans, len(cur))
l = n - i
for ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR RETURN IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
d = set()
res = 1
n = len(s)
def solve(p, ans):
nonlocal res
if p == n:
res = max(res, ans)
for i in range(p, n):
ss = "".join(s[p : i + 1])
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
best = -1
ans = []
for i in range(2 ** (len(s) - 1)):
x = bin(i)
x = x[2:]
x = (len(s) - len(x) - 1) * "0" + x
tmp = ""
a = []
c = 0
for char in s:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER STRING VAR ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def split(s, b):
res = []
x, y = s[0], b[0]
for i in range(1, len(s)):
if b[i] == y:
x += s[i]
else:
res.append(x)
x, y =... | CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VA... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
self.res = 1
def backtrack(curr, idx):
if len(curr) != len(set(curr)):
return
elif idx == len(s):
self.res = max(self.res, len(curr))
return
for i in range(i... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR VAR VAR EXPR FUN... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def dfs(self, s, req_l, segs, cur, hs):
if cur >= len(s):
return segs == req_l
for pos in range(cur, len(s)):
ts = s[cur : pos + 1]
if ts in hs:
continue
hs.add(ts)
if self.dfs(s, req_l, segs + 1, pos + 1, h... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF VAR FOR VAR FUNC_CALL... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def builder(s, seen):
if not s:
return 0
res = 0
for i, c in enumerate(s):
candidate = s[: i + 1]
if candidate not in seen:
seen.add(candidate)
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR FUNC_CALL ... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
max_ = 0
def maxUniqueSplit(self, s: str) -> int:
b = len(s) - 1
ar = []
self.h(s, b, ar)
return self.max_
def h(self, s, b, ar):
ar2 = ar.copy()
if b < 0:
self.max_ = max(self.max_, len(ar2))
return 0
t = s[b:... | CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR A... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def maxU(s, soFar=set()):
if len(s) == 1:
if s in soFar:
return 0
maxSplit = len(soFar) + 1
for partition in range(1, len(s)):
a = s[:partition]
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR RETURN FU... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
if s == None or len(s) == 0:
return 0
self.res = 0
has = set()
def dfs(cur, lasti, ct):
if cur > len(s):
self.res = max(self.res, ct)
return
for cur in range... | CLASS_DEF FUNC_DEF VAR IF VAR NONE FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def allsplit(s):
if len(s) == 1:
return [[s]]
res = [[s]]
for i in range(1, len(s)):
res += [([s[:i]] + x) for x in allsplit(s[i:])]
return res
ans = 0
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN LIST LIST VAR ASSIGN VAR LIST LIST VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP LIST VAR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIG... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
result = []
def dfs(path, word):
if not word:
result.append(path)
return
for i in range(1, len(word) + 1):
prefix, suffix = word[:i], word[i:]
if prefix ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FU... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def check(st, cm):
mx = 0 if st in cm else 1
for i in range(1, len(st)):
a = st[:i]
b = st[i:]
if a not in cm:
ncm = set(cm)
ncm.add(a)
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR RETURN FUNC_CALL VAR VA... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s)
self.res = 0
def helper(curIdx, curW, curSets):
if curIdx == n:
self.res = max(self.res, len(curSets))
return
helper(curIdx + 1, curW + s[curIdx], curSets)
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL V... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | def get_sequences(symbols, length):
if length == 0:
return [[]]
sequences = []
tail_sequences = get_sequences(symbols, length - 1)
for tail_sequence in tail_sequences:
for symbol in symbols:
sequences.append(list(tail_sequence) + [symbol])
return sequences
def is_unique... | FUNC_DEF IF VAR NUMBER RETURN LIST LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR LIST VAR RETURN VAR FUNC_DEF IF VAR STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
N = len(s)
res = 0
for mask in itertools.product("10", repeat=N - 1):
mask = list(mask) + ["1"]
substr = set()
begin = 0
i = 0
valid = True
while True:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR LIST STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP VAR NUMBE... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
self.ans = 1
def rec(split, s):
if not s:
se = set(split)
if len(se) == len(split):
self.ans = max(self.ans, len(split))
return
for i in range(len(s)... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
best_ans = 1
cur_ans = set()
def find_result(i):
nonlocal best_ans
if i >= len(s):
return len(cur_ans)
elif len(s) - i + len(cur_ans) < best_ans:
return best_ans
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VA... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
if not s:
return 0
cache = [None] * len(s)
setSet = self.dp(s, 0, cache)
return len(max(setSet, key=lambda x: len(x))) if setSet else 0
def dp(self, inputStr, i, cache):
if i == len(inputStr):
... | CLASS_DEF FUNC_DEF VAR IF VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR RETURN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN LIST FUNC_CALL VAR IF VAR VAR NONE RETURN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
ans = 1
def getans(self, s, start, n, temp):
self.ans = max(self.ans, len(temp))
for x in range(start + 1, n + 1):
boss = set(list(temp))
boss.add(s[start:x])
self.getans(s, x, n, boss)
def maxUniqueSplit(self, s: str) -> int:
tem... | CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER F... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
self.seen = set()
self.result = 0
def backtrack(s, start):
if start == len(s):
return True
for end in range(start + 1, len(s) + 1):
if s[start:end] not in self.seen:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CA... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def search(s):
ans = [[s]]
for i in range(1, len(s)):
ans += [([s[:i]] + comb) for comb in search(s[i:])]
return ans
a = search(s)
r = 1
for comb in a:
if len(s... | CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR LIST LIST VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP LIST VAR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL ... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
if not s:
return 0
return self.dfs(s, set())
def dfs(self, s: str, present: set) -> int:
maximum = 0
for i in range(1, len(s) + 1):
substring = s[:i]
if substring not in present:
... | CLASS_DEF FUNC_DEF VAR IF VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR RETURN VAR VAR |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | def aux(s, lst, i):
if i == len(s):
return 0
mx = 0
for j in range(i, len(s)):
if s[i : j + 1] not in lst:
tmp = 1 + aux(s, lst + [s[i : j + 1]], j + 1)
if tmp > mx:
mx = tmp
return mx
class Solution:
def maxUniqueSplit(self, s: str) -> int:... | FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR LIST VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIS... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s)
ans = 0
for pat in range(1 << n - 1):
start = 0
end = 1
split = []
for b in bin(pat)[2:].zfill(n - 1):
if b == "1":
split.append(s[start:en... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER E... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
for answer in range(len(s), 0, -1):
num_splits = answer - 1
for split_points in combinations(range(1, len(s)), num_splits):
current = 0
words = set()
for split_point in split_poi... | CLASS_DEF FUNC_DEF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR ... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def dfs(index, visited):
nonlocal ans
if s[index:n] and s[index:n] not in visited:
ans = max(ans, len(visited) + 1)
for i in range(index, n):
if (
s[index:i]
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s)
def back(i, curr, addhere):
if i == n:
return len(addhere) - 1
if curr + s[i] in addhere:
return back(i + 1, curr + s[i], addhere.copy())
else:
re... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
le = len(s) - 1
max = 1
for ma in range(pow(2, le) - 1, 0, -1):
bi = format(ma, "0" + str(le) + "b") + "1"
prev = 0
lis = []
valid = True
for bit in range(len(bi)):
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VA... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
N = len(s)
possibilities = []
for k in range(1, N):
comb = itertools.combinations(list(range(1, N)), k)
possibilities += [
(
[s[0 : x[0]]]
+ [s[x[i] : x[i... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP BIN_OP LIST VAR NUMBER VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER LIST VAR VAR NUMBER VA... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def split(i):
if i >= len(s):
return len([v for v in t.values() if v])
best = 0
for j in range(i, len(s)):
ss = s[i : j + 1]
t[ss] += 1
best = max(be... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
@lru_cache(None)
def helper(s):
if not s:
return [[]]
splits = []
for i in range(1, len(s) + 1):
word = s[:i]
next_splits = helper(s[i:])
for... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR RETURN LIST LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR RETURN VAR FUNC_CALL VAR NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUN... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
N, res = len(s), 0
for i in range(2 ** (N - 1)):
start, seen = 0, set()
for j in range(N):
if i + (1 << N - 1) & 1 << j:
seen.add(s[start : j + 1])
start = j + 1
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUM... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
self.ans = 0
n = len(s)
def backtrack(start, have):
if start >= n:
self.ans = max(self.ans, len(have))
return
for i in range(start + 1, n + 1):
tmp = s[start:i]
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_C... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s)
currli = []
visiting = set()
self.maxval = 1
def dfs(st, s):
if len(s) <= 0:
self.maxval = max(self.maxval, len(currli))
return True
for i in range(1,... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBE... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
have = set()
self.cur = []
def dfs(i):
if i == len(s):
return 0 if "".join(self.cur) not in have else -float("inf")
self.cur.append(s[i])
ret = dfs(i + 1)
st = "".join(s... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING VAR VAR NUMBER FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR AS... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def all_partitions(string):
for cutpoints in range(1 << len(string) - 1):
result = []
lastcut = 0
for i in range(len(string) - 1):
if 1 << i & cutpoints != 0:
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def numway(s):
nw = 0
for i in range(1, len(s) + 1):
if s[:i] not in nq:
nq.add(s[:i])
nw = max(nw, 1 + numway(s[i:]))
nq.remove(s[:i])
r... | CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s)
res = 1
if n == 1:
return res
for x in range(2 ** (n - 1)):
m = 1 << n - 2
p0 = 0
p1 = 0
st = set()
done = False
while m:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR VAR ASSIGN VAR VAR VAR BI... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def backtrack(seen, sidx):
if sidx == len(s):
self.res = max(self.res, len(seen))
return
if len(seen) + len(s) - sidx <= self.res:
return
for eidx in range(sidx, len... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN IF BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP V... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def func(self, s, idx, words):
max_result = 0
for i in range(idx + 1, len(s)):
max_result = max(max_result, self.func(s, i, words | {s[idx:i]}))
max_result = max(max_result, len(words | {s[idx:]}))
return max_result
def maxUniqueSplit(self, s: str) -... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF VAR RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
result = 1
for l in itertools.product([True, False], repeat=len(s)):
if l[-1] == False:
continue
cache = list()
now = ""
for c, end in zip(s, l):
now += c
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FU... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s)
def dp(cur, ss):
if cur == n - 1:
return len(set(ss.split()))
cur += 1
return max(dp(cur, ss + s[cur]), dp(cur, ss + " " + s[cur]))
return dp(0, s[0]) | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR STRING VAR VAR RETURN FUNC_CALL VAR NUMBER VAR NUMBER VAR |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
val = 0
if len(s) == 0:
return val
def helper(s, sett=()):
return max(
(
1 + helper(s[i:], {candidate, *sett})
for i in range(1, len(s) + 1)
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR VAR |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s)
if n == 1:
return 1
res = 1
seen = set()
for m in range(1, 1 << n - 1):
if bin(m).count("1") < res:
continue
valid = True
p = 0
for... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER IF FUNC_CALL FUNC_CALL VAR VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR IF B... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
res = 0
for count in range(len(s)):
for partitions in combinations(range(1, len(s)), count):
partitions = [0] + list(partitions) + [len(s)]
parts = [s[a:b] for a, b in zip(partitions, partitions[1:]... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER FUNC_CALL VAR VAR LIST FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR F... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def dfs(i, vis):
nonlocal ans
if len(vis) + n - i < ans:
return
if i >= n:
ans = max(ans, len(vis))
l = n - i
for k in range(1, l + 1):
x = s... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR RETURN IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR V... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def f(self, s):
xss = []
if len(s) == 0:
temp = []
temp.append("")
xss.append(temp)
return xss
for i in range(1, len(s) + 1):
xs = self.f(s[i:])
for x in xs:
if s[:i] not in x:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def helper(curr_set, s):
if len(s) == 0:
return len(s)
max_split = 0
for i in range(len(s)):
if s[: i + 1] not in curr_set:
curr_set.add(s[: i + 1])
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR B... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
self.mx = 0
self.lim = len(s)
def r(i, l, c):
if i == self.lim - 1:
if s[i] not in l:
if c + 1 > self.mx:
self.mx = c + 1
elif c > self.mx:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN V... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
self.s = s
self.cache = {}
count = self.maxUniqueSplitHelper(0, set())
return count
def maxUniqueSplitHelper(self, pos: int, substrings: set) -> int:
hashed = frozenset(substrings)
if (pos, hashed) in self... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR RETURN VAR VAR FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN VAR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VA... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | def partition(s):
def backtrack(index, path):
if index == len(s):
res.append(list(path))
else:
path.append(s[index])
backtrack(index + 1, path)
path.pop()
if path:
path[-1] = path[-1] + s[index]
backtrack(in... | FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR IF VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER LIST RETURN VAR CLA... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
self.maxsplits = 0
def DFS(i, substring_set):
if i == len(s):
self.maxsplits = max(len(substring_set), self.maxsplits)
return
for j in range(i + 1, len(s) + 1):
DFS(j, s... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR RETURN VAR VAR |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def helper(s, strings=set()):
leng_s = len(s)
leng_set = len(strings)
if leng_s == 1 and s in strings:
return 0
else:
ans = leng_set + 1
for i in range(1... | CLASS_DEF FUNC_DEF VAR FUNC_DEF FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR RETURN VAR RETURN FUNC... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
ans = 0
queue = [(set([s[:i]]), s[i:]) for i in range(1, len(s) + 1)]
while queue:
curSet, curS = queue.pop(0)
if curS == "":
ans = max(ans, len(curSet))
for i in range(1, len(curS) ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR V... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
spl = list(s)
n = len(spl)
c = collections.Counter(spl)
if all(v == 1 for v in c.values()):
return n
mx = 2 ** (n - 1) - 2
ans = 1
for cmb in range(mx, 0, -1):
bs = list(bin(cmb)... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUN... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | def count1(x):
xx = x
ans = 0
while x != 0:
x &= x - 1
ans += 1
return ans
def ok(mask, s):
strs = []
prev = 0
for i in range(len(s) - 1):
if 1 << i & mask:
strs.append(s[prev : i + 1])
prev = i + 1
strs.append(s[prev:])
return len(se... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s) - 1
ans = 1
for i in range(2**n + 1):
prev = 0
ok = True
visited = set()
for j in range(n):
if i & 1 << j:
tmp = s[prev : j + 1]
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMB... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
return get_max(s, set())
def get_max(s, set):
maxi = 0
for i in range(1, len(s) + 1):
if s[:i] not in set:
set.add(s[:i])
maxi = max(maxi, 1 + get_max(s[i:], set))
set.remove(s[:i])
return max... | CLASS_DEF FUNC_DEF VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def helper(s, start, seen):
ans = 0
for end in range(start + 1, len(s) + 1):
added = s[start:end]
print(added)
if added not in seen:
seen.add(added)
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def backtrack(m, s):
if len(s) == 0:
return 0
ans = 0
for i in range(1, len(s) + 1):
candidate = s[:i]
if candidate not in m:
m.add(candidate)
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR ... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | import itertools
class Solution:
def maxUniqueSplit(self, s: str) -> int:
maxres = 1
for sep in itertools.product([0, 1], repeat=len(s) - 1):
sett = set()
cur = s[0]
for i, (se, c) in enumerate(zip(sep, s[1:]), start=1):
if se:
... | IMPORT CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_C... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | from itertools import combinations
class Solution:
def maxUniqueSplit(self, s: str) -> int:
for num_splits in reversed(range(1, len(s))):
num_strings = num_splits + 1
for split_indices in combinations(range(1, len(s)), num_splits):
indices = [0] + list(split_indice... | CLASS_DEF FUNC_DEF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER FUNC_CALL VAR VAR LIST FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER VA... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def helper(s1_set, s2):
N = len(s2)
if N == 1:
if s2 in s1_set:
return 0
return len(s1_set) + 1
res = 0 if s2 in s1_set else len(s1_set) + 1
for i in... | CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR V... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def split(s):
if not s:
return [set()]
n = len(s)
w = set()
w.add(tuple([s]))
ret = [set([s])]
if n == 1:
return ret
if n == 2:
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR RETURN LIST FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR ASSIGN VAR LIST FUNC_CALL VAR LIST VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR LIST FUNC_CALL VAR LIST VAR RETURN VAR FOR VAR FUNC_... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, string: str) -> int:
def split(s, splits):
maxs = 1 if s not in splits else 0
for i in range(1, len(s)):
if s[:i] in splits:
continue
rst = 1 + split(s[i:], splits + [s[:i]])
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR LIST VAR |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s)
ans = -1
for bit in range(1 << n - 1):
sep = []
for i in range(n - 1):
if bit >> i & 1:
sep.append(i + 1)
sep.append(n)
ww = set()
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER A... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
if len(s) == 1:
return 1
if len(s) == 2:
if s[0] == s[1]:
return 1
return 2
ans = 0
for i in range(2 ** (len(s) - 1)):
ss = format(i, "0" + str(len(s) - 1) + "b")... | CLASS_DEF FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP FUNC_CALL ... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def dfs(i):
nonlocal used, ret
if i == n:
ret = max(ret, len(used))
return
for j in range(i + 1, n + 1):
w = s[i:j]
if w in used:
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN V... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def __init__(self):
self.ans = 0
self.set = set()
def maxUniqueSplit(self, s: str) -> int:
self.solve(s, 0)
return self.ans
def solve(self, s: str, pos: int) -> None:
if pos > len(s):
return
self.ans = max(self.ans, len(self.set)... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN VAR VAR FUNC_DEF VAR VAR IF VAR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL ... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
i = 0
self.res = 0
def sub(s, x):
if len(s) == 0:
if sorted(x) == sorted(list(set(x))):
self.res = max(self.res, len(set(x)))
return
for i in range(1, len(s)... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR B... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s) - 1
ans = 1
for i in range(1 << n):
subs = set()
start = 0
flag = False
for j in range(n):
if 1 << j & i:
tmp = s[start : j + 1]
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_C... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
lookup = set()
return self.traverse(s, 0, lookup)
def traverse(self, s, index, lookup):
if index > len(s):
return 0
array = []
for idx in range(index, len(s) + 1):
if len(s[index:idx]) > 0 ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP N... |
Given a string s, return the maximum number of unique substrings that the given string can be split into.
You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.
A substrin... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
def dfs(s, n):
if n < 0:
return [[s]]
else:
res = []
for i in range(1, len(s) - n):
for group in dfs(s[i:], n - 1):
res.append([s[:i]... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR NUMBER RETURN LIST LIST VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL V... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def longestPath(
self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int
) -> int:
if mat[xs][ys] == 0 or mat[xd][yd] == 0:
return -1
def dfs(r, c, pathlen, res):
if r == xd and c == yd:
res[0] = max(res[0], pathlen)
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUN... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def longestPath(
self, matrix, n: int, m: int, xs: int, ys: int, xd: int, yd: int
) -> int:
currlen = 0
def safe(matrix, xs, ys):
if (
xs < 0
or ys < 0
or xs >= len(matrix)
or ys >= len(matrix[0... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN IF FUNC_... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def longestPath(
self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int
) -> int:
if mat[xs][ys] == 0 or mat[xd][yd] == 0:
return -1
if xs == xd and ys == yd:
return 0
vis = [[(0) for i in range(m)] for j in range(n)]
def d... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR ... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def longestPath(
self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int
) -> int:
def solve(mat, n, m, xs, ys, xd, yd, cnt):
if xs == xd and yd == ys:
ans[0] = max(cnt, ans[0])
return
dir = [[0, 1], [0, -1], [1, 0],... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER RETURN ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def longestPath(self, M, R, C, sc, sr, dc, dr):
if M[sc][sr] == 0:
return -1
ans = dfs(sc, sr, R, C, M, set(), dr, dc)
return -1 if ans == 0 else ans
def dfs(r, c, R, C, M, v, dc, dr):
if (r, c) == (dr, dc):
return len(v)
v.add((r, c))
l = 0... | CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR NUMBER NUMBER VAR FUNC_DEF IF VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR ... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def longestPath(self, mat, n, m, xs, ys, xd, yd) -> int:
res = [0]
vis = [[(0) for i in range(m)] for i in range(n)]
if mat[xs][ys] == 0 or mat[xd][yd] == 0:
return -1
def recsol(row, col, temp):
if row == xd and col == yd:
re... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def longestPath(self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int):
visited = [[(0) for i in range(m)] for j in range(n)]
directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
def dfs(x, y):
if x == xd and y == yd:
return 0
mn =... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR A... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def longestPath(self, l, n, m, xs, ys, xd, yd):
if l[xs][ys] == 0 or l[xd][yd] == 0:
return -1
self.ans = -1
def ss(i, j, t):
if i == xd and j == yd:
self.ans = max(self.ans, t)
return
if i < 0 or j < 0 or ... | CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUN... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def longestPath(self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int):
visited = [[(0) for i in range(m)] for j in range(n)]
directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
def dfs(x, y):
if x == xd and y == yd:
return 0
mn =... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR A... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def rec(self, mat, i, j, n, m, temp, ans, vis, xd, yd):
if i < 0 or i >= n or j < 0 or j >= m or vis[i][j] == 1 or mat[i][j] == 0:
return
vis[i][j] = 1
if i == xd and j == yd:
ans[0] = max(ans[0], temp)
paths = [[0, 0, 1, -1], [1, -1, 0, 0]]
... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CA... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def solve(self, mat, i, j, m, n, dp, c, ans):
if (
i < 0
or j < 0
or i >= len(mat)
or j >= len(mat[0])
or mat[i][j] == 0
or dp[i][j] == False
):
return -100000000
if i == n and j == m:
... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR F... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def longestPath(
self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int
) -> int:
if mat[xs][ys] == 0 or mat[xd][yd] == 0:
return -1
def sol(mat, i, j, xd, yd, length):
if i == xd and j == yd:
if length > self.ans:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def isBound(self, x, y):
if 0 <= x < self.N and 0 <= y < self.M:
return True
return False
def dfs(self, x, y, dist):
if x == self.targetX and y == self.targetY:
self.maxLength = max(self.maxLength, dist)
return
self.mat[x][y] ... | CLASS_DEF FUNC_DEF IF NUMBER VAR VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CAL... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def longestPath(
self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int
) -> int:
row = len(mat)
col = len(mat[0])
ans = []
visited = [([False] * col) for i in range(row)]
def solve(i, j, c, visited):
if (
i < 0... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RET... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def check(self, i, j, n, m, mat):
if i < n and 0 <= i and j < m and j >= 0 and mat[i][j] == 1:
return True
return False
def find(self, i, j, x, y, n, m, mat, ans, visited, cnt):
if i == x and j == y:
ans[0] = max(ans[0], cnt)
return
... | CLASS_DEF FUNC_DEF IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER ... |
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc... | class Solution:
def longestPath(self, arr, n, m, xs, ys, xd, yd) -> int:
if arr[xd][yd] == 0:
return -1
def helper(i, j):
if i == xd and j == yd:
return 0
if i < 0 or i >= n or j < 0 or j >= m or arr[i][j] == 0:
return -100000
... | CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VA... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.