description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | def is_palindrome(i, j, mat, m, n):
count = 0
t = 0
while True:
try:
if (i - t < 0 or j - t < 0) or i + t > m or j + t > n:
return count
if mat[i - t][j] == mat[i + t][j] and mat[i][j - t] == mat[i][j + t]:
count += 1
t += 1
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR RETURN VAR IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FU... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | def main():
for _ in range(int(input())):
n, m = map(int, input().split())
a = [0] * n
for i in range(n):
a[i] = list(map(int, input().split()))
ans = 0
for i in range(n):
if i == 0 or i == n - 1:
ans += m
else:
... | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR ... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | def f(n, m, i, j, l):
k = min(i, n - i - 1, j, m - j - 1)
v = 1
ans = 0
while v != k + 1:
if l[i - v][j] == l[i + v][j] and l[i][j - v] == l[i][j + v]:
ans = ans + 1
else:
break
v = v + 1
return ans
t = int(input())
for x in range(t):
n, m = map(... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RET... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | from sys import stdin
def fun(a, i, j):
p = 1
asi = 0
while 1:
if i - p >= 0 and i + p < n and j - p >= 0 and j + p < m:
if a[i - p][j] == a[i + p][j] and a[i][j - p] == a[i][j + p]:
asi = asi + 1
p = p + 1
else:
break
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FU... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | def solve(t, i, j):
count = 0
mini1 = min(i, n - 1 - i)
mini2 = min(j, m - 1 - j)
z = min(mini1, mini2) + 1
q = 1
while q < z:
if t[i][j - q] == t[i][j + q] and t[i - q][j] == t[i + q][j]:
count += 1
q += 1
else:
break
return count
for i ... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | def longestPalindrome(s):
l = len(s)
res = [0] * l
c, r = 0, 0
for i in range(l):
m = 2 * c - i
if i < r and m >= 0:
res[i] = min(r - i, res[m])
try:
while i + res[i] < l and i - res[i] >= 0 and s[i + res[i]] == s[i - res[i]]:
res[i] += 1
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR V... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | def doremon(grid):
n = len(grid)
m = len(grid[0])
summ = 0
for i in range(1, n - 1):
for j in range(1, m - 1):
for k in range(1, min(i, j, m - j - 1, n - i - 1) + 1):
if (
grid[i + k][j] == grid[i - k][j]
and grid[i][j + k] == g... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | t = int(input())
for test in range(t):
matrix = []
n, m = map(int, input().split())
trans_matrix = [[(0) for x in range(n)] for y in range(m)]
for k in range(n):
rows = list(map(int, input().split()))
matrix.append(rows)
for i in range(m):
for j in range(n):
trans... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR ... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | def count_matrix(matrix, i, j, n, m):
l = min(i - 0, n - 1 - i, j - 0, m - 1 - j)
count = 0
for k in range(l):
if (
matrix[i - k - 1][j] == matrix[i + k + 1][j]
and matrix[i][j - k - 1] == matrix[i][j + k + 1]
):
count += 1
else:
break
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMB... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | pali = lambda x: x == x[::-1]
def traverse(arr, n, m):
cnt = m * n
for i in range(n):
for j in range(m):
length = 2 * min(i, j, n - i - 1, m - j - 1) + 1
if length == 1:
continue
if (
i < length // 2
or i >= n - length... | ASSIGN VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR N... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | def pairs(matrix, n, m):
pairs = n * m
for i in range(1, n - 1):
for j in range(1, m - 1):
for k in range(min(min(n - i - 1, i), min(m - j - 1, j))):
k += 1
if (
matrix[i - k][j] == matrix[i + k][j]
and matrix[i][j + k] ... | FUNC_DEF ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR V... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | def getPairs(i, j, M, N, mat):
minSteps = min(i - 0, M - i - 1, j - 0, N - j - 1)
count = 0
for x in range(1, minSteps + 1):
if mat[i - x][j] == mat[i + x][j] and mat[i][j - x] == mat[i][j + x]:
count += 1
else:
break
return count
T = int(input())
for t in range... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | def calcPairs(A, i, j, xR, M, N):
p = 0
for x in range(1, xR):
if j + x < M and j - x >= 0 and i + x < N and i - x >= 0:
if A[i][j - x] == A[i][j + x] and A[i + x][j] == A[i - x][j]:
p += 1
continue
break
break
return p
for _ in range... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN V... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and column $j$ by $A_{i,j}$. Next, let's define a sub-row of a row $r$ a... | def manachars(arr, n, l):
n = 2 * n + 1
c = 1
r = 2
diff = -1
imirror = -1
l[1] = 1
for i in range(2, n):
imirror = 2 * c - i
diff = r - i
if diff > 0:
l[i] = min(diff, l[imirror])
try:
while (
i + l[i] < n
... | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE BIN_OP VAR ... |
Implement a basic calculator to evaluate a simple expression string.
The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces .
Example 1:
Input: "1 + 1"
Output: 2
Example 2:
Input: " 2-1 + 2 "
Output: 3
Example 3:
Input: "(1+(4+5... | class Solution:
def calculate(self, s):
sign = [1]
nums = 0
total = 0
latestsign = 1
for c in s:
if c.isdigit():
nums = 10 * nums + int(c)
elif c == "(":
nums = 0
sign.append(latestsign)
elif... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBE... |
Implement a basic calculator to evaluate a simple expression string.
The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces .
Example 1:
Input: "1 + 1"
Output: 2
Example 2:
Input: " 2-1 + 2 "
Output: 3
Example 3:
Input: "(1+(4+5... | class Solution:
def calculate(self, s):
total, tmp, sign = 0, 0, 1
numStack = []
signStack = []
for c in s:
if c == "+":
total, tmp, sign = total + tmp * sign, 0, 1
elif c == "-":
total, tmp, sign = total + tmp * sign, 0, -1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR ... |
Implement a basic calculator to evaluate a simple expression string.
The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces .
Example 1:
Input: "1 + 1"
Output: 2
Example 2:
Input: " 2-1 + 2 "
Output: 3
Example 3:
Input: "(1+(4+5... | class Solution:
def calculate(self, s):
result = number = 0
sign = 1
stack = []
for i in s:
if i == " ":
continue
if i.isdigit():
number = number * 10 + int(i)
elif i == "+":
result += sign * number
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR STRING IF FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STR... |
Implement a basic calculator to evaluate a simple expression string.
The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces .
Example 1:
Input: "1 + 1"
Output: 2
Example 2:
Input: " 2-1 + 2 "
Output: 3
Example 3:
Input: "(1+(4+5... | class Solution:
def calculate(self, s):
res = 0
num = 0
sign = 1
stk = []
for c in s:
if c.isdigit():
num = 10 * num + (ord(c) - ord("0"))
elif c == "+":
res += sign * num
num = 0
sign = ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR STRING VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ... |
Implement a basic calculator to evaluate a simple expression string.
The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces .
Example 1:
Input: "1 + 1"
Output: 2
Example 2:
Input: " 2-1 + 2 "
Output: 3
Example 3:
Input: "(1+(4+5... | class Solution:
def calculate(self, s):
expression = s
s = []
res = 0
curr = 0
sign = 1
for c in expression:
if c.isdigit():
curr *= 10
curr += int(c)
if c == "+":
res += sign * curr
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING EX... |
Implement a basic calculator to evaluate a simple expression string.
The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces .
Example 1:
Input: "1 + 1"
Output: 2
Example 2:
Input: " 2-1 + 2 "
Output: 3
Example 3:
Input: "(1+(4+5... | class Solution:
def calculate(self, s):
stack = []
res = 0
sign = 1
number = 0
for i in range(len(s)):
c = s[i]
if c.isdigit():
number = number * 10 + int(c)
elif c == "+":
res += number * sign
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR BIN_OP VAR VAR... |
Implement a basic calculator to evaluate a simple expression string.
The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces .
Example 1:
Input: "1 + 1"
Output: 2
Example 2:
Input: " 2-1 + 2 "
Output: 3
Example 3:
Input: "(1+(4+5... | class Solution:
def calculate(self, s):
if not s:
return 0
res = 0
sign = 1
stack = [1]
num = 0
for c in s:
if c <= "9" and c >= "0":
num = num * 10 + ord(c) - ord("0")
elif c in "+-":
res += sign * ... | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR STRING VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_... |
Given two integers N and K. The task is to find the string S of minimum length such that it contains all possible strings of size N as a substring. The characters of the string can be from 0 to K-1.
Example 1:
Input:
N = 2, K = 2
Output:
00110
Explanation:
There are 4 string possible of size N=2
which contains cha... | import sys
class Solution:
res = ""
def dfs(self, ans, d, tot, N, K):
global res
if len(d) == tot:
res = ans
return True
tmp = ""
if N > 1:
tmp = ans[len(ans) - N + 1 :]
for i in range(K):
tmp += chr(48 + i)
i... | IMPORT CLASS_DEF ASSIGN VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR RETURN NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER I... |
Given two integers N and K. The task is to find the string S of minimum length such that it contains all possible strings of size N as a substring. The characters of the string can be from 0 to K-1.
Example 1:
Input:
N = 2, K = 2
Output:
00110
Explanation:
There are 4 string possible of size N=2
which contains cha... | class Solution:
def findString(self, N, K):
str_char = []
for i in range(K):
str_char.append(str(i))
all_str = []
def dfs(cur_str):
if len(cur_str) == N:
all_str.append(cur_str)
return
for i in range(len(str_char))... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR FOR VAR VA... |
Given two integers N and K. The task is to find the string S of minimum length such that it contains all possible strings of size N as a substring. The characters of the string can be from 0 to K-1.
Example 1:
Input:
N = 2, K = 2
Output:
00110
Explanation:
There are 4 string possible of size N=2
which contains cha... | class Solution:
def __init__(self):
self.ans = []
def findString(self, n, k):
if n == 1:
l = [str(i) for i in range(k)]
return "".join(l)
if k == 1:
return "0" * n
dic = {}
def backtrack(s, ans):
if len(ans) == k**n + n -... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING VAR IF VAR NUMBER RETURN BIN_OP STRING VAR ASSIGN VAR DICT FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN IF VAR VAR VAR VAR VAR RETURN IF VAR... |
Given two integers N and K. The task is to find the string S of minimum length such that it contains all possible strings of size N as a substring. The characters of the string can be from 0 to K-1.
Example 1:
Input:
N = 2, K = 2
Output:
00110
Explanation:
There are 4 string possible of size N=2
which contains cha... | class Solution:
def findString(self, n, k):
out = [0]
combs = set()
def dfs(n, string):
if n == 0:
combs.add(string)
return
for i in range(K):
dfs(n - 1, string + str(i))
vis = set()
def find(comb, st... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMB... |
Given two integers N and K. The task is to find the string S of minimum length such that it contains all possible strings of size N as a substring. The characters of the string can be from 0 to K-1.
Example 1:
Input:
N = 2, K = 2
Output:
00110
Explanation:
There are 4 string possible of size N=2
which contains cha... | class Solution:
def findString(self, N, K):
def __init__(self):
self.a = None
def dfs(n, k, string, ans):
if n == 0:
ans.add(string)
return ans
for i in range(k):
ans = dfs(n - 1, k, string + str(i), ans)
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NONE FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN NUMBER FOR V... |
Given two integers N and K. The task is to find the string S of minimum length such that it contains all possible strings of size N as a substring. The characters of the string can be from 0 to K-1.
Example 1:
Input:
N = 2, K = 2
Output:
00110
Explanation:
There are 4 string possible of size N=2
which contains cha... | class Solution:
res = ""
def dfs(self, ans, d, tot, N, K):
global res
if len(d) == tot:
res = ans
return True
tmp = ""
if N > 1:
tmp = ans[len(ans) - N + 1 :]
for i in range(K):
tmp += chr(48 + i)
if tmp not in ... | CLASS_DEF ASSIGN VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR RETURN NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER IF FUNC_... |
Given two integers N and K. The task is to find the string S of minimum length such that it contains all possible strings of size N as a substring. The characters of the string can be from 0 to K-1.
Example 1:
Input:
N = 2, K = 2
Output:
00110
Explanation:
There are 4 string possible of size N=2
which contains cha... | from itertools import product
class Solution:
def findString(self, n, k):
perms = set(map(lambda x: "".join(x), product(map(str, range(k)), repeat=n)))
ans = []
def dfs(node):
if not perms:
return
for d in map(str, range(k)):
next_ ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL... |
Given two integers N and K. The task is to find the string S of minimum length such that it contains all possible strings of size N as a substring. The characters of the string can be from 0 to K-1.
Example 1:
Input:
N = 2, K = 2
Output:
00110
Explanation:
There are 4 string possible of size N=2
which contains cha... | import sys
class Solution:
seen = []
edge = []
def dfs(node, k, A):
for i in range(k):
str_ = node + A[i]
if str_ not in Solution.seen:
Solution.seen.append(str_)
Solution.dfs(str_[1:], k, A)
Solution.edge.append(i)
def ... | IMPORT CLASS_DEF ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BI... |
Given two integers N and K. The task is to find the string S of minimum length such that it contains all possible strings of size N as a substring. The characters of the string can be from 0 to K-1.
Example 1:
Input:
N = 2, K = 2
Output:
00110
Explanation:
There are 4 string possible of size N=2
which contains cha... | class Solution:
def findString(self, N, K):
total = K**N
visited = set()
ans = ""
def dfs(subs, counter, res):
if counter == total:
nonlocal ans
ans = res
return True
for digit in range(K):
newS... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FUNC_DEF IF VAR VAR ASSIGN VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR RETURN N... |
Given two integers N and K. The task is to find the string S of minimum length such that it contains all possible strings of size N as a substring. The characters of the string can be from 0 to K-1.
Example 1:
Input:
N = 2, K = 2
Output:
00110
Explanation:
There are 4 string possible of size N=2
which contains cha... | class Solution:
def findString(self, N, K):
ans = "0" * (N - 1)
str_set = set()
for i in range(K**N):
substr = ans[-N + 1 :] if N > 1 else ""
for j in range(K - 1, -1, -1):
if substr + str(j) not in str_set:
str_set.add(substr + st... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FUN... |
Given two integers N and K. The task is to find the string S of minimum length such that it contains all possible strings of size N as a substring. The characters of the string can be from 0 to K-1.
Example 1:
Input:
N = 2, K = 2
Output:
00110
Explanation:
There are 4 string possible of size N=2
which contains cha... | class Solution:
def __init__(self):
self.ans = ""
def findString(self, N, K):
h = {}
def dfs(a):
for i in range(K):
new = a + str(i)
if new not in h:
h[new] = True
dfs(new[1:])
self... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING FUNC_DEF ASSIGN VAR DICT FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER 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:
ans = [0]
def split(curr, ind):
if ind >= len(s):
return len(curr)
for i in range(ind + 1, len(s) + 1):
tmp = curr.copy()
tmp.add(s[ind:i])
s1 = split(tm... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN ... |
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 func(string: str, visited: set):
if string in visited or len(string) == 0:
return 0
res = 1
for i in range(len(string)):
s = string[: i + 1]
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FUNC_DEF VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER 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, seen=()) -> int:
return max(
(
1 + self.maxUniqueSplit(s[i:], {candidate, *seen})
for i in range(1, len(s) + 1)
if (candidate := s[:i]) not in seen
),
default=0,
) | CLASS_DEF FUNC_DEF VAR 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 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:
combin_dict = {s[0]: [set(s[0])]}
for index, char in enumerate(s[1:]):
new_dict = {}
for last_str, sets in combin_dict.items():
for combin_set in sets:
if char not in new_dict:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT VAR NUMBER LIST FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER 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:
to_ret = 0
for bin_i in range(2 ** (len(s) - 1)):
to_deal = set()
mark = True
last = s[0]
for i in range(len(s) - 1):
cn = s[i + 1]
if bin_i & 1 << i:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN 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.N = len(s)
wordset = set(s)
if len(wordset) >= self.N - 1:
return len(wordset)
self.cur = 0
def dfs(i, visit, num):
if self.N - i + num <= self.cur:
return
if s... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF BIN_OP BIN_OP VAR VAR VAR VAR RETURN IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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:
start = 0
end = 0
se = set()
res = 0
def helper(stn, se, count):
nonlocal res
if not stn:
res = max(res, count)
if len(stn) + count <= res:
return
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR 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:
dp = [[] for i in range(len(s))]
dp[0].append([s[0]])
for i in range(1, len(s)):
for j in range(len(dp[i - 1])):
comb = dp[i - 1][j]
dp[i].append(comb[:-1] + [comb[-1] + s[i]])
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER LIST 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 self.dfs(s, 0, [])
def dfs(self, s, index, ele):
currMax = 0
for i in range(index, len(s)):
if s[index : i + 1] not in ele:
currMax = max(
currMax, 1 + self.dfs(s, i + 1, ele... | CLASS_DEF FUNC_DEF VAR RETURN FUNC_CALL VAR VAR NUMBER LIST VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR BIN_OP VAR NUMBER 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:
l = len(s)
for i in range(l - 1, 0, -1):
for j in itertools.combinations(range(1, l), i):
cut = [0] + list(j)
subs = []
for k in range(len(cut)):
if k == len(cut)... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL 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 check(s):
if len(s) == 1:
return [[s]]
if len(s) == 0:
return [[]]
ans = []
for i in range(1, len(s) + 1):
for item in check(s[i:]):
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN LIST LIST VAR IF FUNC_CALL VAR VAR NUMBER RETURN LIST LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSI... |
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.result = 0
def maxUniqueSplit(self, s: str) -> int:
if not s:
return 0
def backtrack(start, cur):
if start == len(s):
self.result = max(self.result, len(set(cur)))
return
for i... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF VAR IF VAR RETURN NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR LIST VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL 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 maxUniqueSplit(self, s: str) -> int:
if not s:
return 0
self.answer = 0
substrings = []
def backtrack(start_i):
if start_i == len(s):
self.answer = max(self.answer, len(set(substrings)))
return
... | CLASS_DEF FUNC_DEF VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR VAR VAR EXPR FUNC_CALL VAR VAR 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:
def explore(seen, s):
for i in range(1, len(s)):
word, other = s[:i], s[i:]
if word in seen:
continue
explore(seen + [word], other)
else:
if ... | CLASS_DEF FUNC_DEF VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN 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:
words = list(s)
N = len(words)
ans = 0
def backtrack(words, s):
nonlocal ans
n = len(words)
if n == 0:
ans = max(len(s), ans)
for i in range(1, n + 1):
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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 solve(S, subs):
if not S:
return len(subs)
ans = 0
for i in range(len(S)):
sub = S[: i + 1]
ans = max(ans, solve(S[i + 1 :], subs | {sub}))
return an... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN VAR RETURN FUNC_CALL VAR 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)
self.res = 0
def dfs(strs, s):
if not s:
if len(set(strs)) == len(strs):
self.res = max(self.res, len(strs))
return
dfs(strs + [s[0]], s[1:])
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER LIST BIN_OP 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:
ans, n = 0, len(s)
def dfs(i, cnt, visited):
nonlocal ans, n
if i == n:
ans = max(ans, cnt)
for j in range(i + 1, n + 1):
if s[i:j] in visited:
continue
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL 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:
def dfs(s, path):
res = 0
if not s:
return len(path)
for i in range(1, len(s) + 1):
res = max(res, dfs(s[i:], path | {s[:i]}))
return res
return dfs(s, set()) | CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR RETURN VAR RETURN FUNC_CALL VAR 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... | from itertools import combinations
class Solution:
def maxUniqueSplit(self, s: str) -> int:
n = len(s)
if n == 1:
return 1
from itertools import combinations
L = list(range(1, n))
for d in range(n - 1, 0, -1):
for x in combinations(L, d):
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER FUNC_CALL VAR VAR LIST VAR ASSIGN VAR VAR VAR VAR 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:
visited = set()
def dfs(start):
nonlocal visited
if start == len(s):
return 0
res = 0
for i in range(start, len(s)):
if s[start : i + 1] not in visited:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP 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, ss: str) -> int:
@lru_cache(None)
def dfs(s, words):
if not s:
return 0
res = 0
words = set(words)
for i in range(len(s)):
if s[: i + 1] not in words:
res = ... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER RETURN... |
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
def findSplit(num):
bin_str = (bin(num)[2:] + "0").zfill(N)
words = []
word = []
for c, binary in zip(s, bin_str):
word.append(c)
if b... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL BIN_OP FUNC_CALL VAR VAR NUMBER STRING VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR LIST IF 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:
exist = collections.defaultdict(int)
self.result = 0
n = len(s)
def dfs(index: int) -> None:
if index == n:
self.result = max(self.result, len(exist))
return
for i in ra... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF VAR 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 VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF 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:
self.x, n = 0, len(s)
def maxUniqueSplit_(i=0, S=set()):
if s[i:] not in S:
self.x = max(self.x, len(S) + 1)
for j in range(i + 1, n):
if s[i:j] not in S and len(S) + 1 + n - j > self.x... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_DEF NUMBER FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR 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:
visited = set()
def solve(cur: str) -> int:
ans = 0
if not cur:
return 0
for i in range(1, len(s) + 1):
candidate = cur[:i]
if candidate not in visited:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF VAR ASSIGN VAR NUMBER IF VAR RETURN 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 VAR RET... |
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(i, s, seen):
if i > len(s) - 1:
return len(seen)
max_len = 1
for k in range(i, len(s)):
temp = set(seen)
temp.add(s[i : k + 1])
max_len = ... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR RETURN 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._s = s
self.best = 1
self.solve(0, set(), 0)
return self.best
def solve(self, index, seen, count):
s = self._s
if index >= len(s):
self.best = max(self.best, count)
for end in rang... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 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 _dfs(self, s, i, visited):
if i == len(s):
yield len(visited)
return
for j in range(i + 1, len(s) + 1):
if s[i:j] not in visited:
visited.add(s[i:j])
yield from self._dfs(s, j, visited)
visited.r... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN 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 EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF VAR IF VAR RETURN NUMBER RETURN FUNC_CALL VAR 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 divide(s):
for i in range(1, len(s)):
low = s[0:i]
high = s[i:]
yield low, high
for div in divide(high):
ret = [low]
ret.extend(d... | CLASS_DEF FUNC_DEF VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF 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:
ls = len(s)
sl = ls - 1
ps = 1 << sl
ans = 0
for i in range(ps):
bi = bin(i)[2:].zfill(sl)
si = [0] + [(j + 1) for j in range(sl) if bi[j] == "0"] + [sl + 1]
lsi = len(si)
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR 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 FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR STRING LIST BIN_OP 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... | def walk_divisions(string, covered, cut):
if cut == len(string):
yield len(covered)
else:
for nxt in range(cut + 1, len(string) + 1):
substring = string[cut:nxt]
if substring not in covered:
covered.append(substring)
yield from walk_divisio... | FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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 VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FUNC_CALL VAR VAR NUMBER RETURN 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 solve(last, idx, cur):
if idx == len(s):
if len(cur) == len(set(cur)):
self.ans = max(self.ans, len(cur))
return
cur.append(s[last : idx + 1])
solve(idx + 1,... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR 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:
N = len(s)
def splitLookup(ss, used):
Ns = len(ss)
if ss in used:
maxSs = 0
else:
maxSs = 1
i = 1
while i < Ns and Ns - i > maxSs - 1:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN 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:
res = 0
dfs = [[set(), s]]
while dfs:
curSet, curS = dfs.pop()
res = max(res, len(curSet))
if len(curSet) + len(curS) <= res or len(curS) == 0:
continue
for i in range(le... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR LIST LIST FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR 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:
n = len(S)
ans = 0
for U in range(1 << n - 1):
word = []
now = S[0]
for j in range(n - 1):
if U >> j & 1:
word.append(now)
now = S[j + 1]
... | 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 ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER 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:
used = set()
self.res = 1
self.backtrack(s, 0, used)
return self.res
def backtrack(self, s, cur, used):
if not s:
self.res = max(self.res, cur)
return
for i in range(1, len(s) + 1):... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR RETURN VAR VAR FUNC_DEF IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER 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:
if len(s) == 1:
return 1
n = len(s)
dp = [0] * (n + 1)
dp[0] = [set()]
for end in range(1, n + 1):
ls = []
sub = set()
for start in range(end):
for ele in... | CLASS_DEF FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER LIST FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR 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... | class Solution:
def maxUniqueSplit(self, s: str) -> int:
to_ret = 0
for bin_i in range(2 ** (len(s) - 1)):
to_deal = []
last = s[0]
for i in range(len(s) - 1):
cn = s[i + 1]
if bin_i & 1 << i > 0:
to_deal.append... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR I... |
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 len(s) == 0:
return []
if len(s) == 1:
return [[s]]
res = []
for i in range(1, len(s) + 1):
ans = [s[:i]]
splits = split... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN LIST IF FUNC_CALL VAR VAR NUMBER RETURN LIST LIST VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP 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:
N = len(s) - 1
res = 1
for m in range(1 << N):
I = [i for i in range(N) if m >> i & 1] + [N]
K = len(I)
ss = {s[: I[0] + 1]}
for k in range(K - 1):
ss.add(s[I[k] + 1 : I[... | 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 BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER LIST VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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 helper(self, s, occur):
if len(s) == 0:
return 0
curMax = -1
for i in range(1, len(s) + 1):
if s[:i] not in occur:
occur.append(s[:i])
if (s[i:], tuple(occur)) in self.memo:
res = self.memo[s[i:]... | CLASS_DEF 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 IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CAL... |
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
seen = set()
def search(i):
if i == len(s):
self.ans = max(len(seen), self.ans)
return
for j in range(i, len(s)):
word = s[i : j + 1]
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN 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 EXPR FUNC_CALL 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:
def helper(s, seen=set()):
maximum = 0
for i in range(1, len(s) + 1):
candidate = s[:i]
if candidate not in seen:
maximum = max(maximum, 1 + helper(s[i:], {candidate, *seen}... | CLASS_DEF FUNC_DEF VAR FUNC_DEF FUNC_CALL 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 BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR VAR RETURN 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... | from itertools import combinations
class Solution:
def maxUniqueSplit(self, s: str) -> int:
from itertools import combinations
for k in reversed(list(range(len(s) + 1))):
for comb in combinations(list(range(1, len(s))), k):
split_idxs = [0, *comb, len(s)]
... | CLASS_DEF FUNC_DEF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF ... |
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 bitsoncount(x):
return bin(x).count("1")
ans = 0
n = len(s)
seen = defaultdict(int)
for m in range(1 << n):
if bitsoncount(m) <= ans:
continue
prev = 0
... | CLASS_DEF FUNC_DEF VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER 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:
positions = []
for i in range(1, len(s)):
positions.append(i)
if len(s) < 3:
if s[0] != s[1]:
return 2
maximally_split = 1
for i in range(1, len(s)):
... | IMPORT CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR NU... |
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.bt(s, set(), 0, 0)
def bt(self, s, d, l, maxl):
if l >= len(s):
maxl = max(len(d), maxl)
return maxl
else:
for r in range(l + 1, len(s) + 1):
if s[l:r] not in d:
... | CLASS_DEF FUNC_DEF VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN 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 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:
return self.helper(s, set())
def helper(self, s, set):
if len(s) == 1 and s in set:
return 0
max_split = len(set) + 1
for i in range(1, len(s)):
a = s[:i]
b = s[i:]
max_spli... | CLASS_DEF FUNC_DEF VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETUR... |
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
def dfs(cur_pos):
nonlocal res
if cur_pos == len(s):
res = max(res, len(seen))
for next_pos in range(cur_pos, len(s)):
if s[cur_pos : next_pos + 1] not in seen:
... | CLASS_DEF FUNC_DEF 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 VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR 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:
def f(s, seen):
if not s:
return 0
res = 0
for i in range(1, len(s) + 1):
chunk = s[:i]
if chunk not in seen:
res = max(res, f(s[i:], seen | {chu... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR 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 ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR 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:
if not s:
return 0
splits = [[] for _ in range(len(s))]
best_len = 0
for i, c in enumerate(s):
splits[i].append(set([s[: i + 1]]))
best_len = max(best_len, 1)
for j in range(1, i... | CLASS_DEF FUNC_DEF VAR IF VAR RETURN NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR 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:
self.result = []
n = len(s)
self.backtrack(s, 0, n, [])
return len(max(self.result, key=len))
def backtrack(self, s, left, n, currArr):
if left >= n:
self.result.append(currArr)
for i in range(... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR LIST RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR 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 maxUniqueSplit(self, s: str) -> int:
def permutations(s):
result = [[s]]
for i in range(1, len(s)):
start = [s[:i]]
end = s[i:]
for p in permutations(end):
result.append(start + p)
r... | CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR LIST LIST VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF 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:
n = len(s)
ans = 1
for i in range(2 ** (n - 1)):
b = "1" + bin(i)[2:].zfill(n - 1) + "1"
pr = 0
w = set()
flag = True
for k in range(1, n + 1):
if k == n or b... | 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 BIN_OP BIN_OP STRING FUNC_CALL FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER 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:
r = 0
m = len(s)
for i in range(2 ** (m - 1)):
bb = "{0:0" + str(m - 1) + "b}"
b = bb.format(i)
st = 0
l = []
for k in range(len(b)):
if b[k] == "1":
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING 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:
ans = 0
for i in range(1, 2 ** (len(s) - 1) + 1):
prev = 0
seen = set()
for j in range(0, len(s)):
if i & 1 << j:
seen.add(s[prev : j + 1])
prev = j +... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN 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:
d = {}
for i in s:
if i in d:
d[i] += 1
else:
d[i] = 1
if len(d) == len(s):
return len(d)
def waysToSplit(s):
if not s:
return []... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR RETURN LIST IF FUNC_CALL VAR VAR NUMBER RETURN LIST LIST VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST 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:
self.S = 0
def dfs(s, tmp):
if s == "":
self.S = max(self.S, len(tmp))
for i in range(1, len(s) + 1):
if s[:i] not in tmp:
dfs(s[i:], tmp + [s[:i]])
dfs(s, ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FUNC_DEF 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 VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR LIST 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:
self.ans = 0
def dfs(node, seen):
if node == len(s):
self.ans = max(self.ans, len(seen))
for i in range(node, len(s)):
if s[node : i + 1] not in seen:
dfs(i + 1, see... | CLASS_DEF FUNC_DEF 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 VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR RETURN ... |
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.max = 0
self.backtrack(s, set(), 0)
return self.max
def backtrack(self, s, store, l):
if l >= len(s):
self.max = max(self.max, len(store))
for i in range(l, len(s) + 1):
if s[l:i] not ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER RETURN VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR 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:
def rec(i, myset):
if i == len(s):
return 0
ans = -float("inf")
for j in range(i, len(s)):
if s[i : j + 1] not in myset:
ans = max(ans, 1 + rec(j + 1, myset | se... | CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER RETURN 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:
res = [[s[0]]]
for i in s[1:]:
for _ in range(len(res)):
j = res.pop(0)
res.append(j + [i])
res.append(j[:-1] + [j[-1] + i])
return max(list(map(len, list(map(set, res))))) | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST LIST VAR NUMBER FOR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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:
n = len(s)
maxi = 0
def sub(ind, ar):
if ind == n:
if len(ar) == len(set(ar)):
return len(ar)
return maxi
a = ar + [s[ind]]
b = ar[:]
... | CLASS_DEF FUNC_DEF 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 RETURN FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR LIST VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL 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:
return self.dfs(s, 0, 1, set())
def dfs(self, s, start, end, dic):
if end >= len(s):
return 0 if s[start:] in dic else 1
k1 = 0
if s[start:end] not in dic:
dic.add(s[start:end])
k1 = 1 ... | CLASS_DEF FUNC_DEF VAR RETURN FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR 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:
def solve(start, visited, memo):
state = start, tuple(visited)
if start >= len(s):
return 0
if state in memo:
return memo[state]
result = 0
for idx in range(... | CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN 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:
c = collections.Counter(s)
res = len(c.keys())
l = len(s)
ways = int(math.pow(2, l - 1))
for i in range(ways):
bit = str(bin(i))[2:].zfill(l - 1)
cand = [s[0]]
for i, x in enumerate(... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR 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:
max_length = 1
for code in range(2 ** (len(s) - 1)):
subs = set()
cur = s[0]
for i in range(1, len(s)):
if code % 2 == 1:
if cur in subs:
break
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NU... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.