description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
You are given an array of size N. Rearrange the given array in-place such that all the negative numbers occur before all non-negative numbers.
(Maintain the order of all -ve and non-negative numbers as given in the original array).
Example 1:
Input:
N = 4
Arr[] = {-3, 3, -2, 2}
Output:
-3 -2 3 2
Explanation:
In the giv... | def Rearrange(a, n):
m = []
p = []
for i in range(0, n):
if a[i] < 0:
m.append(a[i])
else:
p.append(a[i])
c = m + p
for i in range(0, n):
a[i] = c[i] | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR |
You are given an array of size N. Rearrange the given array in-place such that all the negative numbers occur before all non-negative numbers.
(Maintain the order of all -ve and non-negative numbers as given in the original array).
Example 1:
Input:
N = 4
Arr[] = {-3, 3, -2, 2}
Output:
-3 -2 3 2
Explanation:
In the giv... | def Rearrange(a, n):
pos, neg = [], []
for i in a:
if i < 0:
neg.append(i)
else:
pos.append(i)
a.clear()
a.extend(neg + pos) | FUNC_DEF ASSIGN VAR VAR LIST LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
You are given an array of size N. Rearrange the given array in-place such that all the negative numbers occur before all non-negative numbers.
(Maintain the order of all -ve and non-negative numbers as given in the original array).
Example 1:
Input:
N = 4
Arr[] = {-3, 3, -2, 2}
Output:
-3 -2 3 2
Explanation:
In the giv... | def Rearrange(a, n):
d = []
e = []
for i in range(n):
if a[i] < 0:
d.append(a[i])
else:
e.append(a[i])
a[:] = d[:] + e[:]
return a | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR |
You are given an array of size N. Rearrange the given array in-place such that all the negative numbers occur before all non-negative numbers.
(Maintain the order of all -ve and non-negative numbers as given in the original array).
Example 1:
Input:
N = 4
Arr[] = {-3, 3, -2, 2}
Output:
-3 -2 3 2
Explanation:
In the giv... | def Rearrange(a, n):
negin = 0
posin = 0
while posin < n:
if a[posin] < 0:
a.insert(negin, a.pop(posin))
posin += 1
negin += 1
else:
posin += 1 | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER |
You are given an array of size N. Rearrange the given array in-place such that all the negative numbers occur before all non-negative numbers.
(Maintain the order of all -ve and non-negative numbers as given in the original array).
Example 1:
Input:
N = 4
Arr[] = {-3, 3, -2, 2}
Output:
-3 -2 3 2
Explanation:
In the giv... | def Rearrange(a, n):
p = []
ne = []
for i in a:
if i < 0:
ne += [i]
else:
p += [i]
b = ne + p
for i in range(n):
a[i] = b[i] | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR LIST VAR VAR LIST VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR |
You are given an array of size N. Rearrange the given array in-place such that all the negative numbers occur before all non-negative numbers.
(Maintain the order of all -ve and non-negative numbers as given in the original array).
Example 1:
Input:
N = 4
Arr[] = {-3, 3, -2, 2}
Output:
-3 -2 3 2
Explanation:
In the giv... | def Rearrange(a, n):
Pos = []
Neg = []
for i in a:
if i >= 0:
Pos.append(i)
else:
Neg.append(i)
a.clear()
a.extend(Neg)
a.extend(Pos) | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given an array of size N. Rearrange the given array in-place such that all the negative numbers occur before all non-negative numbers.
(Maintain the order of all -ve and non-negative numbers as given in the original array).
Example 1:
Input:
N = 4
Arr[] = {-3, 3, -2, 2}
Output:
-3 -2 3 2
Explanation:
In the giv... | def Rearrange(a, n):
stack = []
for i in range(n - 1, -1, -1):
if a[i] >= 0:
stack.append(a[i])
k = 0
for i in range(n):
if a[i] < 0:
a[k] = a[i]
k += 1
while len(stack) > 0:
a[k] = stack.pop()
k += 1
return a | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER RETURN VAR |
You are given an array of size N. Rearrange the given array in-place such that all the negative numbers occur before all non-negative numbers.
(Maintain the order of all -ve and non-negative numbers as given in the original array).
Example 1:
Input:
N = 4
Arr[] = {-3, 3, -2, 2}
Output:
-3 -2 3 2
Explanation:
In the giv... | def Rearrange(a, n):
pos = []
neg = []
for i in a:
if i < 0:
neg.append(i)
else:
pos.append(i)
a.clear()
for i in range(len(neg)):
a.append(neg[i])
for i in range(len(pos)):
a.append(pos[i])
return a | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR |
You are given an array of size N. Rearrange the given array in-place such that all the negative numbers occur before all non-negative numbers.
(Maintain the order of all -ve and non-negative numbers as given in the original array).
Example 1:
Input:
N = 4
Arr[] = {-3, 3, -2, 2}
Output:
-3 -2 3 2
Explanation:
In the giv... | def Rearrange(a, n):
ne = []
p = []
for i in a:
if i < 0:
ne.append(i)
else:
p.append(i)
i = 0
m = len(ne)
j = 0
while i < n and j < m:
a[i] = ne[j]
i += 1
j += 1
q = len(p)
j = 0
while i < n and j < q:
a[i] ... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN... |
You are given an array of size N. Rearrange the given array in-place such that all the negative numbers occur before all non-negative numbers.
(Maintain the order of all -ve and non-negative numbers as given in the original array).
Example 1:
Input:
N = 4
Arr[] = {-3, 3, -2, 2}
Output:
-3 -2 3 2
Explanation:
In the giv... | def Rearrange(A, n):
def merge(L, R):
if L == R:
if A[L] < 0:
return L, L + 1, R + 1
else:
return L, L, R + 1
m = (L + R) // 2
Lns, Lne, Lpe = merge(L, m)
Rns, Rne, Rpe = merge(m + 1, R)
A[Lne:Lpe] = reversed(A[Lne:Lpe]... | FUNC_DEF FUNC_DEF IF VAR VAR IF VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR V... |
You are given an array of size N. Rearrange the given array in-place such that all the negative numbers occur before all non-negative numbers.
(Maintain the order of all -ve and non-negative numbers as given in the original array).
Example 1:
Input:
N = 4
Arr[] = {-3, 3, -2, 2}
Output:
-3 -2 3 2
Explanation:
In the giv... | def Rearrange(arr, n):
pos = list()
neg = list()
for i in range(n):
if arr[i] < 0:
neg.append(arr[i])
else:
pos.append(arr[i])
i = 0
while neg:
arr[i] = neg.pop(0)
i += 1
while pos:
arr[i] = pos.pop(0)
i += 1
return arr | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER RETURN VAR |
Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules:
You receive a valid board, made of only battleships or empty slots.
Battleships can only be placed horizontally or vertically. In other words, ... | class Solution:
def countBattleships(self, board):
num = 0
record = [(-1, -1)]
colnum = 0
for i in board:
rownum = 0
cont = 0
for j in i:
if j == "X":
if cont == 1:
rownum += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EX... |
Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules:
You receive a valid board, made of only battleships or empty slots.
Battleships can only be placed horizontally or vertically. In other words, ... | class Solution:
def countBattleships(self, board):
ans = 0
for r, row in enumerate(board):
for c, val in enumerate(row):
if val == "X":
ans += 1
if r and board[r - 1][c] == "X":
ans -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER RETURN VAR |
Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules:
You receive a valid board, made of only battleships or empty slots.
Battleships can only be placed horizontally or vertically. In other words, ... | class Solution:
def countBattleships(self, board):
count = 0
for i in range(len(board)):
for j in range(len(board[i])):
if board[i][j] == "X":
if i - 1 < 0 and j - 1 < 0:
count += 1
elif i - 1 < 0 and board[... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VA... |
As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answe... | import sys
input = lambda: sys.stdin.readline().strip()
print = lambda s: sys.stdout.write(str(s) + "\n")
a, b = map(int, input().split())
r = [0] * a
c1 = [0] * (a + 1)
c2 = [0] * (a + 1)
f = 0
for i in range(a):
n = int(input())
r[i] = n
if n > 0:
c1[n] += 1
else:
f += 1
c2[-n... | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CAL... |
As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answe... | import sys
n, m = map(int, input().split(" "))
inp = []
guess = [0] * (n + 1)
for i in range(n):
temp = int(input())
inp.append(temp)
if temp < 0:
m -= 1
guess[-temp] -= 1
else:
guess[temp] += 1
dic = {temp for temp in range(1, n + 1) if guess[temp] == m}
if len(dic) == 0:
f... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BI... |
As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answe... | n, m = map(int, input().split())
t = [int(input()) for i in range(n)]
s, p = 0, [0] * (n + 1)
for i in t:
if i < 0:
m -= 1
p[-i] -= 1
else:
p[i] += 1
q = {i for i in range(1, n + 1) if p[i] == m}
if len(q) == 0:
print("Not defined\n" * n)
elif len(q) == 1:
j = q.pop()
print("... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF FUN... |
As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answe... | n, m = list(map(int, input().split()))
a = [[0, 0] for i in range(n)]
b = []
e = 0
f = 0
for i in range(n):
c = input()
d = int(c[1:])
if c[0] == "+":
a[d - 1][0] += 1
e += 1
else:
a[d - 1][1] += 1
f += 1
b.append([c[0], d])
g = [(a[i][0] + f - a[i][1]) for i in range... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER NUMBER NUMBER V... |
As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answe... | from sys import stdin, stdout
n, m = map(int, stdin.readline().split())
cntf = [(0) for i in range(n + 1)]
cnts = [(0) for i in range(n + 1)]
challengers = []
for i in range(n):
s = stdin.readline().strip()
challengers.append(s)
if s[0] == "+":
cntf[int(s[1:])] += 1
else:
cnts[int(s[1:]... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER STRING VAR FUNC_CALL VAR VAR NUMBER NUMBE... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | for _ in range(int(input())):
s = input()
p = input()
c = {}
d = {}
for i in range(97, 124):
c[chr(i)] = 0
d[chr(i)] = 0
l = sorted(list(s))
m = sorted(list(p))
for i in l:
c[i] += 1
for i in m:
d[i] += 1
for i in d:
c[i] -= d[i]
ans1 =... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VA... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | for _ in range(int(input())):
s = input()
p = input()
u = [p[0]]
for e in p[1:]:
if e not in u:
u.append(e)
s = s + p[0]
s = "".join(sorted(s))
for e in p:
s = s.replace(e, "", 1)
pos = 0
if u[0] < u[1]:
pos = s.rfind(p[0])
else:
pos = ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER ASSIGN... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | testcase = int(input())
for _ in range(testcase):
string = input()
pattern = input()
result = ""
cnt = [0] * 26
for c in string:
cnt[ord(c) - ord("a")] += 1
for c in pattern:
cnt[ord(c) - ord("a")] -= 1
flag = 1
for i in range(1, len(pattern)):
if pattern[i] == pa... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR N... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | t = int(input())
for _ in range(t):
a = input()
b = input()
n = len(a)
m = len(b)
i = 0
flag = True
while i + 1 < m and b[i + 1] == b[i]:
i += 1
if i < m - 1 and ord(b[i]) < ord(b[i + 1]):
flag = False
c = []
for i in range(0, 26):
c.append(0)
for i in... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | t = int(input())
for _ in range(t):
s = list(input())
p = list(input())
freq = {}
for c in s:
freq[c] = freq.get(c, 0) + 1
for c in p:
freq[c] -= 1
flag = 0
for i in range(len(p) - 1):
if p[i] == p[i + 1]:
continue
if p[i] > p[i + 1]:
f... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUM... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | try:
for _ in range(int(input())):
n = input()
t = input()
a = [(0) for i in range(26)]
for i in n:
a[ord(i) - 97] += 1
for i in t:
a[ord(i) - 97] -= 1
last = ord(t[0]) - 97
s1 = ""
s2 = ""
for i in range(26):
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | for _ in range(int(input())):
a = list(input())
b = list(input())
for i in b:
a.remove(i)
a.sort()
left = []
right = []
equal = []
k = len(a)
l = 0
for i in range(1, len(b)):
if ord(b[i]) > ord(b[0]):
l = 0
break
if ord(b[i]) < ord(... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR ... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | for _ in range(int(input())):
s = list(str(input()))
p = list(str(input()))
s_26 = [0] * 26
p_26 = [0] * 26
to_add = [0] * 26
for i in s:
s_26[ord(i) - 97] += 1
for i in p:
p_26[ord(i) - 97] += 1
for i in range(26):
to_add[i] = s_26[i] - p_26[i]
ans = []
f... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBE... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | for _ in range(int(input())):
s1 = input()
s2 = input()
l = [0] * 26
for i in s1:
l[ord(i) - ord("a")] += 1
for i in s2:
l[ord(i) - ord("a")] -= 1
k, s, s1 = ord(s2[0]) - ord("a"), "", ""
for i in range(26):
if i == k:
s += chr(ord("a") + i) * l[i]
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR N... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | t = int(input())
while t != 0:
s = input()
p = input()
x = len(s)
y = len(p)
a = [0] * 26
b = [0] * 26
for i in range(x):
pointer = ord(s[i]) - 97
a[pointer] += 1
for i in range(y):
pointer = ord(p[i]) - 97
b[pointer] += 1
for i in range(26):
i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR N... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | for _ in range(int(input())):
s = str(input())
p = str(input())
if len(s) == len(p):
print(p)
else:
res = ""
flag = 1
for i in range(1, len(p)):
if ord(p[i]) == ord(p[i - 1]):
continue
if ord(p[i]) < ord(p[i - 1]):
f... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | t = int(input())
for i in range(t):
s = input()
p = input()
s1 = list(s)
front = []
middle = ""
last = []
for i in p:
if i in s1:
s1.remove(i)
for i in range(len(s1)):
if s1[i] < p[0]:
front.append(s1[i])
elif s1[i] == p[0]:
mid... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | for _ in range(int(input())):
s = input()
p = input()
i = 0
d = {}
for l in s:
if l in d:
d[l] = d[l] + 1
else:
d[l] = 1
for k in p:
d[k] = d[k] - 1
res = ""
res1 = ""
t = p[0]
d = {k: v for k, v in sorted(d.items(), key=lambda item... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR NUMB... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | try:
t = int(input())
for _ in range(t):
s1 = input()
p1 = input()
s = list(s1)
p = list(p1)
for i in range(len(p)):
if p[i] in s:
s.remove(p[i])
first = ""
middle = ""
last = ""
for i in range(len(s)):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUN... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | for _ in range(int(input())):
a = input()
b = input()
a_small = ""
a_big = ""
a_small1 = ""
a_big1 = ""
a = list(a)
b = list(b)
for i in range(len(b)):
a.remove(b[i])
a = "".join(a)
b = "".join(b)
for i in range(len(a)):
if ord(a[i]) <= ord(b[0]):
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL ST... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | for i in range(int(input())):
S = input()
P = input()
s = list(S)
p = list(P)
for i in p:
s.remove(i)
s.sort()
if p[0] not in s:
r = s[:]
r.append(p[0])
r.sort()
n = r.index(p[0])
u = s[:n] + p
s = s[n:]
print(*(u + s), sep="")
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR V... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | tests = int(input())
for i in range(tests):
s = input()
p = input()
arr = [0] * 26
for j in s:
arr[ord(j) - 97] += 1
for j in p:
arr[ord(j) - 97] -= 1
ans = ""
p_added = False
for j in range(26):
add = chr(97 + j) * arr[j]
if add + p > p + add and not p_ad... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | for _ in range(int(input())):
s = input()
p = input()
list1 = []
list1[:0] = s
list2 = []
list2[:0] = p
for i in list2:
list1.remove(i)
list1.sort()
str1 = ""
str2 = ""
s = str1.join(list1)
p = str2.join(list2)
temp = p[0]
empty = ""
third = ""
sec... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | t = int(input())
for j in range(t):
s = input()
p = input()
s1 = list(s)
p1 = list(p)
for i in p1:
if i in s1:
s1.remove(i)
f = ""
l = ""
e = ""
for k in s1:
if k < p[0]:
f += k
elif k == p[0]:
e += k
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR NUMBER VAR VAR IF VAR VA... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | t = int(input())
for _ in range(t):
s = input()
p = input()
g = list(s)
left = []
right = []
mid = []
for i in p:
g.remove(i)
s = "".join(g)
for i in s:
if i > p[0]:
right.append(i)
elif i == p[0]:
mid.append(i)
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR V... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | t = int(input())
for tc in range(t):
s = input()
p = input()
d = {}
for i in range(len(s)):
try:
d[s[i]] += 1
except:
d[s[i]] = 1
for i in range(len(p)):
d[p[i]] -= 1
d = {k: v for k, v in sorted(d.items(), key=lambda item: item[0])}
res = ""
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC... |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore, he is willing to reorder the characters of $S$ in such a way tha... | t = int(input())
for _ in range(t):
string = list(input())
pattern = list(input())
for i in pattern:
string.remove(i)
string.sort()
new_st = "".join(string)
pattern = "".join(pattern)
p = len(pattern)
l = len(new_st)
i = 0
while i < l and new_st[i] < pattern[0]:
i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR A... |
The Postmaster wants to write a program to answer the queries regarding letter collection in a city. A city is represented as a matrix mat of size n*m. Each cell represents a house and contains letters which are denoted by a number in the cell. The program should answer q queries which are of following types:
1 i j : T... | class Solution:
def matrixSum(self, n, m, mat, q, queries):
output = []
for hop, i, j in queries:
output.append(0)
if j - hop >= 0:
for k in range(max(0, i - hop), min(n, i + hop)):
output[-1] += mat[k][j - hop]
if j + hop < m:... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NU... |
The Postmaster wants to write a program to answer the queries regarding letter collection in a city. A city is represented as a matrix mat of size n*m. Each cell represents a house and contains letters which are denoted by a number in the cell. The program should answer q queries which are of following types:
1 i j : T... | class Solution:
def matrixSum(self, n, m, mat, q, queries):
ans = []
for ele in queries:
d, i, j = ele
temp = 0
if d == 1:
if i - 1 >= 0:
temp += mat[i - 1][j]
if j - 1 >= 0:
temp += mat[i][j... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR... |
The Postmaster wants to write a program to answer the queries regarding letter collection in a city. A city is represented as a matrix mat of size n*m. Each cell represents a house and contains letters which are denoted by a number in the cell. The program should answer q queries which are of following types:
1 i j : T... | class Solution:
def matrixSum(self, n, m, mat, q, queries):
t1 = [-1, 0, 1]
t2 = [-2, -1, 0, 1, 2]
res = []
for g in range(q):
z, x, y = queries[g]
ans1 = 0
ans2 = 0
if z == 1:
for i in range(len(t1)):
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUM... |
The Postmaster wants to write a program to answer the queries regarding letter collection in a city. A city is represented as a matrix mat of size n*m. Each cell represents a house and contains letters which are denoted by a number in the cell. The program should answer q queries which are of following types:
1 i j : T... | class Solution:
def matrixSum(self, n, m, mat, q, que):
ans = []
for i in range(q):
x = que[i][1]
y = que[i][2]
s = 0
if que[i][0] == 1:
for j in range(x - 1, x + 2):
for k in range(y - 1, y + 2):
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR... |
The Postmaster wants to write a program to answer the queries regarding letter collection in a city. A city is represented as a matrix mat of size n*m. Each cell represents a house and contains letters which are denoted by a number in the cell. The program should answer q queries which are of following types:
1 i j : T... | class Solution:
def matrixSum(self, n, m, mat, q, queries):
res = []
for i in range(q):
sum1 = 0
dist = queries[i][0]
ind_i = queries[i][1]
ind_j = queries[i][2]
i_mod_top = ind_i - dist
i_mod_bot = ind_i + dist
j_m... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER V... |
The Postmaster wants to write a program to answer the queries regarding letter collection in a city. A city is represented as a matrix mat of size n*m. Each cell represents a house and contains letters which are denoted by a number in the cell. The program should answer q queries which are of following types:
1 i j : T... | class Solution:
def matrixSum(self, n, m, mat, q, queries):
ans = []
for i in range(q):
s = 0
t = queries[i][0]
a = queries[i][1]
b = queries[i][2]
hop1x = [a - 1, a - 1, a - 1, a, a, a + 1, a + 1, a + 1]
hop1y = [b - 1, b, b +... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMB... |
The Postmaster wants to write a program to answer the queries regarding letter collection in a city. A city is represented as a matrix mat of size n*m. Each cell represents a house and contains letters which are denoted by a number in the cell. The program should answer q queries which are of following types:
1 i j : T... | class Solution:
def matrixSum(self, n, m, mat, q, queries):
ans = []
for t, x, y in queries:
temp = 0
if t == 1:
for i in range(-1, 2):
for j in range(-1, 2):
if i == 0 and j == 0:
contin... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR ... |
The Postmaster wants to write a program to answer the queries regarding letter collection in a city. A city is represented as a matrix mat of size n*m. Each cell represents a house and contains letters which are denoted by a number in the cell. The program should answer q queries which are of following types:
1 i j : T... | class Solution:
def matrixSum(self, n, m, mat, q, queries):
s = []
for i in range(q):
p = queries[i][0]
r = queries[i][1]
c = queries[i][2]
ans = 0
if p == 1:
row = r - 1
col = c - 1
if row >... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR... |
You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west,
x[2] metres to the south,
x[3] metres to the east and so on. In other words, after each move your direction changes
counter-clockwise.
Write a one-pass algorithm w... | class Solution:
def isSelfCrossing(self, x):
b = c = d = e = 0
for a in x:
if d >= b > 0 and (a >= c or a >= c - e >= 0 and f >= d - b):
return True
b, c, d, e, f = a, b, c, d, e
return False | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER |
You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west,
x[2] metres to the south,
x[3] metres to the east and so on. In other words, after each move your direction changes
counter-clockwise.
Write a one-pass algorithm w... | class Solution:
def isSelfCrossing(self, x):
l = len(x)
iscross = False
if l < 4:
return False
for i in range(3, l):
if x[i - 3] >= x[i - 1] and x[i - 2] <= x[i]:
return True
if i >= 4 and x[i - 4] + x[i] >= x[i - 2] and x[i - 3] =... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER IF VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN... |
You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west,
x[2] metres to the south,
x[3] metres to the east and so on. In other words, after each move your direction changes
counter-clockwise.
Write a one-pass algorithm w... | class Solution:
def isSelfCrossing(self, x):
n = len(x)
if n < 4:
return False
i = 3
while i < n:
if x[i] >= x[i - 2] and x[i - 3] >= x[i - 1]:
return True
if i >= 4:
if x[i - 1] == x[i - 3] and x[i] + x[i - 4] >= x... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER R... |
You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west,
x[2] metres to the south,
x[3] metres to the east and so on. In other words, after each move your direction changes
counter-clockwise.
Write a one-pass algorithm w... | class Solution:
def isSelfCrossing(self, x):
if not x or len(x) < 4:
return False
i = 3
while i < len(x):
if x[i] >= x[i - 2] and x[i - 1] <= x[i - 3]:
print("case 1")
return True
elif i >= 4 and x[i - 1] == x[i - 3] and x[... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMB... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
temp1 = head1
temp2 = head2
sortedList = Node(-1)
if temp1.data <= temp2.data:
sortedList.data = temp1.data
temp1 = temp1.next
else:
sortedList.data = temp2.data
temp2 = temp2.next
sortedList.next = None
resHead = sortedList
... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR VAR WHILE VAR NONE VAR NONE ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIG... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
dummy = Node
cur = dummy
while True:
if head1.data <= head2.data:
cur.next = head1
head1 = head1.next
else:
cur.next = head2
head2 = head2.next
cur = cur.next
if head1 is None and head2:
... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE VAR ASSIGN VAR VAR IF VAR NONE VAR ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
dummy = Node(None)
curr = dummy
p1, p2 = head1, head2
while p1 and p2:
if p1.data <= p2.data:
curr.next = p1
p1 = p1.next
else:
curr.next = p2
p2 = p2.next
curr = curr.next
if p1:
curr.next... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
head = None
tail = None
curr1 = head1
curr2 = head2
while curr1 != None and curr2 != None:
if curr1.data <= curr2.data:
if head == None:
head = curr1
tail = curr1
curr1 = curr1.next
else:
... | FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE IF VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VA... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(headA, headB):
dummyNode = Node(0)
tail = dummyNode
while True:
if headA is None:
tail.next = headB
break
if headB is None:
tail.next = headA
break
if headA.data <= headB.data:
tail.next = headA
h... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE NUMBER IF VAR NONE ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def findBetween(a1, a2, b):
start_b = b
while b is not None and a1.data <= b.data <= a2.data:
if b.next is None or b.next.data > a2.data:
break
b = b.next
return start_b, b
def sortedMerge(head1, head2):
temp_node = Node(-1)
temp_node.next = head1
a1, a2, b = temp_n... | FUNC_DEF ASSIGN VAR VAR WHILE VAR NONE VAR VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN ... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(left, right):
if not left:
return right
if not right:
return left
ans = Node(-1)
temp = ans
while left and right:
if left.data < right.data:
temp.next = left
temp = left
left = left.next
else:
temp.next =... | FUNC_DEF IF VAR RETURN VAR IF VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
a = []
b = []
h1 = head1
h2 = head2
while h1:
a.append(h1.data)
h1 = h1.next
while h2:
b.append(h2.data)
h2 = h2.next
r = a + b
r.sort()
head = None
for i in range(len(r) - 1, -1, -1):
ne = Node(r[i])
... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
if head1 == None:
return head2
if head2 == None:
return head1
if head1.data > head2.data:
temp = head2.next
head2.next = head1
head1 = head2
head2 = temp
temp = head1
prev = temp
while temp != None and head2 != None:
... | FUNC_DEF IF VAR NONE RETURN VAR IF VAR NONE RETURN VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE ASSIGN VA... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
temp1 = head1
temp2 = head2
a = []
b = []
while temp1:
a += [temp1.data]
temp1 = temp1.next
while temp2:
b += [temp2.data]
temp2 = temp2.next
a.extend(b)
a.sort()
head = Node(a[0])
T = head
for i in range(1, len(a... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR LIST VAR ASSIGN VAR VAR WHILE VAR VAR LIST VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(h1, h2):
ans = Node(-1)
head_ans = ans
while h1 or h2:
if h1 != None and h2 != None:
if h1.data < h2.data:
tmp = Node(h1.data)
ans.next = tmp
ans = ans.next
h1 = h1.next
else:
tmp ... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR NONE VAR NONE IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def solve(temp1, temp2):
while temp2 is not None and temp1.next is not None:
curr = temp1.next
if temp2.data >= temp1.data and temp2.data <= curr.data:
temp1.next = temp2
temp2 = temp2.next
temp1.next.next = curr
temp1 = temp1.next
else:
... | FUNC_DEF WHILE VAR NONE VAR NONE ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR FUNC_DEF IF VAR NONE RETURN VAR IF VAR NONE RETURN VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
a = head1
b = head2
u = []
v = []
while a:
u.append(a.data)
a = a.next
while b:
v.append(b.data)
b = b.next
u = u + v
u = sorted(u)
head = Node(u[0])
t = head
for i in range(1, len(u)):
x = Node(u[i])
... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def findsmaller(curr, t1):
if curr.data < t1.data:
return curr
return t1
def sortedMerge(head1, head2):
t1 = head1
t2 = head2
if t1.data > t2.data:
curr = head2
while t1 != None and curr.next != None:
temp = curr.next
curr.next = findsmaller(curr.nex... | FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE IF VAR VAR ASSIGN VAR VAR RETURN VAR IF VAR... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(start1, start2):
temp1 = temp2 = None
if start1.data < start2.data:
temp1 = start1
temp2 = start2
else:
temp1 = start2
temp2 = start1
start = temp1
prev = None
node = None
while temp1 and temp2:
if temp1.data > temp2.data:
n... | FUNC_DEF ASSIGN VAR VAR NONE IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
x = []
y = []
temp1 = head1
temp2 = head2
while head1 != None:
x.append(head1.data)
head1 = head1.next
while head2 != None:
y.append(head2.data)
head2 = head2.next
z = x + y
z.sort()
for i in z:
print(i, end=" ") | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
a = []
while head1:
a.append(head1.data)
head1 = head1.next
while head2:
a.append(head2.data)
head2 = head2.next
a.sort(reverse=True)
p = None
for i in a:
temp = Node(i)
if p is None:
p = temp
else... | FUNC_DEF ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NONE FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def mergeUtil(h1, h2):
if h1.next == None:
h1.next = h2
return h1
curr1 = h1
next1 = h1.next
curr2 = h2
next2 = h2.next
while next1 != None and curr2 != None:
if curr2.data <= next1.data and curr2.data >= curr1.data:
next2 = curr2.next
curr1.next =... | FUNC_DEF IF VAR NONE ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR RETURN VAR F... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
if head1.data <= head2.data:
final_head = head1
temp = head1
i = temp.next
j = head2
else:
final_head = head2
temp = head2
i = head1
j = temp.next
while i is not None and j is not None:
if i.data <= j.data... | FUNC_DEF IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(h1, h2):
if h1.data > h2.data:
h1, h2 = h2, h1
res = h1
while h1 and h2:
temp = Node(0)
while h1 and h1.data <= h2.data:
temp = h1
h1 = h1.next
temp.next = h2
h1, h2 = h2, h1
return res | FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
curr1, curr2 = head1, head2
if curr2.data < curr1.data:
merged_head = curr2
curr2 = curr2.next
else:
merged_head = curr1
curr1 = curr1.next
merged_tail = merged_head
while curr1 != None and curr2 != None:
node = Node(10000000)
... | FUNC_DEF ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR RET... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
if head1 == None:
return head2
if head2 == None:
return head1
if head1.data < head2.data:
head = tail = head1
head1 = head1.next
else:
head = tail = head2
head2 = head2.next
while head1 and head2:
if head1.data < ... | FUNC_DEF IF VAR NONE RETURN VAR IF VAR NONE RETURN VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | class Node:
def __init__(self, data):
self.data = data
self.next = None
def sortedMerge(head1, head2):
r = Node(0)
head = r
p = head1
q = head2
while p and q:
if p.data < q.data:
r.next = p
p = p.next
else:
r.next = q
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR ASSI... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
if head1 == None:
return head2
if head2 == None:
return head1
temp1 = head1
temp2 = head2
ans = None
while temp1 != None and temp2 != None:
if temp1.data <= temp2.data:
temp = temp1
temp1 = temp1.next
else:
... | FUNC_DEF IF VAR NONE RETURN VAR IF VAR NONE RETURN VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE WHILE VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VA... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
z = Node(-1)
start = z
while head1 and head2:
if head1.data <= head2.data:
start.next = head1
head1 = head1.next
start = start.next
else:
start.next = head2
head2 = head2.next
start = start... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
if head1.data < head2.data:
res = head1
curr = head1
head1 = head1.next
else:
res = head2
curr = head2
head2 = head2.next
while True:
if head1 == None:
curr.next = head2
return res
elif hea... | FUNC_DEF IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER IF VAR NONE ASSIGN VAR VAR RETURN VAR IF VAR NONE ASSIGN VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
if not head1:
return head2
if not head2:
return head1
temp1, temp2 = head1, head2
temp = None
while temp1 and temp2:
if temp1.data <= temp2.data:
if temp:
temp.next = temp1
temp = temp1
temp1 =... | FUNC_DEF IF VAR RETURN VAR IF VAR RETURN VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NONE WHILE VAR VAR IF VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF VAR VAR RETURN VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
if head1 is None:
return head2
if head2 is None:
return head1
dummy = Node(None)
tail = dummy
while head1 and head2:
if head1.data < head2.data:
tail.next = head1
head1 = head1.next
else:
tail.next = h... | FUNC_DEF IF VAR NONE RETURN VAR IF VAR NONE RETURN VAR ASSIGN VAR FUNC_CALL VAR NONE ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR NONE RETURN VAR IF VAR NONE RETURN VAR IF VAR VAR ASSIGN... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
if head1 is None:
return head2
if head2 is None:
return head1
ptr1 = head1
ptr2 = head2
dummy = Node(0)
tail = dummy
while ptr1 is not None and ptr2 is not None:
if ptr1.data <= ptr2.data:
tail.next = ptr1
ptr1 = ... | FUNC_DEF IF VAR NONE RETURN VAR IF VAR NONE RETURN VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE ASS... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def solve(head1, head2):
if head1.next == None:
head1.next = head2
return head1
res = Node(-1)
dummy = res
while head1 and head2:
if head1.data < head2.data:
res.next = head1
head1 = head1.next
else:
res.next = head2
head2 =... | FUNC_DEF IF VAR NONE ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
res = LinkedList()
for i in range(n + m):
if head2 == None or head1 != None and head1.data <= head2.data:
res.append(head1.data)
head1 = head1.next
else:
res.append(head2.data)
head2 = head2.next
return res.head | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NONE VAR NONE VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
if not head1 and not head2:
return head1
if not head1:
return head2
if not head2:
return head1
ans = None
head = None
while head1 and head2:
if head1.data > head2.data:
if head:
head.next = head2
... | FUNC_DEF IF VAR VAR RETURN VAR IF VAR RETURN VAR IF VAR RETURN VAR ASSIGN VAR NONE ASSIGN VAR NONE WHILE VAR VAR IF VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF VAR ASS... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
if not head1:
return head2
if not head2:
return head1
newnew = Node(0)
currr = newnew
cur = head1
cur2 = head2
while cur and cur2:
if cur.data <= cur2.data:
currr.next = cur
cur = cur.next
else:
... | FUNC_DEF IF VAR RETURN VAR IF VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(h1, h2):
if h1 == None:
return h2
if h2 == None:
return h1
if h1.data > h2.data:
h1, h2 = h2, h1
res = h1
while h1 and h2:
temp = None
while h1 and h1.data <= h2.data:
temp = h1
h1 = h1.next
temp.next = h2
... | FUNC_DEF IF VAR NONE RETURN VAR IF VAR NONE RETURN VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR NONE WHILE VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
ans = []
res = []
cur = head1
prev = head2
while cur:
ans.append(cur.data)
cur = cur.next
while prev:
res.append(prev.data)
prev = prev.next
ans.extend(res)
ans.sort()
l = Node(0)
p = l
for i in ans:
k = N... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN V... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
l1 = head1
l2 = head2
if l1.data > l2.data:
l1, l2 = l2, l1
res = l1
while l1 and l2:
temp = Node(-1)
temp = None
while l1 and l1.data <= l2.data:
temp = l1
l1 = l1.next
temp.next = l2
l1, l2 = l2,... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NONE WHILE VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | class Node:
def __init__(self, data):
self.data = data
self.next = None
def sortedMerge(head1, head2):
dummyNode = Node(-1)
auxA = head1
auxB = head2
tail = dummyNode
breakLoop = False
while not breakLoop:
if auxA == None:
tail.next = auxB
b... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NONE ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
if head1 is None:
return head2
if head2 is None:
return head1
p1 = head1
p2 = head2
dummy = Node(0)
tail = dummy
while p1 is not None and p2 is not None:
if p1.data <= p2.data:
tail.next = p1
p1 = p1.next
... | FUNC_DEF IF VAR NONE RETURN VAR IF VAR NONE RETURN VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
if head1 is None and head2 is None:
return None
if head1 is None and head2 is not None:
return head2
if head2 is None and head1 is not None:
return head1
head = Node(0)
curr = head
while head1 and head2:
if head1.data == head2.data o... | FUNC_DEF IF VAR NONE VAR NONE RETURN NONE IF VAR NONE VAR NONE RETURN VAR IF VAR NONE VAR NONE RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE I... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
self.tail = None
def append(self, new_value):
new_node = Node(new_value)
if self.head == None:
self.head = new_node
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CA... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
temp1 = head1
temp2 = head2
head = None
curr = None
while temp1 is not None and temp2 is not None:
if temp1.data < temp2.data:
if head is None:
head = temp1
else:
curr.next = temp1
curr = temp1... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE WHILE VAR NONE VAR NONE IF VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VA... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
a = head1
p, q = [], []
while a is not None:
p.append(a.data)
a = a.next
b = head2
while b is not None:
q.append(b.data)
b = b.next
list1 = sorted(p + q)
c = None
head3 = None
for i in list1:
m = Node(i)
i... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR LIST LIST WHILE VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
newhead = None
temp = newhead
while head1 and head2:
if head1.data > head2.data:
if newhead == None:
newhead = head2
temp = newhead
else:
temp.next = head2
temp = temp.next
... | FUNC_DEF ASSIGN VAR NONE ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
NewList = LinkedList()
node1 = head1
node2 = head2
while node1 != None and node2 != None:
if node1.data <= node2.data:
NewList.append(node1.data)
node1 = node1.next
else:
NewList.append(node2.data)
node2 = nod... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE VAR NONE IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN VAR |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
l = []
while head1 != None:
l.append(head1.data)
head1 = head1.next
while head2 != None:
l.append(head2.data)
head2 = head2.next
l.sort()
head = Node(l[0])
x = head
for i in range(1, len(l)):
y = Node(l[i])
x.next... | FUNC_DEF ASSIGN VAR LIST WHILE VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VA... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def solve(temp, temp1, temp2):
while temp1 is not None and temp2 is not None:
if temp1.data <= temp2.data:
newNode = Node(temp1.data)
temp.next = newNode
temp = temp.next
temp1 = temp1.next
else:
newNode = Node(temp2.data)
temp.... | FUNC_DEF WHILE VAR NONE VAR NONE IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NONE ASSIGN VAR FUNC_CALL VAR... |
Given two sorted linked lists consisting of N and M nodes respectively. The task is to merge both of the list (in-place) and return head of the merged list.
Example 1:
Input:
N = 4, M = 3
valueN[] = {5,10,15,40}
valueM[] = {2,3,20}
Output: 2 3 5 10 15 20 40
Explanation: After merging the two linked
lists, we have me... | def sortedMerge(head1, head2):
tmp = temp = None
while head1 and head2:
if head1.data <= head2.data:
if not tmp:
temp = head1
tmp = head1
else:
tmp.next = head1
tmp = tmp.next
head1 = head1.next
e... | FUNC_DEF ASSIGN VAR VAR NONE WHILE VAR VAR IF VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.