description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish. For the given positive integer N, your tas...
t = int(input()) m = 7 + 10**9 den = pow(25, 1000000005, 1000000007) for i in range(0, t): n = int(input()) t = (n + 1) // 2 s = 52 * ((pow(26, t, 1000000007) - 1) % m) % m s = s * den % m if n % 2 == 0: print(str(s)) else: print(str((s - pow(26, t, 1000000007)) % 1000000007))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR NUM...
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish. For the given positive integer N, your tas...
MOD = 1000000007 def mult(A, B): R = [] for i in range(len(A)): row = [] for j in range(len(B[0])): result = 0 for k in range(len(B)): result += A[i][k] * B[k][j] % MOD result %= MOD row.append(result) R.append(row) ...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_...
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish. For the given positive integer N, your tas...
def main(): modulo = 1000000007 for T in range(int(input())): N = int(input()) t = N // 2 ans = 560000006 * (pow(26, t, modulo) - 1) % modulo if N % 2: ans = (ans + pow(26, t + 1, modulo)) % modulo print(ans) main()
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR...
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish. For the given positive integer N, your tas...
MOD = 1000000007 def power(a, b): if b == 0: return 1 else: temp = power(a, b // 2) if b % 2 == 0: return temp * temp % MOD else: return temp * temp * a % MOD def InverseEuler(t): return power(t, MOD - 2) def aml(n): p = n // 2 temp = 52 ...
ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_O...
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish. For the given positive integer N, your tas...
mod, i = 1000000007, 280000002 for _ in range(int(input())): n = int(input()) t = ( 2 * 26 * (pow(26, n // 2, mod) - 1) * i % mod + (n & 1) * pow(26, (n + 1) // 2, mod) ) % mod print(t)
ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER...
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish. For the given positive integer N, your tas...
inv = 280000002 mod = 1000000007 def solve(): n = int(input()) if n % 2 == 0: print(2 * ((pow(26, n // 2 + 1, mod) - 1) * inv - 1) % mod) else: print( (2 * ((pow(26, n // 2 + 2, mod) - 1) * inv - 1) - pow(26, n // 2 + 1, mod)) % mod ) for i in range(int(in...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP BIN_OP BIN_OP ...
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish. For the given positive integer N, your tas...
mod = 10**9 + 7 def f(n): k = n + 1 >> 1 ans = 26 * (pow(26, k, mod) - 1) * pow(25, mod - 2, mod) * 2 if n % 2: ans -= pow(26, k, mod) ans %= mod return ans for _ in range(int(eval(input()))): n = int(eval(input())) print(f(n))
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL...
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish. For the given positive integer N, your tas...
def get_power(a, N, m, D): if N == 0: return 1 elif N == 1: return a elif N in D: return D[N] else: D[N] = get_power(a, N // 2, m, D) % m * (get_power(a, N - N // 2, m, D) % m) % m return D[N] T = int(input()) ans = [] m = 10**9 + 7 for _ in range(T): N = in...
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN V...
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish. For the given positive integer N, your tas...
import sys m = 1000000007 mi26 = pow(25, m - 2, m) sys.stdin.readline() for line in sys.stdin.read().splitlines(0): n = int(line) ans = 1 if n & 1: k = n // 2 ans = ( 2 * (26 * ((pow(26, k, m) - 1) % m) * mi26) % m % m + pow(26, (n + 1) // 2, m) ) % m els...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP BIN_O...
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish. For the given positive integer N, your tas...
"__author__" == "deepak Singh Mehta(learning to code)) " mod = 1000000007 def pow(n): if n == 0: return 1 if n % 2 == 1: return 26 * pow(n - 1) % mod tmp = pow(n // 2) return tmp * tmp % mod tests = int(input()) for _ in range(tests): n = int(input()) curr = 26 * (pow(n // 2)...
EXPR STRING STRING ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FU...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def heapify(ind): global curr_size par = ind if 2 * ind + 1 < curr_size and heap[2 * ind + 1] < heap[par]: par = 2 * ind + 1 if 2 * ind + 2 < curr_size and heap[2 * ind + 2] < heap[par]: par = 2 * ind + 2 if par != ind: heap[par], heap[ind] = heap[ind], heap[par] heap...
FUNC_DEF ASSIGN VAR VAR IF BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VA...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def heapify(i): global heap, curr_size target = i left = 2 * i + 1 right = 2 * i + 2 if left < curr_size and heap[left] < heap[target]: target = left if right < curr_size and heap[right] < heap[target]: target = right if target != i: heap[i], heap[target] = heap[targe...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER W...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def left(pos): return 2 * pos + 1 def right(pos): return 2 * pos + 2 def parent(pos): return (pos - 1) // 2 def isleaf(pos): if left(pos) > curr_size - 1: return True return False def shiftdown(pos): if not isleaf(pos): smallest = pos if heap[smallest] > heap[left...
FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL V...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def left(pos): return 2 * pos + 1 def right(pos): return 2 * pos + 2 def parent(pos): return (pos - 1) // 2 def swap(pos1, pos2): global heap heap[pos1], heap[pos2] = heap[pos2], heap[pos1] def isLeaf(pos): if left(pos) > curr_size - 1: return True return False def heapify(...
FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def siftUp(i): parent = (i - 1) // 2 while i != 0 and heap[parent] > heap[i]: heap[parent], heap[i] = heap[i], heap[parent] i = parent parent = (i - 1) // 2 def siftDown(i): left = i * 2 + 1 right = i * 2 + 2 while ( left < curr_size and heap[left] < heap[i]...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR V...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def getParent(x): return (x - 1) // 2 def leftChild(x): return 2 * x + 1 if 2 * x + 1 < curr_size else -1 def rightChild(x): return 2 * x + 2 if 2 * x + 2 < curr_size else -1 def heapify(): curr_ind = curr_size - 1 while getParent(curr_ind) != -1 and heap[getParent(curr_ind)] > heap[curr_ind]:...
FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def heapify2(i): global heap p = (i - 1) // 2 while p >= 0 and heap[p] > heap[i]: heap[p], heap[i] = heap[i], heap[p] i, p = p, (p - 1) // 2 def insertKey(x): global curr_size, heap heap[curr_size] = x curr_size += 1 heapify2(curr_size - 1) def deleteKey(i): global cu...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VA...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def left(i): return 2 * i + 1 def right(i): return 2 * i + 2 def parent(i): return (i - 1) // 2 def swap(i, j): global heap heap[i], heap[j] = heap[j], heap[i] def heapifyparent(i): while i > 0 and heap[i] < heap[parent(i)]: swap(i, parent(i)) i = parent(i) def heapify(...
FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF WHILE VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FU...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def swim(i): if i == 0: return parent_ind = (i - 1) // 2 if heap[i] < heap[parent_ind]: heap[i], heap[parent_ind] = heap[parent_ind], heap[i] swim(parent_ind) def sink(i): global curr_size if i > curr_size: return lc_ind, rc_ind = 2 * i + 1, 2 * i + 2 lc_val...
FUNC_DEF IF VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VA...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def minHeapify(i): global curr_size, heap m = i l = 2 * i + 1 r = l + 1 if l < curr_size and heap[l] < heap[m]: m = l if r < curr_size and heap[r] < heap[m]: m = r if i != m: t = heap[i] heap[i] = heap[m] heap[m] = t minHeapify(m) def insertK...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER VAR ...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def insertKey(x): global curr_size heap[curr_size] = x curr_size += 1 i = curr_size - 1 while i != 0 and heap[(i - 1) // 2] > heap[i]: heap[(i - 1) // 2], heap[i] = heap[i], heap[(i - 1) // 2] i = (i - 1) // 2 def minheapify(arr, n, i): smallest = i l = 2 * i + 1 r = 2 ...
FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMB...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def heapify(i): p = (i - 1) // 2 while p >= 0: if heap[p] > heap[i]: heap[p], heap[i] = heap[i], heap[p] i = p p = (p - 1) // 2 def insertKey(x): global curr_size heap[curr_size] = x heapify(curr_size) curr_size = curr_size + 1 def heapify2(i): global ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASS...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def heapify(i): global curr_size, heap smallest = i while True: l, r = 2 * i + 1, 2 * i + 2 if l < curr_size and heap[smallest] > heap[l]: smallest = l if r < curr_size and heap[smallest] > heap[r]: smallest = r if smallest != i: heap[small...
FUNC_DEF ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_O...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def insertKey(x): global curr_size if curr_size >= 101: return curr_size += 1 decreaseKey(curr_size - 1, x) def deleteKey(i): global curr_size if i >= curr_size: return decreaseKey(i, -float("inf")) extractMin() def extractMin(): global curr_size if curr_size ...
FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR VAR RETURN EXPR FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR NU...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def heapify_up(i): if i <= 0: return p_idx = (i - 1) // 2 if heap[p_idx] > heap[i]: heap[p_idx], heap[i] = heap[i], heap[p_idx] heapify_up(p_idx) def heapify_down(i): global curr_size global heap l_idx, r_idx = 2 * i + 1, 2 * i + 2 min_idx, smallest = i, heap[i] ...
FUNC_DEF IF VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VA...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def insertKey(x): global curr_size heap[curr_size] = x curr_size += 1 indx = curr_size - 1 while indx > 0 and heap[(indx - 1) // 2] > heap[indx]: heap[(indx - 1) // 2], heap[indx] = heap[indx], heap[(indx - 1) // 2] indx = (indx - 1) // 2 def deleteKey(i): global curr_size ...
FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN ASSIGN VAR VAR FUNC_CALL V...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def parent(i): return (i - 1) // 2 def leftchild(i): return 2 * i + 1 def rightchild(i): return 2 * i + 2 def insertKey(x): global curr_size heap[curr_size] = x curr_size += 1 i = curr_size - 1 while i > 0 and heap[parent(i)] > heap[i]: p = parent(i) heap[i], heap[p...
FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR V...
A binary heap is a Binary Tree with the following properties: 1) Its a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Ma...
def heapify(heap, i): global curr_size left = 2 * i + 1 right = 2 * i + 2 if left < curr_size and heap[i] > heap[left]: mini = left else: mini = i if right < curr_size and heap[mini] > heap[right]: mini = right if i != mini: heap[mini], heap[i] = heap[i], heap...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NU...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, root): myMap = {} def dfs(node): if not node: return if node not in myMap: clone = Node(node.data) myMap[node] = clone else: return myMap[node] clone....
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR RETURN IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): if tree: a = Node(tree.data) if tree.random: a.random = Node(tree.random.data) a.left = self.cloneTree(tree.left) a.right = self.cloneTree(tree.right) return a class Node: def __ini...
CLASS_DEF FUNC_DEF IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): mapp = {} cloned_root = self.cloneUtil(tree, mapp) return cloned_root def cloneUtil(self, root, mapp): if root in mapp: return mapp[root] if not root: return node = Node(root.data) mapp[r...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR V...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): visit = set() def dfs(root): if root == None: return if root in visit: return visit.add(root) copy = Node(root.data) copy.left = dfs(root.left) copy.ri...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NONE RETURN IF VAR VAR RETURN EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): root = Node(tree.data) qq = [] qq.append(root) qq.append(None) hm = {} q = [] q.append(tree) q.append(None) while q: temp = q.pop(0) curr = qq.pop(0) if temp == Non...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NONE ASSIGN VAR DICT ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NONE WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NONE VAR EXPR FUNC_CALL VAR NONE EXPR FUNC_CALL V...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def traverse_tree(self, tree): self.c += 1 tree.c = self.c if tree.left is not None: self.traverse_tree(tree.left) if tree.right is not None: self.traverse_tree(tree.right) def copy_recursively(self, tree): node = Node(data=tree.d...
CLASS_DEF FUNC_DEF VAR NUMBER ASSIGN VAR VAR IF VAR NONE EXPR FUNC_CALL VAR VAR IF VAR NONE EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR NONE ASSIGN VAR VAR VAR IF VAR NONE EXP...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def clone(self, node, d): if not node: return None clone = Node(node.data) d[node] = clone clone.left = self.clone(node.left, d) clone.right = self.clone(node.right, d) return clone def copyr(self, node, clone, d): if not clon...
CLASS_DEF FUNC_DEF IF VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR RETURN ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR ...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, root): mapp = {} root = self.cloneTreeUtil(root, mapp) return root def cloneTreeUtil(self, root, mapp): if not root: return None if root.data not in mapp: node = Node(root.data) mapp[node.data] = no...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR RETURN NONE IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR NONE IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def simple_clone(self, root): if root is None: return None else: new_root = Node(root.data) if root.random: new_root.random = Node(root.random.data) new_root.left = self.simple_clone(root.left) new_root.righ...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): def recursive(tree): if tree is None: return None cur = Node(tree.data) cur.left = recursive(tree.left) cur.right = recursive(tree.right) cur.random = tree.random return cur ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree, random=False): if tree is None: return None if random: return tree newNode = Node(tree.data) newNode.left = self.cloneTree(tree.left) newNode.right = self.cloneTree(tree.right) newNode.random = self.cl...
CLASS_DEF FUNC_DEF NUMBER IF VAR NONE RETURN NONE IF VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): n = Node(tree.data) tq = [tree] rq = [n] visited = {} while len(tq) > 0: onode = tq.pop(0) nnode = rq.pop(0) if onode in visited: continue visited[onode] = True ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR LIST VAR ASSIGN VAR DICT WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VA...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def io(self, a): if a: self.io(a.left) print(a.data, end=" ") self.io(a.right) def cloneTree(self, tree): visited = {} queue = [tree] g = Node(tree.data) queue1 = [g] while len(queue) > 0: x = queue...
CLASS_DEF FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUM...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneLeftAndRight(self, node, cloneNode, visitedMap): visitedMap[node.data] = cloneNode if node.left: cloneNode.left = Node(node.left.data) self.cloneLeftAndRight(node.left, cloneNode.left, visitedMap) if node.right: cloneNode.right = ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR NONE ASSIGN VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR DICT ASSIGN ...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): if tree is None: return None hashMap = {} newTree = self.cloneTreeUtil(tree, hashMap) self.connectRandomPointer(tree, newTree, hashMap) return newTree def connectRandomPointer(self, tree, newTree, hashMap): ...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NONE RETURN IF VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR NONE RETURN ASSIGN VAR FUNC_CALL VAR VA...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): if tree is None: return None hashMap = {} newTree = self.cloneTreeUtil(tree, hashMap) self.connectRandomTree(tree, newTree, hashMap) return newTree def cloneTreeUtil(self, tree, hashMap): if tree is None: ...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NONE RETURN ...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): if not tree: return temp = Node(tree.data) temp.left = self.cloneTree(tree.left) temp.right = self.cloneTree(tree.right) temp.random = tree.random return temp
CLASS_DEF FUNC_DEF IF VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): root = self.clone(tree) return root def clone(self, root): if root is None: return None else: _node = Node(root.data) if root.random is not None: _node.random = Node(root.random.data)...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def inorder_data(self, root, ans): if root: self.inorder_data(root.left, ans) ans[root] = Node(root.data) self.inorder_data(root.right, ans) def inorder_ans(self, root, ans): if root: self.inorder_ans(root.left, ans) n...
CLASS_DEF FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASS...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): mp = dict() s = [] s.append(tree) while len(s) > 0: c = s.pop() temp = Node(c.data) mp[c.data] = temp if c.right: s.append(c.right) if c.left: s.app...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASS...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): if not tree: return tree nodes = [tree] first = prev = Node(None) while nodes: new_nodes = [] for node in nodes: prev.data = node.data prev.left = node.left ...
CLASS_DEF FUNC_DEF IF VAR RETURN VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR FUNC_CALL VAR NONE WHILE VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NONE RETURN VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
def helper(root, d): if root: clone = Node(root.data) d[root.data] = [root.random, clone] clone.left = helper(root.left, d) clone.right = helper(root.right, d) return clone def traverse(node, d): if node: temp = d[node.data] if temp[0] is not None: ...
FUNC_DEF IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR ASSIGN VAR VAR VAR IF VAR NUMBER NONE ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR NONE EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR CLASS_DEF FUN...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): if not tree: return else: if not tree.left and not tree.right: return tree root = Node(tree.data) root.random = tree.random root.left = self.cloneTree(tree.left) root.r...
CLASS_DEF FUNC_DEF IF VAR RETURN IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): d = {} def helper(node): if node == None: return None clone = Node(node.data) d[node.data] = [node.random, clone] clone.left = helper(node.left) clone.right = helper(node.right) ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR VAR VAR IF VAR NONE ASSIGN VAR VAR NUMBER ASSIGN VAR ...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def preorder(self, root, po): if root is None: return po.append( [ root.data, root.left.data if root.left else -1, root.right.data if root.right else -1, root.random.data if root.random else -1, ...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN EXPR FUNC_CALL VAR LIST VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST V...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): dic = dict() def rec(nod): if nod is None: return None tem = Node(nod.data) dic[nod.data] = tem.data tem.left = rec(nod.left) tem.right = rec(nod.right) return tem ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NONE VAR NONE RETURN ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def c(self, h, he): if h == None: return self.ra[h] = h.random self.cl[h] = he if h.left == None and h.right == None: return if h.left is not None: he.left = Node(h.left.data) self.cl[h.left] = he.left ...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NONE VAR NONE RETURN IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT A...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def clone(self, root): if root is None: return None root_copy = Node(root.data) root_copy.left = self.clone(root.left) root_copy.right = self.clone(root.right) return root_copy def cloneRandom(self, clone_root, root): if root is None:...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def copy(self, root, random, newptr): if not root: return node = Node(root.data) node.left = root.left node.right = root.right random[root.data] = root.random newptr[node.data] = node self.copy(root.left, random, newptr) se...
CLASS_DEF FUNC_DEF IF VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR RETURN IF VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VA...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): a = Node(tree.data) d = {tree.data: a} rd = {} q = [tree] while q: c = q.pop(0) if c.left: q.append(c.left) d[c.data].left = Node(c.left.data) d[c.left.data] = ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VA...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): def _solve(nd): if not nd: return None nodes.append(nd) mp[nd.data] = new = Node(nd.data) new.left = _solve(nd.left) new.right = _solve(nd.right) return new nodes = [...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR RETURN NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NONE ASSIGN VAR VAR VAR VAR RETURN VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def solve(self, root): if root == None: return new = Node(root.data) new.random = root.random new.left = self.solve(root.left) new.right = self.solve(root.right) return new def cloneTree(self, tree): return self.solve(tree)
CLASS_DEF FUNC_DEF IF VAR NONE RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): if not tree: return None return self.dfs(tree, {}) def dfs(self, root, oldToNew): if not root: return None if root in oldToNew: return oldToNew[root] newNode = Node(root.data) oldToNe...
CLASS_DEF FUNC_DEF IF VAR RETURN NONE RETURN FUNC_CALL VAR VAR DICT FUNC_DEF IF VAR RETURN NONE IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def clone_tree_util(self, root, mp): if root is None: return None if root in mp: return mp[root] cloned_node = Node(root.data) mp[root] = cloned_node cloned_node.left = self.clone_tree_util(root.left, mp) cloned_node.right = se...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN NONE IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def helper(self, node1, node2): if node1 is None: return self.d1[node1] = node2 if node1.left: node2.left = Node(node1.left.data) if node1.left.random: node2.left.random = self.d1[node1.left.random] self.helper(...
CLASS_DEF FUNC_DEF IF VAR NONE RETURN ASSIGN VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT EXPR FUNC_CA...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): if not tree: return if tree.left is None and tree.right is None: root = Node(tree.data) root.random = tree.random return root root = Node(tree.data) root.left = self.cloneTree(tree.left) ...
CLASS_DEF FUNC_DEF IF VAR RETURN IF VAR NONE VAR NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def clone(self, tree, dict): if tree != None: node = Node(tree.data) node.left = self.clone(tree.left, dict) node.right = self.clone(tree.right, dict) dict[node] = tree return node def cloneTree(self, tree): dict = {} ...
CLASS_DEF FUNC_DEF IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR RETURN VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def makenode(self, root): if not root: return node = Node(root.data) node.left = root.left node.right = root.right root.left = node self.makenode(node.left) self.makenode(node.right) def connectrandom(self, root): if r...
CLASS_DEF FUNC_DEF IF VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR NONE RETURN ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR NONE RETURN ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF VAR ASSIGN...
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
def fun(tree, d): if tree == None: return None if tree in d: pass else: root = Node(0) root.data = tree.data d[tree] = 1 root.left = fun(tree.left, d) root.right = fun(tree.right, d) root.random = fun(tree.random, d) return root class...
FUNC_DEF IF VAR NONE RETURN NONE IF VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR VAR
Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree. Example 1: Input: Output: 1 Explanation: The tree was cloned successfully. Your Task: No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as in...
class Solution: def cloneTree(self, tree): hashTable = {} if tree == None: return tree newRoot = self.preorder(tree, hashTable) for node in hashTable: if node.random not in hashTable: if node.random == None: hashTable[node]...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT IF VAR NONE RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR VAR IF VAR NONE ASSIGN VAR VAR NONE ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NONE RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Ridbit is given an array $a_{1}, a_{2}, \ldots, a_{N}$. He needs to find the number of ways to divide the array into contiguous subarrays such that: Each element of the sequence $a$ belongs to exactly one of the su...
mod = 10**9 + 7 t = int(input()) for i in range(t): n = int(input()) arr = [int(x) for x in input().split()] l = sorted(arr) prev = -1 for i in range(n): if l[i] - prev > 1: break prev = l[i] m = prev + 1 d = {} for i in range(n): if arr[i] > m: ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Ridbit is given an array $a_{1}, a_{2}, \ldots, a_{N}$. He needs to find the number of ways to divide the array into contiguous subarrays such that: Each element of the sequence $a$ belongs to exactly one of the su...
T = int(input()) P = 10**9 + 7 for _ in range(T): N = int(input()) A = [int(x) for x in input().split()] S = set(A) MEX = 0 while True: if MEX not in S: break MEX += 1 if MEX == 0: print(pow(2, N - 1, P)) continue S1 = set(range(MEX)) end_index...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VA...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Ridbit is given an array $a_{1}, a_{2}, \ldots, a_{N}$. He needs to find the number of ways to divide the array into contiguous subarrays such that: Each element of the sequence $a$ belongs to exactly one of the su...
from sys import stdin input = stdin.readline mod = 10**9 + 7 def add(a, b): return (a % mod + b % mod) % mod def mexofa(): c = [0] * (size + 1) for i in a: c[i] += 1 for i in range(size + 1): if c[i] == 0: return i def answer(): if mex == 0: return pow(2, n...
ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VA...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Ridbit is given an array $a_{1}, a_{2}, \ldots, a_{N}$. He needs to find the number of ways to divide the array into contiguous subarrays such that: Each element of the sequence $a$ belongs to exactly one of the su...
import sys T = int(input()) P = 1000000007 for t in range(T): N = int(input()) A = list(int(x) for x in sys.stdin.readline().split()) m1 = min(A) if m1 > 0: print(pow(2, N - 1, P)) else: nums = [0] * 100001 for a in A: nums[a] += 1 mex = -1 for i ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Ridbit is given an array $a_{1}, a_{2}, \ldots, a_{N}$. He needs to find the number of ways to divide the array into contiguous subarrays such that: Each element of the sequence $a$ belongs to exactly one of the su...
def find_mex(arr): max_value = len(arr) + 1 all_possibles = set(range(max_value)) arr_values = set(arr) omissions = all_possibles - arr_values return min(omissions) def calc_k(arr, mex): DP = [None] * (len(arr) + 1) for i in range(len(arr) + 1): if mex: DP[i] = [0, 0, 0...
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NONE BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR ASSIGN VAR VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Ridbit is given an array $a_{1}, a_{2}, \ldots, a_{N}$. He needs to find the number of ways to divide the array into contiguous subarrays such that: Each element of the sequence $a$ belongs to exactly one of the su...
def main(): mod = 10**9 + 7 for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) xx = [0] * (n + 2) for i in a: xx[i] += 1 if min(a): print(pow(2, n - 1, mod)) continue for i in range(n + 2): ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CAL...
You are given a list of preferences for n friends, where n is always even. For each person i, preferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list. Friends in each list are denoted by integers from 0 t...
class Solution: def unhappyFriends( self, n: int, preferences: List[List[int]], pairs: List[List[int]] ) -> int: res = set() mem = [[(0) for _ in range(n)] for _ in range(n)] for i in range(n): for j in range(n - 1): mem[i][preferences[i][j]] = j + 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VA...
You are given a list of preferences for n friends, where n is always even. For each person i, preferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list. Friends in each list are denoted by integers from 0 t...
class Solution: def unhappyFriends( self, n: int, preferences: List[List[int]], pairs: List[List[int]] ) -> int: idx_table = collections.defaultdict(lambda: collections.defaultdict(int)) for i in range(n): for idx, person in enumerate(preferences[i]): idx_tab...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUN...
You are given a list of preferences for n friends, where n is always even. For each person i, preferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list. Friends in each list are denoted by integers from 0 t...
class Solution: def unhappyFriends( self, n: int, preferences: List[List[int]], pairs: List[List[int]] ) -> int: unhappy = [0] * n for i in range(n // 2): a, b = pairs[i] b_a_idx, a_b_idx = preferences[b].index(a), preferences[a].index(b) for j in ran...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASS...
You are given a list of preferences for n friends, where n is always even. For each person i, preferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list. Friends in each list are denoted by integers from 0 t...
class Solution: def get_pair(self, i): for j in self.pairs: if i in j: for k in j: if k != i: return k def t_happy(self, t, i): pair = self.get_pair(t) for j in self.prefer[t]: if j == pair: ...
CLASS_DEF FUNC_DEF FOR VAR VAR IF VAR VAR FOR VAR VAR IF VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR IF VAR NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR N...
You are given a list of preferences for n friends, where n is always even. For each person i, preferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list. Friends in each list are denoted by integers from 0 t...
class Solution: def unhappyFriends( self, n: int, preferences: List[List[int]], pairs: List[List[int]] ) -> int: pref = {} for i in range(len(preferences)): pref[i] = {} plist = preferences[i] for j in range(len(plist)): pref[i][plist[...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR F...
You are given a list of preferences for n friends, where n is always even. For each person i, preferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list. Friends in each list are denoted by integers from 0 t...
class Solution: def unhappyFriends( self, n: int, preferences: List[List[int]], pairs: List[List[int]] ) -> int: preference_list = [[(0) for _ in range(n)] for _ in range(n)] for x in range(n): for i, y in enumerate(preferences[x]): preference_list[x][y] = n ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BI...
You are given a list of preferences for n friends, where n is always even. For each person i, preferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list. Friends in each list are denoted by integers from 0 t...
class Solution: def unhappyFriends(self, n: int, P: List[List[int]], A: List[List[int]]) -> int: unhappy = set() for i in range(n // 2): for j in range(i + 1, n // 2): Ai0, Ai1, Aj0, Aj1 = A[i][0], A[i][1], A[j][0], A[j][1] if P[Ai0].index(Ai1) > P[Ai0].i...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VA...
You are given a list of preferences for n friends, where n is always even. For each person i, preferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list. Friends in each list are denoted by integers from 0 t...
class Solution: def preferences_to_scores(self, preferences): scores = {} for u, up in enumerate(preferences): for s, v in enumerate(up): scores[u, v] = s return scores def unhappy_friends(self, scores, a, b): ret = set() for ai, aa in enumer...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR VAR VAR VAR ...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def palindrome(self, a, b, st, end): i = 0 j = len(a) - 1 i2 = 0 j2 = len(b) - 1 op = 0 while i < j: if i < st and j > end or j < st or i > end: if a[i] != a[j]: op += 1 elif j > end: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR ...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): makeP = 0 i, j = 0, len(s1) - 1 dic = {} while i <= j: if s1[i] != s1[j]: makeP += 1 dic[i] = s1[i] dic[j] = s1[j] i += 1 j -= 1 def chec...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR I...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s, t): def makePalindrome(s, l, h): i, j = 0, len(s) - 1 cnt = 0 while i < j: if i >= l and i <= h and j <= h and j >= l and s[i] != s[j]: return float("inf") if s[i] != s[j]...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR STRING IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): mud = 0 menor = 1000 a = 0 for i in range(len(s1) - len(s2) + 1): s3 = s1[:i] + s2 + s1[i + len(s2) :] for y in range(i, i + len(s2)): k = len(s3) - 1 - y if s3[y] != s3[k] a...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR ...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
import sys def f(a, b, strt, end): ans = 0 i = 0 j = len(a) - 1 while i <= j: if i >= strt and i <= end: if j >= strt and j <= end: if b[i - strt] != b[j - strt]: return -1 if a[i] != b[i - strt]: ans += 1 ...
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VA...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): s1l = len(s1) s2l = len(s2) ans = float("inf") if s1l < s2l: return -1 for i in range(s1l - s2l + 1): temp = s1[:i] + s2 + s1[i + s2l :] cost = 0 for j in range(i, i + s2l): ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR V...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(sefl, s1, s2): costs = [] for i in range(0, len(s1) - len(s2) + 1): s3 = s1[0:i] + s2 + s1[i + len(s2) :] cost = 0 for j in range(i, i + len(s2)): if s1[j] != s3[j]: cost += 1 p...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER F...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): a = 1 for _ in range(1000): a += 1 s1 = [c for c in s1] s2 = [c for c in s2] ans = float("inf") for i in range(0, len(s1) - len(s2) + 1): s = s1[:] count = 0 for j in...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): n, m = len(s1), len(s2) org = list(s1) slis = org[:] res = 100000000.0 for i in range(n - m + 1): cur = 0 for j in range(m): if slis[i + j] != s2[j]: slis[i + j] ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CA...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): if len(s2) > len(s1): return -1 if s2 in s1: count = 0 for j in range(0, l1 // 2): if s1[j] != s1[l1 - 1 - j]: count += 1 return count else: l...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER B...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def palop1(self, temp, i, m): low = 0 high = len(temp) - 1 pal = 0 while low <= high: if temp[low] != temp[high]: if low >= i and high <= i + m - 1: return 1000000000.0 pal += 1 low += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FO...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): n1, n2 = len(s1), len(s2) ans = float("inf") for i in range(n1 - n2 + 1): costs = 0 for k in range(n2): if s1[i + k] != s2[k]: costs += 1 j1, j2 = 0, n1 - 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR BIN_OP VAR VAR VA...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): def get(k): return (s2[k - i], True) if i <= k < i + N2 else (s1[k], False) Inv, N1, N2 = 10**9, len(s1), len(s2) ans, baseline = Inv, 0 for i in range(N1 // 2): if s1[i] != s1[N1 - 1 - i]: ...
CLASS_DEF FUNC_DEF FUNC_DEF RETURN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BI...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def makePalindrome(self, arr, i, m): start = 0 end = len(arr) - 1 count = 0 while start < end: if arr[start] != arr[end]: if start >= i and end <= i + m - 1: return 1000000000.0 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VA...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def solver(S, L, R): steps = 0 for i in range(len(S) // 2): if i >= L and len(S) - 1 - i <= R and S[i] != S[len(S) - 1 - i]: return -1 if S[i] != S[len(S) - 1 - i]: steps += 1 return steps def specialPalindrome(ign...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN NUMBER IF VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VA...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): if len(s2) > len(s1): return -1 mini = -1 for i in range(len(s1) - len(s2) + 1): st, end = i, i + len(s2) - 1 m, n = 0, len(s1) - 1 tmp = 0 stop = False while n >= m:...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): ret = float("inf") m = len(s1) n = len(s2) for i in range(m - n + 1): s3 = list(s1[:i]) + list(s2) + list(s1[i + n :]) t = [1] * i + [0] * n + [1] * (m - i - n) tmp = 0 for j in rang...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NU...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): s1 = list(s1) s2 = list(s2) n = len(s1) m = len(s2) ans = n + 1 for i in range(n - m + 1): s = s1.copy() for j in range(i, i + m): s[j] = s2[j - i] pos = True ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIG...