description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
t = int(input()) for _ in range(t): n = int(input()) s = input() ans = [i for i in s] hi = n - 1 while hi >= 0 and s[hi] not in "aeiou": hi -= 1 hi -= 1 st, ed, d, idx = 0, hi, 0, hi while idx >= 0: temp = [] while idx >= 0: if s[idx] in "aeiou": ...
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 ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR WHILE VAR NUMBER ASSIGN VAR LIST WHILE V...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
def reverse_per_vowel(s): vowels = {"a", "e", "i", "o", "u"} endings = [[], []] side = 1 for c in reversed(s): if c in vowels: endings[side].append(c) side = 1 - side else: endings[side].append(c) return "".join(endings[0] + endings[1][::-1]) t =...
FUNC_DEF ASSIGN VAR STRING STRING STRING STRING STRING ASSIGN VAR LIST LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL STRING BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FO...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
def vowel(s): if s == "a" or s == "e" or s == "i" or s == "o" or s == "u": return True else: return False for p in range(int(input())): n = int(input()) a = str(input()) a = a[::-1] s, q = "", "" x = 0 for i in range(n): if not vowel(a[i]) and x % 2 == 0: ...
FUNC_DEF IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING RETURN NUMBER RETURN 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 ASSIGN VAR VAR NUMBER ASSIGN VAR VAR STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for _ in range(int(input())): n = int(input()) if 23243 == 32432432342: print("Tanmay") s = input() c = 0 for i in s: if i in ["a", "e", "i", "o", "u"]: c += 1 if s[0] not in ["a", "e", "i", "o", "u"]: c += 1 m = n l = "" for i in range(n - 1, -1, ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR LIST STRING STRING STRING STRING STRING VAR NUMBER IF VAR NUMBER LIST STRING STRING STRING STRING STRING VAR NUMBER ASSIGN VAR...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for _ in range(int(input())): n = int(input()) s = input() s = s[::-1] dic = {} vowels = ["a", "e", "i", "o", "u"] count = 0 l = 0 panku = [] for i in range(n): if s[i] in vowels: panku.append((s[l : i + 1], count)) l = i + 1 count += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR V...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
def find(a): if a == "a" or a == "e" or a == "i" or a == "o" or a == "u": return True return False for _ in range(int(input())): n = int(input()) s = input() p1, p2 = [], [] sub = 1 for i in range(n - 1, -1, -1): if sub == 1: p1.append(s[i]) if find(...
FUNC_DEF IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING RETURN NUMBER RETURN 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 ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
t = int(input()) while t: n = int(input()) s = input() first = 0 l1 = [] last = 0 for i in range(0, len(s)): if s[i] in "aeiou": last = i res = s[first:i] first = i if res != "": l1.append(res) l1.reverse() pre = "" ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
def solve(n, s): first = -1 vowels = {"a", "e", "i", "o", "u"} for i in range(n - 2, -1, -1): if s[i + 1] in vowels: first = i break if first == -1: return s res = [""] * (first + 1) flag = False l = 0 r = first for i in range(first, -1, -1): ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
t = int(input()) for _ in range(t): n = int(input()) s = input() vowels = [] segments = [] prev = 0 last = 1 for i in range(n): if s[i] in {"a", "e", "i", "o", "u"}: segments.append(s[prev:i]) prev = i segments.append(s[prev : len(s)]) for i in range(l...
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 ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR EXPR ...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for i in range(int(input())): n = int(input()) s = input() b = [(0) for i in range(n)] right = n - 1 left = 0 vowelc = 0 vowels = ["a", "e", "i", "o", "u"] for i in reversed(range(n)): if vowelc % 2 == 0: b[right] = s[i] right -= 1 else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP ...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for _ in range(int(input())): n = int(input()) s = input() l = list(s) c = [(0) for i in range(len(l))] pre = 0 for i in reversed(range(0, len(l))): c[i] = pre if l[i] in ["a", "e", "i", "o", "u"]: pre += 1 s1 = "" s2 = "" for i in range(len(l)): i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR LIST STRING ST...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for _ in range(int(input())): n = int(input()) s = input() vowels = ["a", "e", "i", "o", "u"] t, v = [""] * n, 0 l, r = 0, n - 1 for i in range(n - 1, -1, -1): if v % 2 == 0: t[r] = s[i] r -= 1 else: t[l] = s[i] l += 1 if s[...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR VAR BIN_OP LIST STRING VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NU...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
def rev(string): string = "".join(reversed(string)) return string for _ in range(int(input())): n = int(input()) s = str(input()) vow = ["a", "e", "i", "o", "u"] bits_ = [] curr_bit = "" for i in range(1, n + 1): curr_bit += s[-i] if i == n: bits_.append(cur...
FUNC_DEF ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR RETURN VAR 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 ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR N...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
from sys import stdin input = stdin.readline for _ in range(int(input())): n = int(input()) s = input().strip() k = 1 p = "" q = "" for i in range(n - 1, -1, -1): if s[i] == "a" or s[i] == "e" or s[i] == "i" or s[i] == "o" or s[i] == "u": if k == 1: q += s[i]...
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR ST...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
t = int(input()) for _ in range(t): n = int(input()) s = input() v = "aeiou" l = [] cur = "" for i in range(n): if s[i] in v: if cur != "": l.append(cur) cur = s[i] else: cur += s[i] l.append(cur) if len(l) % 2 == 1: ...
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 ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for _ in range(int(input())): n = int(input()) s = input() strt = 0 i = 2 st = [] while i < len(s): if s[i] in {"a", "e", "i", "o", "u"}: st.append(s[strt:i]) strt = i i += 1 rt, lt = [], [] for i, x in enumerate(st): if i % 2 == 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR LIST LIS...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
t = int(input()) while t: t -= 1 n = int(input()) s = input() l = 0 r = n - 1 lisst = [0] * n rev = False for i in range(n - 1, -1, -1): if rev: lisst[l] = s[i] l += 1 else: lisst[r] = s[i] r -= 1 if s[i] == "a" or s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR ASSIGN VAR VAR VAR VAR VAR NUMBER AS...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for _ in range(int(input())): n = int(input()) s = input() new = [] l = [] v = {"a", "e", "i", "o", "u"} for i in range(len(s)): if s[i] in v: if len(new) != 0: new = "".join(new) l.append(new) new = [s[i]] else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CAL...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for i in range(int(input())): n = int(input()) s = input() strt = False res = [0] * n l = 0 r = n - 1 for i in range(n - 1, -1, -1): if strt: res[l] = s[i] l += 1 else: res[r] = s[i] r -= 1 if s[i] == "a" or s[i] == "e" ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR V...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
import sys input = sys.stdin.readline M = int(1000000000.0) + 7 def solve(): n = int(input()) s = input().strip("\n") flip = 0 l, r = "", "" for i in range(n - 1, -1, -1): if flip % 2 == 0: r += s[i] else: l += s[i] if s[i] in "aeiou": f...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR IF VAR VA...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
import sys t = int(input()) for _ in range(t): n = int(input()) s = input() v = ["a", "e", "i", "o", "u"] p = [] q = [] x = True y = False for i in range(len(s) - 1, -1, -1): if s[i] not in v: if x == True: p.append(s[i]) else: ...
IMPORT 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 ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMB...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
t = int(input()) for i in range(t): n = int(input()) s = input() ind = [0] * n for j in range(n): if s[j] in "aeiou": ind[j] -= 1 ind[0] += 1 for j in range(1, n): ind[j] += ind[j - 1] o = [""] * n e = n - 1 st = 0 for j in range(n - 1, -1, -1)...
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 ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
def solve(): n = int(input()) s = input() vow = ["a", "e", "i", "o", "u"] vow_cnt = 0 res = "" data = [-1] * n for i in range(n - 1, -1, -1): if vow_cnt & 1: res += s[i] if s[i] in vow: data[i] = vow_cnt vow_cnt += 1 else: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR N...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
t = int(input()) while t > 0: t -= 1 n = int(input()) s = input() sl = [(0) for i in range(n)] for i in range(n - 1, -1, -1): sl[i] = s[i] if s[i] in {"a", "e", "i", "o", "u"}: break k = i df = k - 1 dr = -1 for i in range(k - 1, -1, -1): if s[i] i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR STRING STRING STRING STRING STRING ASSIGN VAR VAR ASSIGN VAR ...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for _ in range(int(input())): _, s = input(), input() curr = "" l = [] for i in s: if i in "aeiou": l.append(curr) curr = i else: curr += i l.append(curr) l = l[::-1] fine = "" fino = "" for i, j in enumerate(l): if i % 2 ==...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP ...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
def main(): for _ in range(int(input())): N = int(input()) s = input() res = [] p = 0 for i in range(1, N): if s[i] in ["a", "e", "i", "o", "u"]: res.append(s[p:i]) p = i l = s[p:] e = "" o = "" r = "...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR LIST STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STR...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
def check(s): lst = ["a", "e", "i", "o", "u"] if s in lst: return True return False case = int(input()) mod = 1000000000.0 + 7 for z in range(case): n = int(input()) s = list(input()) ans = ["-1"] * n for i in range(n): ans[i] = s[i] j = n - 1 while j >= 0 and not c...
FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for t in range(int(input())): n = int(input()) s = input() v = ["a", "e", "i", "o", "u"] t1 = "" t2 = "" c = 0 s = s[::-1] for i in s: if c % 2: t1 += i else: t2 += i if i in v: c += 1 print(t1 + t2[::-1])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUN...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
t = int(input()) for _ in range(t): n = int(input()) s = input() ans, temp = "", "" vowel = ["a", "e", "i", "o", "u"] for i in range(n - 1, -1, -1): temp = s[i] + temp if s[i] in vowel: break i -= 1 flag = True while i >= 0: if flag: ans = ...
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 ASSIGN VAR VAR STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR NUMBER A...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
T = int(input()) for i in range(T): N = int(input()) S = input() n = len(S) vpos = [i for i in range(n) if S[i] in "aeiou"] v = [S[i] for i in range(n) if S[i] in "aeiou"] last = -1 cval = [] for i in vpos: cval.append(S[last + 1 : i]) last = i end = [S[last + 1 :]] ...
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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUN...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for i in range(int(input())): n = int(input()) a = input() l = list(a) ans = ["" for _ in range(n)] d = {"a": 1, "e": 1, "i": 1, "o": 1, "u": 1} now = n - 1 y = n - 1 x = 0 left = True for i in reversed(range(n)): if l[i] not in d: ans[now] = l[i] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR ...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
class Node: def __init__(self, data): self.data = data self.next = None self.prev = None class DoublyLL: def __init__(self): self.head = None self.tail = None def ppend(self, data): new_node = Node(data) if self.head is None and self.tail is None:...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR RETURN ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE VAR NONE ASS...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for _ in range(int(input())): N = int(input()) S = input() A = [0] * len(S) direction = -1 front = 0 back = len(S) - 1 S_ = list(S) S_.reverse() for val in S_: if direction == -1: A[back] = val back -= 1 else: A[front] = val ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER ASSIG...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
def is_vowel(ch): return ch in "aeiou" for _ in range(int(input())): n = int(input()) s = input() rev = [] for i in range(n - 1, -1, -1): if is_vowel(s[i]): rev.append(i) if len(rev) == 0: print(s) continue if rev[-1] != 0: rev.append(0) end ...
FUNC_DEF RETURN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUM...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for _ in range(int(input())): n = int(input()) s = [*input()] q = [] prev = 0 vowel = {*"aeiou"} for i in range(n): if s[i] in vowel: q.append((prev, i)) prev = i if q: last = q[-1][1] ans = [] for i in range(len(q) - 1, -1, -2): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_C...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for h in range(int(input())): temp = [] k = "" f = 0 a, b = "", "" n = int(input()) s = input() for i in s: if i in ["a", "e", "i", "o", "u"]: temp.append(k) k = "" k += i temp.append(k) for i in range(len(temp)): if i % 2 == 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR LIST STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR VAR EXPR FUNC_CALL VA...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
t = int(input()) for _ in range(t): n = int(input()) s = input() s1 = "" s2 = "" ans1 = "" count = 0 for i in range(n): if s[i] == "a" or s[i] == "e" or s[i] == "i" or s[i] == "o" or s[i] == "u": count += 1 if count % 2 == 1: ans1 = s1 + ans1 ...
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 ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR NUMBER IF B...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
t = int(input()) for i in range(t): n = int(input()) s = input() arr = [0] for i in range(1, n): if s[i] in ["a", "e", "i", "o", "u"]: arr.append(i) l = len(arr) count = 1 temp = [] ans = "" for i in range(l - 1, 0, -1): if count % 2 == 0: temp...
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 ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR LIST STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIS...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
vo = "aeiou" for _ in range(int(input())): n = int(input()) s = input() res = ["0"] * n l, r = 0, n - 1 flag = False for i in range(n - 1, -1, -1): if flag: res[l] = s[i] l += 1 else: res[r] = s[i] r -= 1 if s[i] in vo: ...
ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR ASSIGN VAR VAR VAR VAR VAR NUMBER A...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for _ in range(int(input())): n = int(input()) string = input() vowels = ["a", "e", "i", "o", "u"] ans = ["0"] * n op = False right = 0 left = n - 1 for i in reversed(range(n)): if op: ans[right] = string[i] right += 1 else: ans[left] =...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR ASSIGN VA...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
t = int(input()) for _ in range(t): n = int(input()) s = input() s1 = "" s2 = "" vowel = "aeiou" v_idx = n flag = 0 for i in range(n - 1, -1, -1): if s[i] in vowel: if flag == 0: s2 = s[i:v_idx] + s2 v_idx = i flag = 1 ...
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 ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for _ in range(int(input())): n = int(input()) s = input() l = [0] * n p = [0] * n c = 0 for i in s: if i in "aeiou": c += 1 for i in range(n): if s[i] in "aeiou": c -= 1 l[i] = c % 2 news = "" for i in range(n - 1, -1, -1): if ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NU...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
vowels = ["a", "e", "i", "o", "u"] for _ in range(int(input())): N = int(input()) s = "0" + input() A = [] L = 1 for i in range(1, N + 1): if s[i] in vowels: A.append((L, i - 1)) L = i for i in range(len(A) - 1, -1, -2): x, y = A[i] print(s[y : x -...
ASSIGN VAR LIST STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSI...
Utkarsh has recently started taking English-language classes to improve his reading and writing skills. However, he is still struggling to learn English. His teacher gave him the following problem to improve his vowel-identification skills: There is a string S of length N consisting of lowercase English letters only. ...
for _ in range(int(input())): n = int(input()) s = input() flip = 0 l, r = "", "" for i in range(n - 1, -1, -1): if flip % 2 == 0: r += s[i] else: l += s[i] if s[i] in "aeiou": flip += 1 print(l + r[::-1])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_O...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): dic = {} sums = 0 longsub = 0 for i in range(n): sums += arr[i] r = sums - k if r == 0: longsub = i + 1 if r in dic: longsub = max(longsub, i - dic[r...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): m = {(0): -1} leng = 0 summ = 0 for i in range(n): summ += arr[i] if summ not in m: m[summ] = i if summ - k in m: leng = max(leng, i - m[summ - k]) retur...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): hashMap = {} res = 0 sum = 0 for i in range(n): sum += arr[i] if sum == k: res = i + 1 remain = sum - k if remain in hashMap: res = max(res, i - hash...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR A...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): mx = 0 s = 0 i = 0 di = dict() for j in range(n): s += arr[j] if s not in di: di[s] = j if s == k: mx = max(mx, j + 1) elif s - k in di: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, a, n, k): n = len(a) preSumMap = {} Sum = 0 maxLen = 0 for i in range(n): Sum += a[i] if Sum == k: maxLen = max(maxLen, i + 1) rem = Sum - k if rem in preSumMap: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VA...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): cursum = 0 reslen = 0 dic = {} for i in range(n): cursum += arr[i] if cursum == k: reslen = max(reslen, i + 1) diff = cursum - k if diff in dic: resl...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): sum_ = 0 length = 0 dict_ = {(0): -1} for i, number in enumerate(arr): sum_ += number index = dict_.get(sum_ - k, -2) if index != -2: length = max(length, i - index) ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): sum_indices = {(0): -1} s = 0 max_len = 0 for i in range(n): s += arr[i] if s - k in sum_indices: max_len = max(max_len, i - sum_indices[s - k]) if s not in sum_indices: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): ans = 0 cur = 0 dic = {(0): 0} for i in range(n): cur += arr[i] if cur - k == 0: ans = i + 1 elif cur - k in dic: ans = max(ans, i + 1 - dic[cur - k]) ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER RETU...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): mp = {} pfs = [0] for i in range(n): pfs.append(pfs[-1] + arr[i]) ans = 0 for i in range(n + 1): if pfs[i] - k in mp: ans = max(ans, i - mp[pfs[i] - k]) if pfs[i] not in...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, a, n, k): count = 0 s = 0 d = {} for i in range(n): s += a[i] if s == k: count = i + 1 if s - k in d: l = i - d[s - k] count = max(l, count) if s...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): for i in range(1, n): arr[i] += arr[i - 1] dict_ = {} ans = 0 for i in range(n): if arr[i] not in dict_: dict_[arr[i]] = [i] if arr[i] - k in dict_: ans = max(an...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NU...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): objmap = {} maxlen = 0 l = n sum = 0 for i in range(l): sum = sum + arr[i] if sum not in objmap: objmap[sum] = i if sum == k: maxlen = i + 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): max = 0 sum_arr = [0] * n sum_arr[0] = arr[0] index_dict = {} index_dict[sum_arr[0]] = 0 for i in range(1, n): sum_arr[i] = sum_arr[i - 1] + arr[i] if index_dict.get(sum_arr[i], True) == Tr...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR AS...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): presum = {} s = 0 presum[s] = -1 for i in range(len(arr)): s += arr[i] if s not in presum: presum[s] = i maxlen = 0 s = 0 for i in range(len(arr)): s += ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR B...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): c, lon = 0, 0 dic = {} for i in range(n): c += arr[i] if c == k: lon = max(i + 1, lon) if c - k in dic: lon = max(i + 1 - dic[c - k], lon) if c not in dic: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): if n == 1: return 1 if k == arr[0] else 0 sm = 0 ans = 0 mp = dict() for i in range(n): sm += arr[i] if sm == k: ans = i + 1 if sm - k in mp: ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR IF...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): l = 0 sumd = {} sum1 = 0 for i in range(n): sum1 += arr[i] if sum1 not in sumd: sumd[sum1] = i if sum1 == k and l < i + 1: l = i + 1 if sum1 - k in s...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, target): prefix_sum = 0 prefix_map = {} res = 0 for index, element in enumerate(arr): prefix_sum += element if prefix_sum == target: res = max(res, index + 1) if prefix_sum not in p...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): a = 0 s = 0 d = {(0): -1} for i in range(n): s = s + arr[i] if s - k in d: if i - d[s - k] > a: a = i - d[s - k] if s not in d: d[s] = i ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): hashmap = {} hashmap[0] = -1 ps = 0 longest = 0 for i in range(len(arr)): ps += arr[i] if ps - k in hashmap: length = i - hashmap[ps - k] longest = max(longest, leng...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): sum = 0 res = 0 dict1 = {} for i in range(n): sum = sum + arr[i] if sum == k: res = i + 1 if sum not in dict1: dict1[sum] = i if sum - k in dict1: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): a = arr.copy() sum = 0 d = {} maxi_len = 0 for i in range(0, len(a)): sum = sum + a[i] if sum == k: maxi_len = max(maxi_len, i + 1) if sum - k in d: maxi...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR V...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): prefix_sum = [0] * n prefix_sum[0] = arr[0] for i in range(1, n): prefix_sum[i] = prefix_sum[i - 1] + arr[i] hash_map = {} max_length = 0 for i in range(n): if prefix_sum[i] == k: ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VA...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): max_len = 0 prefix_sum = {} sum = 0 for i in range(n): sum += arr[i] if sum == k: max_len = max(max_len, i + 1) else: j = prefix_sum.get(sum - k, i) ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): cumul_sum = 0 sum_map = {} answer = 0 for index, num in enumerate(arr): cumul_sum += num if cumul_sum == k: answer = max(answer, index + 1) if cumul_sum - k in sum_map: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR...
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): map = {} ll = 0 sum = 0 for i in range(n): sum += arr[i] if sum == k: l = i + 1 if l > ll: ll = l else: more = sum - k ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): mydict = dict() sum = 0 lenn = 0 for i in range(n): sum += arr[i] if sum == k: lenn = i + 1 elif sum - k in mydict: lenn = max(lenn, i - mydict[sum - k]) ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): pref = dict() ans, res = 0, 0 pref[0] = -1 for i in range(n): res += arr[i] if res - k in pref.keys(): ans = max(ans, i - pref[res - k]) if res not in pref.keys(): ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR VAR RETURN VAR
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K. Example 1: Input : A[] = {10, 5, 2, 7, 1, 9} K = 15 Output : 4 Explanation: The sub-array is {5, 2, 7, 1}. Example 2: Input : A[] = {-1, 2, 3} K...
class Solution: def lenOfLongSubarr(self, arr, n, k): dic = {(0): [-1]} count = 0 for i in range(n): count += arr[i] if count in dic: dic[count].append(i) else: dic[count] = [i] ans = 0 for num in dic: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETUR...
Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K. Example 1: Input: N = 9, K = 3 arr[] = 1 2 3 1 4 5 2 3 6 Output: 3 3 4 5 5 5 6 Explanation: 1st contiguous subarray = {1 2 3} Max = 3 2nd contiguous subarray = {2 3 1} Max = 3 3rd contiguous subarray =...
class Solution: def max_of_subarrays(self, arr, n, K): q = deque() result = [] for i in range(K): while q and arr[i] >= arr[q[-1]]: q.pop() q.append(i) for i in range(K, len(arr)): result.append(arr[q[0]]) while q and q...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR WHILE VAR VAR VAR VAR VAR ...
Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K. Example 1: Input: N = 9, K = 3 arr[] = 1 2 3 1 4 5 2 3 6 Output: 3 3 4 5 5 5 6 Explanation: 1st contiguous subarray = {1 2 3} Max = 3 2nd contiguous subarray = {2 3 1} Max = 3 3rd contiguous subarray =...
class Solution: def max_of_subarrays(self, arr, n, k): result = [] max_element = max(arr[:k]) result.append(max_element) for i in range(k, n): if arr[i - k] == max_element: max_element = max(arr[i - k + 1 : i + 1]) elif arr[i] > max_element: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR
Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K. Example 1: Input: N = 9, K = 3 arr[] = 1 2 3 1 4 5 2 3 6 Output: 3 3 4 5 5 5 6 Explanation: 1st contiguous subarray = {1 2 3} Max = 3 2nd contiguous subarray = {2 3 1} Max = 3 3rd contiguous subarray =...
class Solution: def max_of_subarrays(self, arr, n, k): res = [] d = deque() for i in range(k): while len(d) and arr[i] >= arr[d[-1]]: d.pop() d.append(i) for i in range(k, n): res.append(arr[d[0]]) while len(d) and d[0]...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR WHILE FUNC_C...
Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K. Example 1: Input: N = 9, K = 3 arr[] = 1 2 3 1 4 5 2 3 6 Output: 3 3 4 5 5 5 6 Explanation: 1st contiguous subarray = {1 2 3} Max = 3 2nd contiguous subarray = {2 3 1} Max = 3 3rd contiguous subarray =...
class Solution: def max_of_subarrays(self, a, n, k): s = [] o = [] for i in range(k): while len(s) != 0 and a[s[-1]] < a[i]: s.pop() s.append(i) o.append(a[s[0]]) for i in range(k, n): if i - k >= s[0]: s.po...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE FUNC_CALL VAR VAR NUMB...
Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K. Example 1: Input: N = 9, K = 3 arr[] = 1 2 3 1 4 5 2 3 6 Output: 3 3 4 5 5 5 6 Explanation: 1st contiguous subarray = {1 2 3} Max = 3 2nd contiguous subarray = {2 3 1} Max = 3 3rd contiguous subarray =...
class Solution: def max_of_subarrays(self, arr, n, k): dq = deque() res = [] for i in range(n): if dq and dq[0] == i - k: dq.popleft() while dq and arr[dq[-1]] < arr[i]: dq.pop() dq.append(i) if i >= k - 1: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR
Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K. Example 1: Input: N = 9, K = 3 arr[] = 1 2 3 1 4 5 2 3 6 Output: 3 3 4 5 5 5 6 Explanation: 1st contiguous subarray = {1 2 3} Max = 3 2nd contiguous subarray = {2 3 1} Max = 3 3rd contiguous subarray =...
class Solution: def max_of_subarrays(self, arr, n, k): queue = [] maxi = 0 for i in range(k): queue.append(arr[i]) maxi = max(maxi, arr[i]) res = [] res.append(maxi) for i in range(k, n): a = queue.pop(0) queue.append(a...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VA...
Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K. Example 1: Input: N = 9, K = 3 arr[] = 1 2 3 1 4 5 2 3 6 Output: 3 3 4 5 5 5 6 Explanation: 1st contiguous subarray = {1 2 3} Max = 3 2nd contiguous subarray = {2 3 1} Max = 3 3rd contiguous subarray =...
class Solution: def max_of_subarrays(self, arr, n, k): m = [] max_val = float("-inf") for i in range(k): max_val = max(max_val, arr[i]) m.append(max_val) for i in range(k, n): if arr[i] > max_val: max_val = arr[i] elif arr[...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER E...
Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K. Example 1: Input: N = 9, K = 3 arr[] = 1 2 3 1 4 5 2 3 6 Output: 3 3 4 5 5 5 6 Explanation: 1st contiguous subarray = {1 2 3} Max = 3 2nd contiguous subarray = {2 3 1} Max = 3 3rd contiguous subarray =...
class Solution: def max_of_subarrays(self, arr, n, k): arr1 = [] max_val = max(arr[:k]) arr1.append(max_val) for i in range(1, n - k + 1): if arr[i - 1] == max_val: max_val = max(arr[i : i + k]) elif arr[i + k - 1] > max_val: m...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_...
Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K. Example 1: Input: N = 9, K = 3 arr[] = 1 2 3 1 4 5 2 3 6 Output: 3 3 4 5 5 5 6 Explanation: 1st contiguous subarray = {1 2 3} Max = 3 2nd contiguous subarray = {2 3 1} Max = 3 3rd contiguous subarray =...
class Solution: def max_of_subarrays(self, arr, n, k): queue = [] result = [] for i in range(n): if len(queue) == 0 or queue[len(queue) - 1] >= arr[i]: queue.append(arr[i]) else: j = len(queue) - 1 while j >= 0 and queu...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_...
Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K. Example 1: Input: N = 9, K = 3 arr[] = 1 2 3 1 4 5 2 3 6 Output: 3 3 4 5 5 5 6 Explanation: 1st contiguous subarray = {1 2 3} Max = 3 2nd contiguous subarray = {2 3 1} Max = 3 3rd contiguous subarray =...
class Solution: def max_of_subarrays(self, arr, n, k): r = [] r.append(max(arr[:k])) j = 0 for i in range(k, n): if arr[j] == r[-1]: r.append(max(arr[j + 1 : i + 1])) elif arr[i] > r[-1]: r.append(arr[i]) else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR
Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K. Example 1: Input: N = 9, K = 3 arr[] = 1 2 3 1 4 5 2 3 6 Output: 3 3 4 5 5 5 6 Explanation: 1st contiguous subarray = {1 2 3} Max = 3 2nd contiguous subarray = {2 3 1} Max = 3 3rd contiguous subarray =...
class Solution: def max_of_subarrays(self, arr, n, k): curr = max(arr[:k]) res = [curr] for i in range(1, n - k + 1): if arr[i + k - 1] >= curr: curr = arr[i + k - 1] elif arr[i - 1] == curr: curr = max(arr[i : i + k]) res....
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR RETURN...
Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times. Example 1: Input: s = "aaabb", k = 3 Output: 3 The longest substring is "aaa", as 'a' is repeated 3 times. Example 2: Input: s = "ababbc", k = 2 Output...
class Solution: def longestSubstring(self, s, k): for i in set(s): if s.count(i) < k: return max(self.longestSubstring(t, k) for t in s.split(i)) return len(s)
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR
Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times. Example 1: Input: s = "aaabb", k = 3 Output: 3 The longest substring is "aaa", as 'a' is repeated 3 times. Example 2: Input: s = "ababbc", k = 2 Output...
class Solution: def longestSubstring(self, s, k): s_set = set(s) ans = -2147483647 for c in s_set: if s.count(c) < k: return max([self.longestSubstring(_s, k) for _s in s.split(c)]) return len(s)
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR
Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times. Example 1: Input: s = "aaabb", k = 3 Output: 3 The longest substring is "aaa", as 'a' is repeated 3 times. Example 2: Input: s = "ababbc", k = 2 Output...
class Solution: def longestSubstring(self, s, k): characters = {} separators = set([]) for char in s: char_count = characters.get(char, 0) characters[char] = char_count + 1 for char, count in characters.items(): if count < k: separ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR FUNC_...
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string. Example 1: Input:s1 = "ab" s2 = "eidbaooo" Output:True Explanation: s2 contains one permutation of s1 ("ba"). Example 2: ...
class Solution: def checkInclusion(self, s1, s2): length_1 = len(s1) length_2 = len(s2) if length_1 > length_2: return False S1_MAP = [0] * 128 S2_MAP = [0] * 128 for char in s1: S1_MAP[ord(char)] += 1 index = 0 while index < l...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR...
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string. Example 1: Input:s1 = "ab" s2 = "eidbaooo" Output:True Explanation: s2 contains one permutation of s1 ("ba"). Example 2: ...
class Solution: def checkInclusion(self, s1, s2): if len(s2) < len(s1): return False c1 = [0] * 128 n = 0 for i in s1: c = ord(i) if c1[c] == 0: n += 1 c1[c] += 1 for i in range(len(s1)): c = ord(s2[...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBE...
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string. Example 1: Input:s1 = "ab" s2 = "eidbaooo" Output:True Explanation: s2 contains one permutation of s1 ("ba"). Example 2: ...
class Solution: def checkInclusion(self, s1, s2): if len(s2) < len(s1): return False counter = collections.defaultdict(int) for c in s1: counter[c] += 1 seen = collections.defaultdict(int) for i in range(len(s1) - 1): seen[s2[i]] += 1 ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: mymap = collections.defaultdict(int) st, j, n = 0, 0, len(s) while st + minSize <= n: count = collections.Counter(s[st : st + minSize - 1]) for j in range(st + minSize - 1,...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR V...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: counter = collections.defaultdict(int) mapping = collections.defaultdict(int) if len(s) < minSize: return 0 count = 0 for i in range(minSize): mapping[s[i]]...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VA...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, mxl: int, mns: int, mxs: int) -> int: freq = collections.Counter() for i in range(mns, len(s) + 1): for j in range(mxs - mns + 1): if i + j > len(s): break curr = s[i - mns : i + j] ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: if minSize > len(s): return 0 left = 0 candidates = Counter() while left <= len(s) - minSize: right = left + minSize count = set(s[left:right]) ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FU...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: count = Counter() for k in range(minSize, maxSize + 1): window = Counter(s[:k]) if len(window) <= maxLetters: count[s[:k]] += 1 for i in range(k, len(s)...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_O...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: currDct = {} ansDct = defaultdict(int) length = len(s) l = 0 r = 0 while l + minSize < length + 1: currDct = Counter(s[l : l + minSize]) if len(curr...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUM...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: res = collections.Counter() n = len(s) size = minSize while size <= maxSize: M = collections.defaultdict(int) for i, c in enumerate(s): if i < size:...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NU...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: ans = 0 l = minSize counts = {} for i in range(len(s) - l + 1): string = s[i : i + l] c = collections.Counter(string) if len(c) <= maxLetters: ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR FUNC_CALL V...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: if len(s) < minSize: return 0 occur = {} l, r = 0, minSize while r <= len(s): sub = s[l:r] if occur.get(sub) is None: distinct = set(sub...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN FUNC_CA...