description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
def f(i, j, n, m, ind, word, board, vis):
if i < 0 or i >= n or j < 0 or j >= m or vis[i][j]:
return False
if board[i][j] == word[ind]:
if ind == len(word) - 1:
return True
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BI... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, g, d):
r = len(g)
c = len(g[0])
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
def isSafe(x, y):
return x >= 0 and y >= 0 and x < r and y < c
def bfs(x, y, k, s):
q = deque()
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF RETURN VAR NUMBER VAR NUMBER VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSI... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
l = []
for i in permutations(S):
if "".join(i) not in l:
l.append("".join(i))
return sorted(l) | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FUNC_CALL VAR VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
data = list(set(permutations(S)))
for i in range(len(data)):
data[i] = "".join(data[i])
return sorted(data) | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL STRING VAR VAR RETURN FUNC_CALL VAR VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
lst = []
all_pm = permutations(S)
for pm in all_pm:
lst.append("".join(pm))
return sorted(list(set(lst))) | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | res = []
def pl(s):
global res
r = ""
for i in s:
r += i
res += [r]
def swap(l, a, b):
t = l[a]
l[a] = l[b]
l[b] = t
def perm(s, l, r):
if l == r:
pl(s)
else:
for i in range(l, r + 1):
swap(s, l, i)
perm(s, l + 1, r)
s... | ASSIGN VAR LIST FUNC_DEF ASSIGN VAR STRING FOR VAR VAR VAR VAR VAR LIST VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_C... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
n = len(S)
def solve(ind, ds, vis):
ds.append(S[ind])
vis[ind] = 1
if len(ds) == n:
perm.append("".join(ds))
for c in range(len(vis)):
if vis[c] == 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP L... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
S = list(S)
S.sort()
ans = []
def solve(temp, s):
if len(temp) == len(S):
if "".join(temp) not in ans:
ans.append("".join(temp))
return
for i in range(len(s)):... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_O... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
k = []
l = 0
r = len(S)
S = list(S)
def find(S, l, r, k):
if l == r:
k.append("".join(S))
else:
for i in range(l, r):
S[l], S[i] = S[i], S[l]
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
if len(S) == 1:
return [S[0]]
ch = S[0]
ss = S[1:]
rr = self.find_permutation(ss)
mr = []
for ele in rr:
for i in range(len(ele) + 1):
mr.append(ele[0:i] + ch + ele[i:])
my... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN LIST VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, s):
p = permutations(s)
l = []
for i in p:
r = ""
for j in i:
r += j
l.append(r)
l.sort()
c = []
m = []
for i in l:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
res = permutations(S)
ans = set()
for i in res:
temp = ""
for j in i:
temp += j
ans.add(temp)
return sorted(ans) | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
op = ""
arr = []
vector = [False] * len(S)
self.solve(arr, op, vector, S)
arr.sort()
return arr
def solve(self, arr, op, vector, s):
if len(op) == len(s):
if op not in arr:
arr.ap... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | import itertools
class Solution:
def find_permutation(self, S):
return sorted(set(["".join(each) for each in itertools.permutations(S)]))
ans = []
S = list(S)
if len(S) == 1:
return S
for i in range(len(S)):
temp = S[i]
remaining = S[:i]... | IMPORT CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
a = ["".join(i) for i in list(permutations(S))]
b = []
for i in a:
if i not in b:
b.append(i)
b = sorted(b)
return b | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, s):
list1 = []
def dfs(s, temp, list1):
if len(s) == 0:
if temp not in list1:
list1.append(temp)
return
for i in range(len(s)):
dfs(s[:i] + s[i + 1 :], temp + s[i]... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF 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 BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR RETURN FUNC_CALL VAR VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def permutation(self, result, arr, start):
if start == len(arr) - 1:
s = "".join(arr)
result.append(s)
return
for i in range(start, len(S)):
arr[start], arr[i] = arr[i], arr[start]
self.permutation(result, arr, start + 1)
... | CLASS_DEF FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN FUNC_DEF ASSIGN VAR LIST A... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
def seq(S, ans, i):
if len(S) == i:
ans.append("".join(S))
for j in range(i, len(S)):
S[i], S[j] = S[j], S[i]
seq(S, ans, i + 1)
S[i], S[j] = S[j], S[i]
ans = []
... | CLASS_DEF FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def toString(self, List):
return "".join(List)
def backtracking(self, arr, l, r, vec):
if l == r:
if self.toString(arr) not in vec:
vec.append(self.toString(arr))
else:
for i in range(l, r):
arr[l], arr[i] = arr[i]... | CLASS_DEF FUNC_DEF RETURN FUNC_CALL STRING VAR FUNC_DEF IF VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | import itertools
class Solution:
def find_permutation(self, S):
permutations = itertools.permutations(S)
return sorted(list(dict.fromkeys(list("".join(i) for i in list(permutations))))) | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | import itertools
class Solution:
def find_permutation(self, S):
l = []
perms = set(itertools.permutations(S))
sorted_perms = sorted(perms)
for perm in sorted_perms:
s = "".join(perm)
l.append(s)
return l | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
s = permutations(S)
ans = []
for i in s:
l = ""
for j in i:
l = l + j
ans.append(l)
g = set(ans)
h = list(g)
h.sort()
retur... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def solve(self, s, ans, res):
if len(s) == 0:
if ans not in res:
res.append(ans)
return
n = len(s)
for i in range(n):
ch = s[i]
left = s[0:i]
right = s[i + 1 :]
rest = left + right
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, s):
result = []
list_s = sorted(list(s))
permutation(list_s, 0, result)
return sorted(result)
def permutation(s, index, result):
if index == len(s):
result.append("".join(s[:]))
return
for i in range(index, len(s))... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VA... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def toString(self, List):
return "".join(List)
def permute(self, a, l, r, words):
if l == r:
words.add(self.toString(a))
return
else:
for i in range(l, r):
a[l], a[i] = a[i], a[l]
self.permute(a, l + 1,... | CLASS_DEF FUNC_DEF RETURN FUNC_CALL STRING VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST AS... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
lst = []
for i in permutations(S):
lst.append("".join(i))
return sorted(set(lst)) | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | import itertools
class Solution:
def find_permutation(self, S):
a = set()
p = itertools.permutations(S, len(S))
for i in p:
a.add("".join(i))
a = sorted(a)
return a | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
res = []
def permute(a, l, r):
if l == r:
k = "".join(a)
if k not in res:
res.append(k)
else:
for i in range(l, r):
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR F... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, s):
ans = permutations(s)
ans = list(ans)
l = []
for i in ans:
k = "".join(i)
l = l + [k]
l = set(l)
l = list(l)
l.sort()
return l | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
l = []
li = permutations(S)
for i in li:
l.append("".join(i))
l = set(l)
l = list(l)
l.sort()
return l | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | import itertools
class Solution:
def find_permutation(self, S):
ans = []
x = list(itertools.permutations(S, len(S)))
for i in x:
temp = ""
for j in range(0, len(i)):
temp += i[j]
ans.append(temp)
final_ans = set(ans)
sort... | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def solve(self, arr, ind, n, res):
if ind == n:
temp = "".join(arr)
if temp not in res:
res.append(temp)
for i in range(ind, n):
arr[i], arr[ind] = arr[ind], arr[i]
self.solve(arr, ind + 1, n, res)
arr[i], a... | CLASS_DEF FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | import itertools
class Solution:
def find_permutation(self, S):
S = sorted(S)
unq_perm = []
permutations = list(itertools.permutations(S))
permutations = ["".join(i) for i in permutations]
for i in permutations:
if i not in unq_perm:
unq_perm.ap... | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, s):
res = []
def permutation(s, i):
if i == len(s):
if s not in res:
res.append(s)
elif s not in res:
for j in range(0, len(s)):
w = [w for w in s]
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR N... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
S = list(S)
res = set()
perm = []
used = [(False) for i in range(len(S))]
def backtrack():
if len(perm) == len(S):
res.add("".join(perm))
return
for i in range(len(used)):... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
l = []
a = []
f = [0] * len(S)
def x(s, l, a, f):
if len(l) == len(s):
y = "".join(l)
if y not in a:
a.append(y)
return
for i in range(len(s)):... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, s):
d = {}
for i in s:
if i in d:
d[i] += 1
else:
d[i] = 1
res = []
l = len(s)
def sol(ind, str, d):
if ind == l:
res.append(str)
r... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NU... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
P = permutations(S)
Output = []
for i in P:
Ans = "".join(i)
Output.append(Ans)
Output = list(set(Output))
Output.sort()
return Output | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
n = len(S)
res = permutations(S)
r = []
for i in res:
k = "".join(i)
if k not in r:
r.append(k)
return sorted(r) | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
result = []
def generate_permutations(current_permutation, used):
if len(current_permutation) == len(S):
result.append(current_permutation)
return
for i in range(len(S)):
if used[... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSI... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
b = []
from itertools import permutations
perms = permutations(S)
perms = sorted(perms)
dic = {}
for i in perms:
x = "".join(i)
if x not in dic:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
p = list(permutations(S))
l = []
for i in p:
s = ""
for j in i:
s += j
if s not in l:
l.append(s)
return sorted(l) | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
self.ans = []
S = list(S)
def recursive(index):
if index == len(S) - 1:
temp = S[:]
self.ans.append("".join(temp))
return
uset = set()
for i in range(index, le... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
i = 0
res = []
arr = [i for i in S]
self.func(i, res, arr)
f_ans = list(set(res))
f_ans.sort()
return f_ans
def func(self, i, res, arr):
if i == len(arr) - 1:
res.append("".join(arr))
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR A... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def permutation_rec(self, rest_letters):
if len(rest_letters) == 1:
return rest_letters[0]
new_ends = []
for i in range(len(rest_letters)):
letter = rest_letters[i]
new_rest_letters = rest_letters.copy()
new_rest_letters.remove... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
def Permutaion(ip, op):
if len(ip) == 0:
if op not in self.ans:
self.ans.append(op)
return
for i in range(len(ip)):
req_ip = ip[:i] + ip[i + 1 :]
Permu... | CLASS_DEF FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR STRING RETURN FUNC_CALL VAR VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
def permute(arr, ds, ans, start):
if len(arr) - 1 == start:
ans.append("".join(list(arr)))
return
for i in range(len(arr)):
arr[start], arr[i] = arr[i], arr[start]
permute... | CLASS_DEF FUNC_DEF FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN ASSIGN VAR LIST AS... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def helper(self, s, l, h, res):
if l == h:
res.append("".join(s))
return
for i in range(l, h):
s[i], s[l] = s[l], s[i]
self.helper(s, l + 1, h, res)
s[l], s[i] = s[i], s[l]
def find_permutation(self, S):
res = ... | CLASS_DEF FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
premList = permutations(S)
l = set()
for prem in list(premList):
l.add("".join(prem))
l = list(l)
l.sort()
return l | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def recur(self, S, index, res, path):
if index == len(S):
res.append(S[:])
return
else:
for i in range(index, len(S)):
S[i], S[index] = S[index], S[i]
self.recur(S, index + 1, res, path)
S[i], S[inde... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR EXPR ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
def backtrack(first=0, curr=[]):
if first == len(S):
result.add("".join(curr))
return
for i in range(first, len(S)):
S[i], S[first] = S[first], S[i]
backtrack(first + 1, c... | CLASS_DEF FUNC_DEF FUNC_DEF NUMBER LIST IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def ansd(self, i, S, ans):
con = len(S)
if i >= con:
if S not in ans:
ans.append(S)
return ans
else:
st = i
while st < con:
os = S
if st != i:
temp1 = os[i]
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR B... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
result = set()
def helper(string, slate):
if not string:
result.add(slate)
return
for i in range(len(string)):
helper(string[:i] + string[i + 1 :], slate + string[i])
hel... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF 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 BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING RETURN FUNC_CALL VAR FUNC_CALL VAR VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
from itertools import permutations
result = set(permutations(S))
result = sorted(["".join(p) for p in result])
return result | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, string):
chars = list(string)
chars.sort()
permutations = []
visited = [False] * len(chars)
self.backtrack(chars, visited, [], permutations)
return permutations
def backtrack(self, chars, visited, current, permutations)... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR LIST VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
perm_set = set()
def generate_permutations(s, l, r):
if l == r:
perm_set.add(s)
else:
for i in range(l, r + 1):
s_list = list(s)
s_list[l], s_list[i] = s_l... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR ... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
if len(S) == 0:
arr = []
arr.append("")
return arr
output = []
for i in range(len(S)):
smallOut = self.find_permutation(S[0:i] + S[i + 1 :])
for j in smallOut:
output.a... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR STRING RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR F... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, s):
n = len(s)
perms = set()
def permute(start, s_list):
if start == n:
perms.add("".join(s_list))
return
for i in range(start, n):
s_list[start], s_list[i] = s_list[i], s_lis... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EX... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
perms = ["".join(p) for p in permutations(S)]
for i in perms:
if perms.count(i) > 1:
perms.pop()
return sorted(set(perms)) | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def find_permutation(self, S):
def backtrack(start):
if start == len(S) - 1:
permutations.add("".join(S))
return
for i in range(start, len(S)):
S[start], S[i] = S[i], S[start]
backtrack(start + 1)
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CA... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | from itertools import permutations
class Solution:
def find_permutation(self, S):
ans = list(permutations(S))
ans.sort()
res = []
for i in ans:
str = "".join(i)
if str not in res:
res.append(str)
return res | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | import itertools as it
class Solution:
def find_permutation(self, S):
import itertools as it
x = list(it.permutations(S))
a = []
for i in x:
if "".join(i) not in a:
a.append("".join(i))
s = sorted(a)
return s | IMPORT CLASS_DEF FUNC_DEF IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def permute(self, s, temp, ans):
if len(s) == 0:
ans.append(temp)
return
for i, char in enumerate(s):
if i > 0 and char == s[i - 1]:
continue
temp += char
self.permute(s[:i] + s[i + 1 :], temp, ans)
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR RETURN... |
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order.
Example 1:
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation:
Given string ABC has permutations in 6
forms as ABC, ACB, BAC, BCA, CAB and CBA .
Example 2:
Input: ABSG
Output:
ABGS ABSG AGBS AGSB A... | class Solution:
def __init__(self):
self.ans = []
def find(self, s, i):
if i == len(s):
self.ans.append(s)
else:
for j in range(i, len(s), 1):
l = []
for k in s:
l.append(k)
temp = l[j]
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER FUNC_DE... |
You are given an array $a$ consisting of $500000$ integers (numbered from $1$ to $500000$). Initially all elements of $a$ are zero.
You have to process two types of queries to this array: $1$ $x$ $y$ — increase $a_x$ by $y$; $2$ $x$ $y$ — compute $\sum\limits_{i \in R(x, y)} a_i$, where $R(x, y)$ is the set of all i... | import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep="\n")
def solve():
q = ni()
n =... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VA... |
You are given an array $a$ consisting of $500000$ integers (numbered from $1$ to $500000$). Initially all elements of $a$ are zero.
You have to process two types of queries to this array: $1$ $x$ $y$ — increase $a_x$ by $y$; $2$ $x$ $y$ — compute $\sum\limits_{i \in R(x, y)} a_i$, where $R(x, y)$ is the set of all i... | import sys
readline = sys.stdin.buffer.readline
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
def solve():
q = ni()
n = 5 * 10**5
a = [0] * (n + 1)
m = 710
rem = [([0] * m) for _ in range(m)]
for _ in range(q):
t, x, y = nm()
if t == 1:
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VA... |
You are given an array $a$ consisting of $500000$ integers (numbered from $1$ to $500000$). Initially all elements of $a$ are zero.
You have to process two types of queries to this array: $1$ $x$ $y$ — increase $a_x$ by $y$; $2$ $x$ $y$ — compute $\sum\limits_{i \in R(x, y)} a_i$, where $R(x, y)$ is the set of all i... | import sys
n = 500001
sqrt = int(0.75 * n**0.5)
data = [0] * n
ans = [[]]
for i in range(1, sqrt):
ans.append([0] * i)
j = int(sys.stdin.readline())
qus = sys.stdin.readlines()
for qu in qus:
q = [int(i) for i in qu.split()]
if q[0] == 1:
x = q[1]
y = q[2]
data[x] += y
for i... | IMPORT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | def valid(grid, r, c, no):
if no in grid[r]:
return False
if any(grid[i][c] == no for i in range(9)):
return False
br, bc = 3 * (r // 3), 3 * (c // 3)
for i in range(br, br + 3):
for j in range(bc, bc + 3):
if grid[i][j] == no:
return False
return ... | FUNC_DEF IF VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER RETURN NUMBER ASSIGN VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUM... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
def issafe(grid, row, col, val):
for i in range(9):
if grid[row][i] == val:
return False
if grid[i][col] == val:
return False
if grid[3 * (row // 3) + i // 3][3 ... | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR ... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
ans = 0
def issafe(self, grid, x, coord):
for i in range(9):
if grid[i][coord[1]] == x:
return 0
for i in range(9):
if grid[coord[0]][i] == x:
return 0
l = coord[0] // 3
r = coord[1] // 3
for i in ra... | CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER F... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def solving(self, grid, row, col):
if row == 8 and col == 9:
return True
if col == 9:
col = 0
row += 1
if grid[row][col] > 0:
return self.solving(grid, row, col + 1)
for i in range(1, 10, 1):
if self.isvalid... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN N... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
def fun1(r, c):
for i in range(1, toggle + 1):
if (
a[r][i] == 0
and b[c][i] == 0
and cbox[hash1.index([r - r % 3, c - c % 3])][i] == 0
):
... | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR FUNC_CALL VAR LIST BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST BIN_OP ... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
def helper(grid):
for i in range(9):
for j in range(9):
if grid[i][j] == 0:
for inx in range(1, 10):
if self.isvalid(i, j, grid, inx):
... | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER RETURN FUNC_CALL... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def issafe(self, arr, number, row, col):
for i in range(len(arr)):
if arr[row][i] == number:
return False
if arr[i][col] == number:
return False
sc = col - col % 3
sr = row - row % 3
for i in range(3):
... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER RE... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
ans = self.solve(grid)
return ans
def printGrid(self, arr):
for i in range(9):
for j in range(9):
print(arr[i][j], end=" ")
def isSafe(self, row, col, grid, val):
for i in range(9):
if gri... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def isValid(self, board, ch, row, col):
for i in range(9):
if board[row][i] == ch:
return False
for i in range(9):
if board[i][col] == ch:
return False
for i in range(9):
if board[3 * (row // 3) + i // 3][3 ... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NU... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
N = 9
def isSafe(grid, row, col, num):
for x in range(9):
if grid[row][x] == num:
return False
for x in range(9):
if grid[x][col] == num:
return False
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_O... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def isValid(self, temp, board, row, col):
for i in range(9):
if board[i][col] == temp:
return False
if board[row][i] == temp:
return False
if board[3 * (row // 3) + i // 3][3 * (col // 3) + i % 3] == temp:
r... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CA... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def isvalid(self, grid, row, col, val):
for i in range(9):
if grid[row][i] == val:
return False
if grid[i][col] == val:
return False
if grid[3 * (row // 3) + i // 3][3 * (col // 3) + i % 3] == val:
return Fa... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CA... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
n = len(grid[0])
for row in range(n):
for col in range(n):
if grid[row][col] == 0:
for val in range(1, 10):
if self.isSafe(grid, row, col, val, n):
grid[r... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER RETUR... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
return self.solveUtil(grid, 0, 0)
def solveUtil(self, grid, ii, jj):
found = False
for i in range(9):
for j in range(9):
if grid[i][j] == 0:
found = True
break
i... | CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR ... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
def valid(i, j, n, r):
for x in range(9):
if grid[i][x] == r or grid[x][j] == r:
return False
sx = i // 3 * 3
sy = j // 3 * 3
for x in range(sx, sx + 3):
for y i... | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN ... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
def check(grid, row, col, k):
for i in range(9):
if grid[row][i] == k:
return False
if grid[i][col] == k:
return False
startRow = row - row % 3
startCol ... | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER RETU... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
def isSafe(i, j, num, grid):
for k in range(0, 9):
if grid[i][k] == num or grid[k][j] == num:
return False
for x in range(i // 3 * 3, i // 3 * 3 + 3):
for y in range(j // 3 * 3, j // 3 ... | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR ... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
empty_cell = self.find_empty_cell(grid)
if empty_cell == -1:
return True
for k in range(1, 10):
i, j = empty_cell
if self.is_safe(grid, i, j, k):
grid[i][j] = k
if self.SolveSudo... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VA... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def printGrid(self, arr):
for i in range(9):
for j in range(9):
print(arr[i][j], end=" ")
def used_in_row(self, arr, row, num):
for i in range(9):
if arr[row][i] == num:
return True
return False
def used_in_co... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMB... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | def canPlace(grid, i, j, num):
for r in range(9):
if grid[r][j] == num:
return False
if grid[i][r] == num:
return False
r3 = int(i / 3) * 3
c3 = int(j / 3) * 3
for r in range(3):
for c in range(3):
if grid[r3 + r][c3 + c] == num:
... | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR RET... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
n = len(grid)
m = len(grid[0])
for i in range(n):
for j in range(m):
if grid[i][j] == 0:
for c in range(1, 10):
if self.checkifokay(i, j, c, n, grid):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER RETUR... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
def checkvalid(row, col, val):
for i in range(9):
if val == grid[row][i]:
return False
if val == grid[i][col]:
return False
r = row // 3
c = col // 3
... | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NU... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
ans = []
new = [([0] * 9) for i in range(9)]
def isSafe(grid, row, col, i):
for k in range(0, 9):
if grid[row][k] == i:
return False
for k in range(0, 9):
if grid[k][col... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def __init__(self):
self.ds = []
def SolveSudoku(self, grid):
rows, cols = len(grid), len(grid[0])
def isvalid(num, grid, row, col):
for i in range(rows):
if grid[i][col] == num:
return False
if grid[row][... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUM... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
tablePossibles = []
sol = []
def ad(lista):
tmp = []
for i in range(0, 9):
vec = []
for j in range(0, 9):
vec.append(lista[i][j])
tmp.append(vec)
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FO... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
def function1(i, j, grid, k):
m = i
n = j
s = "F"
while m < 9:
if grid[m][j] == k:
return False
m = m + 1
m = i
while m >= 0:
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
return solve_sudoku(grid)
def printGrid(self, arr):
print_sudoku(arr)
def solve_sudoku_helper(grid: [[]], row: int, col: int):
if row == 9:
return True
if col == 9:
return solve_sudoku_helper(grid, row + 1, 0)
if grid[r... | CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF LIST LIST VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | import sys
sys.setrecursionlimit(10**6)
class Solution:
def is_placable(self, i, j, k):
if self.grid[i][j] == 0:
for ii in range(9):
if self.grid[i][ii] == k:
return False
for ii in range(9):
if self.grid[ii][j] == k:
... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER N... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def printGrid(self, arr):
for i in range(9):
for j in range(9):
print(arr[i][j], end=" ")
def used_in_box(self, grid, box_start_row, box_start_col, num):
for row in range(3):
for col in range(3):
if grid[row + box_start_ro... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBE... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def solve(self, grid, row, col, cell, i, j):
if j == 9:
if i == 8:
return True
else:
return self.solve(grid, row, col, cell, i + 1, 0)
if grid[i][j]:
return self.solve(grid, row, col, cell, i, j + 1)
else:
... | CLASS_DEF FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER AS... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def find_empty_cell(self, board):
for row in range(9):
for col in range(9):
if board[row][col] == 0:
return row, col
return None
def SolveSudoku(self, board):
empty_cell = self.find_empty_cell(board)
if not empty_c... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR RETURN NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR RET... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
for i in range(9):
for j in range(9):
if grid[i][j] == 0:
break
else:
continue
break
else:
return True
for i in range(9):
for j in ran... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER ... |
Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution.
A sudoku solution must satisfy all of the following rules:
Each of the digits 1-9 must occur exactly once in each row... | class Solution:
def SolveSudoku(self, grid):
for i in range(9):
for j in range(9):
if grid[i][j] == 0:
for num in range(1, 10):
if self.IsValid(grid, i, j, num):
grid[i][j] = num
... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NU... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.