description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
t = int(input()) for i in range(t): password = list(input()) a = 0 b = 0 c = 0 d = 0 if len(password) > 9: for i in range(1, len(password) - 1): if ( password[i] == "@" or password[i] == "#" or password[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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
tests = int(input()) for i in range(tests): string = input() lower_case = False upper_case = False digits = False special_char = False if 97 <= ord(string[0]) <= 122 or 97 <= ord(string[-1]) <= 122: lower_case = True for j in string[1:-1]: num = ord(j) if 97 <= num <=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF N...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
t = int(input()) for i in range(t): n = input() s = "" for j in n: if ord(j) <= 122 and ord(j) >= 97: s = s + "1" break for j in range(1, len(n) - 1): if ord(n[j]) <= 90 and ord(n[j]) >= 65: s = s + "1" break for j in range(1, len(n) - ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUM...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
for _ in range(int(input())): s = input().strip() dig, sml, cap, cha = 0, 0, 0, 0 chs = ["@", "#", "%", "&", "?"] nums = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] if len(s) < 10: print("NO") else: for i in range(len(s)): if s[i].islower(): sml...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
for i in range(int(input())): s = input() one = 0 two = 0 three = 0 four = 0 if len(s) >= 10: for i in range(len(s)): if s[i].islower(): one += 1 if i != 0 and i != len(s) - 1: if s[i].isupper(): two += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VA...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
T = int(input()) while T > 0: S = str(input()) l = u = n = sp = 0 if len(S) >= 10: for i in S: alpha = "abcdefghijklmnopqrstuvwxyz" num = "0123456789" spl = "@#%&?" if i in alpha: l = l + 1 elif i in alpha.upper() and 1 <= S...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CAL...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
lowerCase = "abcdefghijklmnopqrstuvwxyz" upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" digitCase = "0123456789" specialCase = "@#%&?" T = int(input()) for i in range(T): lower = 0 upper = 0 digit = 0 special = 0 password = input() if len(password) < 10: print("NO") else: for i in ...
ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
t = int(input()) for _ in range(t): a = input() if len(a) >= 10: ansa = [a[i] for i in range(len(a)) if a[i].islower()] if len(ansa) >= 1: ansb = [a[i] for i in range(1, len(a) - 1) if a[i].isupper()] if len(ansb) >= 1: if len([a[i] for i in range(1, len(a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF FUNC...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
for _ in range(int(input())): i = input() ans = False alpha = "abcdefghijklmnopqrstuvwxyz" num = "0123456789" spl = "@#%&?" for val in alpha: if val in i: ans = True break temp = False temp2 = False if len(i) < 10: ans = False i = i[1:-1] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF FUNC_C...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
a = ["@", "#", "%", "&", "?"] for i in range(int(input())): s = input() l = [0] l.append(len(s) - 1) b = 0 c = 0 d = 0 e = 0 for i in range(len(s)): if i not in l and s[i].isupper() == True: b += 1 elif s[i].islower() == True: c += 1 elif i...
ASSIGN VAR LIST STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
alphabet = "abcdefghijklmnopqrstuvwxyz" Capitals = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" numbers = "1234567890" special = "@#%&?" for i in range(int(input())): s = input() check1 = check2 = check3 = check4 = check5 = False if len(s) >= 10: check5 = True for i in s: if i in alphabet: c...
ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMB...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
special_symbols = {"@", "#", "%", "&", "?"} def check_security(pwd): flags = [False, False, False, False] l = len(pwd) for i in range(l): if pwd[i].islower(): flags[0] = True if i != 0 and i != l - 1: if pwd[i].isupper(): flags[1] = True ...
ASSIGN VAR STRING STRING STRING STRING STRING FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
for _ in range(int(input())): s = input() lower_check, upper_check, digit_check, spec_check = 0, 0, 0, 0 if len(s) < 10: print("NO") continue if lower_check == 0: if s[0].islower() or s[-1].islower(): lower_check = 1 for j in range(1, len(s) - 1): i = s[j]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER AS...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
for i in range(int(input())): s = input() up, low, digit, spec = 0, 0, 0, 0 t = ["@", "#", "%", "&", "?"] d = [int(x) for x in range(0, 10)] if len(s) < 10: print("NO") else: for i in range(len(s)): if s[i].islower(): low += 1 elif i != 0 a...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_C...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
import sys input = sys.stdin.readline r = "QWERTYUIOPASDFGHJKLZXCVBNM" A = set(list(r)) a = set(list(r.lower())) n = set(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]) c = set(["@", "#", "%", "&", "?"]) for i in range(int(input().strip())): s = list(input().strip()) if len(s) < 10: print("NO") ...
IMPORT ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING FOR VAR FUNC_CALL V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
for _ in range(int(input())): s = input() check = 0 lower_check, upper_check, digit_check, spec_check = 0, 0, 0, 0 if len(s) > 9: if lower_check == 0: if s[0].islower() or s[-1].islower(): lower_check = 1 check += 1 for j in range(1, len(s) - 1...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
for i in range(int(input())): S1 = input() S2 = S1[1:-1] c1 = 0 c2 = 0 c3 = 0 c4 = 0 spl = ["@", "#", "%", "&", "?"] for item in S1: if item.islower(): c4 += 1 for item in S2: if item.isupper(): c1 += 1 if item.isdigit(): c2...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
n = int(input()) for i in range(n): lc = "qwertyuiopasdfghjklzxcvbnm" uc = "QWERTYUIOPASDFGHJKLZXCVBNM" num = "01233456789" sc = "@#%&?" l = [0, 0, 0, 0] st = input() flag = 0 if len(st) >= 10: for x in range(0, len(st)): if min(l) != 0: flag = 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
def Solve(s, n): lower, upper, digit, special = 0, 0, 0, 0 for i in range(n): o = ord(s[i]) if 65 <= o <= 90 and i > 0 and i < n - 1: upper += 1 elif 97 <= o <= 122: lower += 1 elif 48 <= o <= 57 and i > 0 and i < n - 1: digit += 1 elif...
FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF NUMBER VAR NUMBER VAR NUMBER IF NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR LIST STRING STRING STRING ST...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
for i in range(int(input())): S1 = input() S = S1[1:-1] l = ["@", "#", "%", "&", "?"] N = [number for number in range(10)] A = [chr(item) for item in range(65, 91)] a = [chr(items) for items in range(97, 123)] counts = 0 for x in range(len(l)): counts += S.count(l[x]) countA ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASS...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): return input().strip() def invr(): return map(int, input().split()) def outp(n): sys.stdout.write(str(n) + "\n") def outlt(lst): sys.stdout.write(" ".j...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
t = int(input()) while t: s = input() accept1 = False accept2 = False accept3 = False accept4 = False accept5 = False if len(s) >= 10: accept5 = True for i in range(1, len(s) - 1): if s[i].isnumeric(): accept3 = True if s[i].isupper(): acce...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CA...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
t = int(input()) for _ in range(t): s = input() k = len(s) m = "" if len(s) > 9: for i in s: if i.islower() == True: m = m + "a" break for j in range(1, k - 1): if s[j].isupper() == True: m = m + "b" elif...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
N = int(input()) for i in range(N): l = input() condition1 = False condition2 = False condition3 = False condition4 = False condition5 = False if len(l) >= 10: condition5 = True for i in range(len(l)): if l[i].islower(): condition1 = True if i != 0 and...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
t = int(input()) for i in range(t): a = input() b, c, d, e = 0, 0, 0, 0 for i in range(len(a)): if a[i].islower(): b += 1 elif i > 0 and i < len(a) - 1 and a[i].isupper(): c += 1 elif i > 0 and i < len(a) - 1 and a[i].isdigit(): d += 1 elif...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP FUN...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
T = int(input()) while T > 0: str1 = input() l1 = [ "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRI...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
t = int(input()) for i in range(t): s = input() flag = None inside = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#%&?" if len(s) >= 10: if ( "a" in s or "b" in s or "c" in s or "d" in s or "e" in s or "f" in s or "g" i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
for _ in range(int(input())): s = input() if len(s) < 10: print("NO") else: small, caps, digit, spec = 0, 0, 0, 0 sett = ["@", "#", "%", "&", "?"] nums = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] for i in range(len(s)): if s[i] >= "a" and s[i] <= ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
for _ in range(int(input())): st = input() if len(st) < 10: print("NO") continue p = 0 q = 0 r = 0 s = 0 for i in range(1, len(st) - 1): if st[i] >= "a" and st[i] <= "z": p = 1 elif st[i] >= "A" and st[i] <= "Z": q = 1 elif st[i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
for _ in range(int(input())): s = input() cnt = 0 check = 0 sp_char = ["@", "#", "%", "&", "?"] lower_check, upper_check, digit_check, spec_check = 0, 0, 0, 0 if len(s) < 10: print("NO") continue if lower_check == 0: if s[0].islower() or s[-1].islower(): l...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF FUNC_CALL VAR NUMBER FUNC_CALL VAR N...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
c = "qwertyuiopasdfghjklzxcvbnm" dig = "0192837465" def sol(s): if len(s) < 10: return False for ch in s: if ch in c: break else: return False for ch in s[1:-1]: if ch in c.upper(): break else: return False for ch in s[1:-1]: ...
ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR VAR IF VAR VAR RETURN NUMBER FOR VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR RETURN NUMBER FOR VAR VAR NUMBER NUMBER IF VAR VAR RETURN NUMBER FOR VAR VAR NUMBER NUMBER IF VAR STRING STRING STRING STRING STRING RETURN NUMBER RE...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
n = int(input()) for i in range(n): pa = str(input()) s = 0 c = 0 no = 0 sp = 0 o = 0 l = len(pa) if l >= 10: for j in pa: if 97 <= ord(j) <= 122: s = 1 elif 65 <= ord(j) <= 90 and o != 0 and o != l - 1: c = 1 el...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR VAR IF NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF NUMBER FUNC_CAL...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
T = int(input()) for i in range(T): S = input() letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Pass = "0123456789" special = "@#%&?" item, upper, num, special = 0, 0, 0, 0 if len(S) >= 10: for i in S: if i in letter.lower(): item = 1 for i in range(1, len(S) - ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) Password must contain at least one lower case letter $[a-z]$; 2) ...
t = int(input()) def check(s): if len(s) < 10: return False else: l = len(s) sa = 0 la = 0 n = 0 sc = 0 for i in range(l): if s[i] in "abcdefghijklmnopqrstuvwxyz": sa += 1 if s[i] in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" an...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR S...
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): flip = 0 count = 0 ans = 0 j = 0 for i in range(n): if arr[i] == 0: flip = flip + 1 while flip > m: if arr[j] == 0: flip = flip - 1 j = j + 1 if i - j + 1 > ans: ans = i - j + 1 ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ...
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
import sys def findZeroes(arr, n, m): i = 0 j = 0 maxi = -sys.maxsize numzeroes = 0 while j < n: if arr[j] == 0: numzeroes += 1 while numzeroes > m: if arr[i] == 0: numzeroes -= 1 i += 1 maxi = max(maxi, j ...
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(nums, n, k): i = 0 j = 0 maxi = 0 count = 0 while j < len(nums): if nums[j] == 0: count += 1 if count < k: maxi = max(maxi, j - i + 1) j += 1 elif count == k: maxi = max(maxi, j - i + 1) j += 1 ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR WHILE VAR V...
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): left = right = 0 best_win = 0 zero_count = 0 while right < n: if zero_count <= m: if arr[right] == 0: zero_count += 1 right += 1 if zero_count > m: if arr[left] == 0: zero_count -= 1 ...
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): i, j = 0, 0 ans = 0 cnt = 0 while j < len(arr): if arr[j] == 0: cnt += 1 if cnt <= m: ans = max(ans, j - i + 1) j += 1 else: while cnt > m: if arr[i] == 0: cnt -= 1 ...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): nums = arr maxm = 0 i, j = 0, 0 n = len(nums) while j < n: if arr[j] == 1: maxm = max(maxm, j - i + 1) j += 1 elif arr[j] == 0 and m > 0: maxm = max(maxm, j - i + 1) j += 1 m -= 1 else: ...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR...
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): left = 0 zeros = 0 max_cons_ones = 0 for right in range(n): if arr[right] == 0: zeros += 1 while zeros > m: if arr[left] == 0: zeros -= 1 left += 1 max_cons_ones = max(max_cons_ones, right - left + 1) ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): i = j = result = 0 max_ones = 0 while j < n: if arr[j] == 1: max_ones += 1 if j - i + 1 - max_ones > m: if arr[i] == 1: max_ones -= 1 i += 1 else: result = max(result, j - i + 1) j += 1...
FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): j = 0 count = 0 maxCount = 0 for i in range(n): if arr[i] == 1: count = count + 1 elif m > 0: count = count + 1 m = m - 1 else: while arr[j] != 0 and j < n: j = j + 1 j = j + 1 ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP ...
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): left = right = s_idx = 0 maxlen = -1000000000 while right < len(arr): while right < len(arr) and (arr[right] == 1 or m > 0): if arr[right] == 0: m -= 1 right += 1 length = right - left if length > maxlen: ...
FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RE...
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): left = right = zero_count = max_count = 0 while right < n: if arr[right] == 0: zero_count += 1 right += 1 while zero_count > m: if arr[left] == 0: zero_count -= 1 left += 1 max_count = max(max_count, r...
FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): a = 0 j = 0 for i in range(len(arr)): if arr[i] == 0: a += 1 if a > m: if arr[j] == 0: a -= 1 j += 1 return n - j
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): i = 0 j = 0 cnt = 0 maxlen = 0 while j < n: if cnt <= m: if arr[j] == 0: cnt += 1 maxlen = max(maxlen, j - i) j += 1 else: if arr[i] == 0: cnt -= 1 i += 1 if cnt...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
import sys def findZeroes(arr, n, m): M = m cz = 0 ans = 0 i = 0 for j in range(n): if arr[j] == 0: M -= 1 while M < 0: if arr[i] == 0: M += 1 i += 1 cz = j - i + 1 ans = max(ans, cz) return ans
IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): right = 0 left = 0 countZero = 0 while right < n: if arr[right] == 0: countZero += 1 if countZero > m: if arr[left] == 0: countZero -= 1 left += 1 right += 1 return right - left
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): czero = 0 j = -1 ans = 0 for i in range(n): if arr[i] == 0: czero += 1 while czero > m: j += 1 if arr[j] == 0: czero -= 1 tot = i - j ans = max(ans, tot) return ans
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): left_index = 0 right_index = 0 zeros_count = [] res = 0 for i in range(n): if arr[i] == 0: zeros_count.append(i) if len(zeros_count) <= m: res = max(res, right_index - left_index) else: left_index ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR...
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): stack = [i for i in range(n - 1, -1, -1) if arr[i] == 0] t = m maxi = 0 i = 0 j = 0 c = 0 while i < n: if arr[i] == 1: c += 1 i += 1 elif arr[i] == 0 and t > 0: t -= 1 c += 1 i += 1 ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FU...
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): p1 = 0 p2 = 0 maxi = 0 while p2 < n and p1 < n: if m > 0 or arr[p2] == 1: if arr[p2] == 0: m -= 1 maxi = max(maxi, p2 - p1 + 1) p2 += 1 else: if arr[p1] == 0: m += 1 p1 ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): k = m cnt = 0 l = 0 i = 0 mx = -1 while i < n: if arr[i] == 1: l += 1 else: if cnt >= m: break l += 1 cnt += 1 i += 1 mx = max(mx, l) s = 0 while i < n: if arr[i...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR...
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): start = 1 end = 1 zero = 0 maxx = 0 for i in range(n): if arr[i] == 0: zero += 1 end += 1 while zero > m: if arr[start - 1] == 0: zero -= 1 start += 1 l = end - start if l > maxx: ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): i, j, zeroes, ones, res = 0, 0, 0, 0, 0 while j < n: if arr[j] == 0: zeroes += 1 else: ones += 1 while j - i + 1 - ones > m: if arr[i] == 0: zeroes -= 1 else: ones -= 1 ...
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): windowLeft = 0 windowRight = 0 result = 0 zero_count = 0 while windowRight < n: if arr[windowRight] == 0: if zero_count == m: while arr[windowLeft] != 0: windowLeft += 1 windowLeft += 1 els...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER IF VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): window_size = 0 j = 0 for i in range(n): if arr[i] == 0: if m > 0: m -= 1 else: while arr[j] != 0: j += 1 j += 1 window_size = max(i - j + 1, window_size) return window_...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR
Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's. Example 1: Input: N = 3 arr[] = {1, 0, 1} M = 1 Output: 3 Explanation: Maximum subarray is of size 3 which can be made subarray of all 1 after flipping one zero to 1. Example 2: Input: N...
def findZeroes(arr, n, m): if m == 0: maxi = 0 count = 0 for i in range(n): if arr[i] == 1: count += 1 if i == n - 1: maxi = max(maxi, count) return maxi else: maxi = max(maxi, cou...
FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NU...
In order to expand its reach to the outer universe and ensure universal peace, the [MIB] has decided to expand its offices. Namely, it has established its office on N most important planets in the universe, with the base station on the planet S. Each office has an intergalactic teleporter that connects it to other plan...
N, K, S = map(int, input().split()) S -= 1 A = list(map(lambda x: int(x) - 1, input().split())) C = [] for i in range(N): C.append(list(map(int, input().split()))) C_BW_A = [{} for i in range(K)] for i in range(N): a = A[i] for b in range(K): if a != b: cur_c = C_BW_A[a].get(b, float("in...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT VAR FUNC_CALL VAR VA...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
t = int(input()) for _ in range(t): n, m, k = map(int, input().split()) a = list(map(int, input().split())) if n * m - 2 > k: print("YA") continue pos = n * m - 3 isPosib = True while pos < len(a): if a[pos] >= k: isPosib = False break k -=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE V...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
class FenwickTree: def __init__(self, n): self.bit = [0] * n self.size = n def update(self, idx, x): while idx < self.size: self.bit[idx] += x idx |= idx + 1 def __call__(self, start, end): return self.__getitem__(end) - self.__getitem__(start) ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_DEF WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
import sys def read(): return [int(x) for x in sys.stdin.readline().split(" ")] [t] = read() for _ in range(t): [n, m, k] = read() A = read() for i in range(len(A)): A[i] -= 1 l = n * m - 3 done = k * [0] acc = 0 next = k - 1 ok = True for a in A: acc += 1 ...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN LIST VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST NUM...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
def solve(n, m, k, a): d = {} val = n * m - 4 nxt = k p1 = 0 while p1 < k: if a[p1] == nxt: nxt -= 1 while True: try: d[nxt] -= 1 nxt -= 1 val += 1 except: ...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER WHILE NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN STRING VAR NUMBER RETURN STRING FOR V...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
t = int(input()) while t > 0: n, m, k = map(int, input().split()) cards = list(map(int, input().split())) onBoard = {} freeSpots = n * m - 2 cardNo = 0 reqd = k freeSpotmin = 2 if m == 2 and n == 2: freeSpotmin = 1 while freeSpots >= freeSpotmin and cardNo < k: card =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSI...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
t = int(input()) for _ in range(t): n, m, k = [int(x) for x in input().split()] lst = [int(x) for x in input().split()] empty = n * m - 3 if k <= empty: print("YA") else: i = 0 count = 0 mp = {} ans = True while empty < k and count <= empty: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSI...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
t = int(input()) for _ in range(t): n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) wait_set = set([]) wait_len = 0 max_len = n * m - 4 answer = "YA" M = k i = 0 while M > 0: if M not in wait_set: x = a[i] if x != M: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR STRING ASSIGN ...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
def my_function(ms, sz, k): if sz - k >= 3: print("YA") return my_dic = {} for index in range(k): my_dic[ms[index]] = index + 1 cnt = sz for index in range(k, 0, -1): if cnt - my_dic[index] < 3: print("TIDAK") return else: c...
FUNC_DEF IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR NUMBER EXPR FUNC_CALL VAR STRING FUNC_DEF FOR VAR VAR...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
t = int(input()) for i in range(t): n, m, k = [int(v) for v in input().split()] w = [int(v) for v in input().split()][::-1] rho = n * m - 4 zeta = k eta = 0 res = set() while zeta > 0: if w: if eta <= rho: eta += 1 res.add(w.pop()) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER IF VAR IF V...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
def solve() -> None: n, m, k = map(int, input().split()) cards = list(map(int, input().split())) have = [False] * (k + 1) need_card = k occupied = 0 for card in cards: if card == need_card: if occupied == n * m - 3: print("TIDAK") return ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR NUMBER...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
import sys input = sys.stdin.readline def readList(): return list(map(int, input().split())) def readInt(): return int(input()) def readInts(): return map(int, input().split()) def readStr(): return input().strip() def solve(): n, m, k = readInts() arr = readList() isPresent = [Fa...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
for _ in range(int(input())): n, m, k = map(int, input().split()) a = list(map(int, input().split())) f = [0] * (k + 5) def get(i): ans = 0 while i > 0: ans += f[i] i -= -i & i return ans def up(i): while i <= k: f[i] += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
def main(): n, m, k = map(int, input().split()) arr = list(map(int, input().split())) ind = [0] * (k + 1) for i in range(k): ind[arr[i]] = i aux = n * m - 4 card = k curr = 0 while card > 0: index = ind[card] if curr > index: aux += 1 card ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUM...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
t = int(input()) for _ in range(t): n, m, k = map(int, input().split()) a = list(map(int, input().split())) cap = m * n - 4 d = {} need = k i = 0 flag = False while need > 0: if need in d: need -= 1 cap += 1 elif a[i] == need: need -= 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF ...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
for _ in range(int(input())): n, m, k = map(int, input().split()) a = list(map(int, input().split())) freeCells = n * m - (n + m - 1) buffers = n * m - freeCells - 4 for i in range(k): if i - k + a[i] > freeCells + buffers: print("TIDAK") break else: print...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF ...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
t = int(input("")) for j in range(t): l = list(map(int, input("").split())) n = l[0] m = l[1] k = l[2] s = [0] * (k + 1) s[0] = 0 c = 0 l = list(map(int, input("").split())) a = n * m - 4 if a >= k - 1: print("YA") continue for i in l: if i != k: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_C...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
I = lambda: int(input()) Is = lambda: map(int, input().split()) Li = lambda: list(map(int, input().split())) def solve(): n, m, k = Is() a = Li() s = n * m - 2 seen = set() cur = k po = 0 for i in a: seen.add(i) po += 1 if po == s: print("TIDAK") ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUM...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
t = int(input()) for x in range(t): S = list(map(int, input().split())) n, m, k = S[0], S[1], S[2] stack = list(map(int, input().split())) count = 0 d = dict() for i in range(k): d[stack[i]] = i for i in range(k, 0, -1): if d[i] > m * n - 4 + k - i: count = 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
def f(n, m, arr): k = len(arr) on_board = set() max_size = n * m - 2 for i in range(k, 0, -1): if i in on_board: on_board.remove(i) continue while arr[-1] != i and len(on_board) < max_size: top_value = arr.pop() on_board.add(top_value) ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN NUMBER...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
for _ in range(int(input())): n, m, k = map(int, input().split()) arr = list(map(int, input().split())) idx = [i for i in range(k, 0, -1)] ans = "YA" if n * m - 3 < k: mx = 0 for i in range(k): if arr[i] > idx[i]: mx = max(mx, arr[i] - idx[i]) if n...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL V...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
t = int(input()) for _ in range(t): m, n, p = [int(x) for x in input().split()] permut = [int(x) for x in input().split()] s = set() i = 0 flag = 0 for need in range(p, 0, -1): while True: if flag == 1: break if need in s: s.remove(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER WHILE NUMBER IF VAR NUMBER IF VA...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
for _ in range(int(input())): n, m, k = map(int, input().split()) a = list(map(int, input().split())) covered = {x: i for i, x in enumerate(a)} avail = n * m - 4 for i in range(k, 0, -1): o = k - i if covered[i] - o > avail: print("TIDAK") break else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
import sys input = sys.stdin.readline for _ in range(int(input())): n, m, k = map(int, input().strip().split()) l = list(map(int, input().strip().split())) lk = [i for i in range(k, 0, -1)] p = n * m - 3 ans = "" if p >= k: ans = "YA" else: co = 0 for i in range(k): ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VA...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
for _ in range(int(input())): n, m, k = map(int, input().split()) a = [(x - 1) for x in list(map(int, input().split()))] kosong, sekarang = n * m - 2, k - 1 ok, bisa = [0] * k, True for i in range(k): ok[a[i]] = 1 kosong -= 1 if kosong <= 0: print("TIDAK") ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR NUMBER FOR VAR FUNC_...
Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ cards stacked in cell $(1, 1)$. Each card has an integer from $1$ to $k$ writ...
t = int(input()) while t > 0: ip = [int(x) for x in input().split()] n = ip[0] m = ip[1] k = ip[2] a = [int(x) for x in input().split()] freq = [] val = k count = n * m - 4 for i in range(k + 1): freq.append(0) flag = True for i in a: if i == k: k ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): table = {} solve(root, 1, table) for k in sorted(table): print(k, end=" ") print(table[k], end=" $") print() def solve(root, path_len, table): if not root: return if not root.left and not root.right: table[path_len] = 1 + table.get(path_len...
FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF IF VAR RETURN IF VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def asd(root, d, c): if root == None: return else: c += 1 if root.left == None and root.right == None: if c in d.keys(): d[c] += 1 else: d[c] = 1 asd(root.left, d, c) asd(root.right, d, c) def pathCounts(root): ...
FUNC_DEF IF VAR NONE RETURN VAR NUMBER IF VAR NONE VAR NONE IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING ...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): l = [] q = [[root, 1]] c = 0 s = {} while c != len(q): t = q[c][0] g = q[c][1] f = 0 if t.left: f = 1 q.append([t.left, g + 1]) if t.right: f = 1 q.append([t.right, g + 1]) c += 1 ...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP ...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): ans = {} def util(root, level): nonlocal ans if root is None: return if root.left is None and root.right is None: ans[level] = ans.get(level, 0) + 1 return util(root.left, level + 1) util(root.right, level + 1) ...
FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): def count(root, ans, path): if not root: return ans if not root.left and not root.right: ans[path] = ans.get(path, 0) + 1 return ans count(root.left, ans, path + 1) count(root.right, ans, path + 1) return ans d =...
FUNC_DEF FUNC_DEF IF VAR RETURN VAR IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR DICT NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL STRING VAR VAR VAR EXP...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def preOrder(p, ans, k): if p == None: return if p.left == None and p.right == None: ans[k + 1] = ans.get(k + 1, 0) + 1 else: preOrder(p.left, ans, k + 1) preOrder(p.right, ans, k + 1) def pathCounts(root): dict = {} preOrder(root, dict, 0) ans = [] for k, v...
FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE ASSIGN VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VA...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): def root_node(root, count): if root == None: return None count += 1 if root.left == None and root.right == None: if count not in dict1: dict1[count] = 1 else: dict1[count] += 1 if root_node(roo...
FUNC_DEF FUNC_DEF IF VAR NONE RETURN NONE VAR NUMBER IF VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BI...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): final = {} def solve(root, ans): ans.append(root.data) if root.left == None and root.right == None: n = len(ans) if n in final: final[n] += 1 else: final[n] = 1 if root.left: solve(root...
FUNC_DEF ASSIGN VAR DICT FUNC_DEF EXPR FUNC_CALL VAR VAR IF VAR NONE VAR NONE ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_C...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): lengthMap = dict() _pathCounts(root, lengthMap, []) for key in sorted(lengthMap.keys()): s = str(key) + " " + str(lengthMap[key]) + " " + "$" print(s, end="") print() def _pathCounts(root, lengthMap, path): if not root: return path.append(root) ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF IF VAR RETURN EXPR FUNC_CALL VAR VAR IF VAR NONE VAR NONE IF...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): d = dict() D(d, root, 1) for i in d: print(i, d[i], end=" $") print() def D(d, root, k): if root and not root.left and not root.right: if k not in d: d[k] = 1 else: d[k] += 1 if root: D(d, root.left, k + 1) D...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): d = {} def f(root, pl, d): if root == None: return if root.left == None and root.right == None: d[pl] = d.get(pl, 0) + 1 return f(root.left, pl + 1, d) f(root.right, pl + 1, d) f(root, 1, d) for i in sorted(d): ...
FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRI...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): def func(node, arr, ans): if node == None: return if node.left == None and node.right == None: arr.append(node.data) ans.append(arr.copy()) arr.pop() return 0 arr.append(node.data) func(node.left, arr,...
FUNC_DEF FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR LIST VAR ASSIGN VAR DICT FOR V...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def freq(arr, val): return sum([(1) for u in arr if u == val]) def helper(r, D, l): if r.right is None and r.left is None: D = D + [l] return D elif r.right is None and r.left is not None: return helper(r.left, D, l + 1) elif r.right is not None and r.left is None: retu...
FUNC_DEF RETURN FUNC_CALL VAR NUMBER VAR VAR VAR VAR FUNC_DEF IF VAR NONE VAR NONE ASSIGN VAR BIN_OP VAR LIST VAR RETURN VAR IF VAR NONE VAR NONE RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NONE VAR NONE RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN V...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def helper(root, d, l): if root == None: return if root.left == None and root.right == None: if l in d: d[l] = d[l] + 1 else: d[l] = 1 helper(root.left, d, l + 1) helper(root.right, d, l + 1) def pathCounts(root): d = {} helper(root, d, 1) fo...
FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def helper(root, d, count_dict): if root is None: return if root.left is None and root.right is None: count_dict.setdefault(d + 1, 0) count_dict[d + 1] += 1 return helper(root.left, d + 1, count_dict) helper(root.right, d + 1, count_dict) def pathCounts(root): count...
FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUN...