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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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": temp.append(s[idx]) idx -= 1 break else: temp.append(s[idx]) idx -= 1 if d & 1: for i in temp: ans[ed] = i ed -= 1 else: for i in temp: ans[st] = i st += 1 d += 1 astr = "".join(ans) print(astr)
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 VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 = int(input()) for i in range(0, t): n = int(input()) test_string = input() test_string = " ".join(test_string) s = test_string.split(" ") x = reverse_per_vowel(s) print(x)
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 FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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: s += a[i] elif not vowel(a[i]) and x % 2: q += a[i] elif vowel(a[i]) and x % 2 == 0: s += a[i] x += 1 elif vowel(a[i]) and x % 2: q += a[i] x += 1 print(q + s[::-1])
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 FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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, -1): m = i l += s[i] if s[i] in ["a", "e", "i", "o", "u"]: break s1 = "" f = False s2 = "" for i in range(m): if s[i] in ["a", "e", "i", "o", "u"]: if i != 0: f = not f if f: s2 += s[i] continue s1 += s[i] if c % 2 == 0: print(s1[::-1] + s2 + l[::-1]) continue print(s2[::-1] + s1 + l[::-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 VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR LIST STRING STRING STRING STRING STRING IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 if s[l : i + 1] != []: panku.append((s[l : i + 1], count)) o = "" e = "" panku.sort(key=lambda x: x[1]) for i in range(len(panku)): if panku[i][1] % 2 == 0: e = panku[i][0][::-1] + e else: o = o + panku[i][0] print(o + 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 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 VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER LIST EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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(s[i]): sub = 0 else: p2.append(s[i]) if find(s[i]): sub = 1 for i in range(len(p2)): print(p2[i], end="") for i in range(len(p1) - 1, -1, -1): print(p1[i], end="") print()
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 EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 = "" post = "" for i in range(0, len(l1)): if i % 2 == 0: pre = pre + l1[i][::-1] else: post = l1[i] + post ans = pre + post + s[last:] print(ans) t = t - 1
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 EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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): if s[i + 1] in vowels: flag = not flag if flag: res[l] = s[i] l += 1 else: res[r] = s[i] r -= 1 return "".join(res) + s[first + 1 :] for _ in range(int(input())): n = int(input()) s = input() print(solve(n, s))
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 NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP FUNC_CALL STRING VAR VAR BIN_OP VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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(len(segments) - 2, -1, -2): print(segments[i][::-1], end="") last = i if last == 1: start = 0 else: start = 1 for i in range(start, len(segments), 2): print(segments[i], end="") print()
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 FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER STRING ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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: b[left] = s[i] left += 1 if s[i] in vowels: vowelc += 1 print("".join(b))
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 VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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)): if c[i] % 2 == 0: s1 += l[i] else: s2 = l[i] + s2 print(s2 + s1)
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 STRING STRING STRING STRING VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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[i] in vowels: v += 1 print("".join(t))
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 NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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(curr_bit) elif s[-i] in vow: bits_.append(curr_bit) curr_bit = "" front, back = "", "" for i in range(len(bits_)): if i & 1: front += bits_[i] else: fa = rev(bits_[i]) back = fa + back ans = front + back print(ans)
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 NUMBER VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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] else: p += s[i] k = 1 - k elif k == 1: q += s[i] else: p += s[i] q = q[::-1] s = p + q print(s)
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 STRING IF VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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: ans = "" flag = False for i in l: if flag: ans = i[::-1] + ans flag = False else: ans = ans + i flag = True else: ans = "" flag = True for i in l: if flag: ans = i[::-1] + ans flag = False else: ans = ans + i flag = True print(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 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_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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: rt.append(x) else: lt.append(x) res = "".join(lt)[::-1] + "".join(rt) if len(st) % 2 == 0: res += s[strt:] else: res = res[::-1] + s[strt:] print(res)
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 LIST FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL STRING VAR NUMBER FUNC_CALL STRING VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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[i] == "e" or s[i] == "i" or s[i] == "o" or s[i] == "u": rev = not rev print("".join(lisst))
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 ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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: new.append(s[i]) sol = [] j = len(l) - 1 i = 0 first = [] second = [] chance = 1 for x in l[::-1]: if chance == 1: first.append(x[::-1]) chance = 2 else: second.insert(0, x) chance = 1 sol = first + second new = "".join(new) sol.append(new) sol = "".join(sol) print(sol)
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_CALL VAR VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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" or s[i] == "i" or s[i] == "o" or s[i] == "u": strt = ~strt for i in range(n): print(res[i], end="") print()
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 VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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": flip += 1 return l + r[::-1] for _ in range(int(input())): print(solve())
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 VAR STRING VAR NUMBER RETURN BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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: q.append(s[i]) elif x == True: p.append(s[i]) x = False y = True else: q.append(s[i]) y = False x = True p.reverse() z = q + p print("".join(z))
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 NUMBER IF VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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): if ind[j] % 2 == 0: o[e] = s[j] e -= 1 else: o[st] = s[j] st += 1 o = "".join(o) print(o)
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 LIST STRING VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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: data[i] = vow_cnt for i in range(n): if not data[i] & 1: res += s[i] print(res) for _ in range(int(input())): solve()
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 NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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] in {"a", "e", "i", "o", "u"} and i > 0: sl[df + dr * i] = s[i] df = df + dr * (i - 1) dr = -dr else: sl[df + dr * i] = s[i] for x in sl: print(x, end="") print()
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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING STRING STRING STRING STRING VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 == 0: fine = j + fine else: fino += j[::-1] print(fino + fine)
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 VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 = "" for i in range(0, len(res), 2): o += res[i] if i + 1 < len(res): e += res[i + 1] if len(res) & 1: print(o[::-1] + e + l) else: print(e[::-1] + o + l) main()
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 STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 check(s[j]): j -= 1 j -= 1 st = 0 end = j dirx = 0 indx = j while indx >= 0: tmp = [] while indx >= 0: if check(s[indx]): tmp.append(s[indx]) indx -= 1 break else: tmp.append(s[indx]) indx -= 1 if dirx % 2 == 1: for i in tmp: ans[end] = i end -= 1 else: for i in tmp: ans[st] = i st += 1 dirx += 1 soln = "".join(ans) print(soln)
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_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 FUNC_CALL VAR BIN_OP VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 = ans + s[i] if s[i] in vowel: flag = not flag i -= 1 count = 0 for i in range(n): if s[i] in vowel: count += 1 if count % 2: flag = False else: flag = True i = 0 while i < n: if s[i] in vowel: flag = not flag if flag: ans = ans + s[i] i += 1 print(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 ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 :]] start = [] pos = len(cval) - 1 while pos >= 0: end.append(v[pos]) start.append(cval[pos][::-1]) pos -= 1 if pos < 0: break start.append(v[pos]) end.append(cval[pos]) pos -= 1 print("".join(start + end[::-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 FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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] if left == True: now -= 1 else: now += 1 else: ans[now] = l[i] if left == True: left = False now -= 1 y = now now = x else: left = True now += 1 x = now now = y print("".join(ans))
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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: self.head = new_node self.tail = new_node return new_node.next = self.head self.head.prev = new_node self.head = new_node def append(self, data): new_node = Node(data) if self.head is None and self.tail is None: self.head = new_node self.tail = new_node return new_node.prev = self.tail self.tail.next = new_node self.tail = new_node T = int(input()) for t in range(T): N = int(input()) line = input() dll = DoublyLL() append = True for c in line: if c in ["a", "e", "i", "o", "u"]: append = not append if append: dll.append(c) else: dll.ppend(c) newll = [] temp_node = dll.head while temp_node.next: newll.append(temp_node.data) temp_node = temp_node.next newll.append(temp_node.data) newl = "".join(newll) if append: print(newl) else: print(newl[::-1])
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 ASSIGN VAR VAR ASSIGN VAR VAR RETURN ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR 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 ASSIGN VAR NUMBER FOR VAR VAR IF VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 front += 1 if val in "aeiou": direction = -direction print("".join(A))
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 ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 = s[rev[0] :] even = "" odd = "" for i in range(len(rev) - 1): while rev[i] - 1 >= rev[i + 1]: if i % 2: even += s[rev[i] - 1] else: odd += s[rev[i] - 1] rev[i] -= 1 print(odd + even[::-1] + 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 NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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): x, y = q[i] ans += s[x:y][::-1] for i in range(len(q) & 1, len(q), 2): x, y = q[i] ans += s[x:y] print("".join(ans + s[last:])) else: print("".join(s))
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_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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: a += temp[i] else: b += temp[i] if len(temp) % 2 != 0: print("".join(list(reversed(b))) + a) else: print("".join(list(reversed(a))) + b)
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 VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 s2 = s1 = "" else: ans1 += s2 s2 = s1 = "" s1 = s[i] + s1 s2 += s[i] if count % 2 == 1: print(ans1 + s2) else: print(ans1[::-1] + s2)
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 BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR STRING VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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.append(s[arr[i - 1] : arr[i]]) else: temp2 = s[arr[i - 1] : arr[i]] temp2 = temp2[::-1] temp.append(temp2) count += 1 l = l - 1 flag = 1 if l % 2 == 0: for i in range(l - 1, -1, -1): if flag == 1: ans = ans + temp[i] flag = 0 else: ans = temp[i] + ans flag = 1 else: for i in range(l - 1, -1, -1): if flag == 1: ans = temp[i] + ans flag = 0 else: ans = ans + temp[i] flag = 1 ans = ans + s[arr[l] :] print(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 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 LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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: flag = not flag print("".join(res))
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 ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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] = string[i] left -= 1 if string[i] in vowels: op = not op print("".join(ans))
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 VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 else: s1 = s1 + s[v_idx - 1 : i : -1] + s[i] v_idx = i flag = 0 if v_idx > 0 and flag == 1: s1 = s1 + s[v_idx - 1 :: -1] elif v_idx > 0 and flag == 0: s1 = s1 + s[0:v_idx] print(s1 + s2)
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 VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 l[i] % 2 == 1: news += s[i] for i in range(n): if l[i] % 2 == 0: news += s[i] print(news)
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 NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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 - 1 : -1], end="") for i in range(len(A) & 1, len(A), 2): x, y = A[i] print(s[x : y + 1], end="") print(s[L : N + 1])
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 ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR BIN_OP 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. Utkarsh has to start from the first letter of the string. Each time he encounters a vowel (i.e. a character from the set \{a, e, i, o, u\}) he has to reverse the entire substring that came before the vowel. Utkarsh needs help verifying his answer. Can you print the final string after performing all the operations for him? ------ Input Format ------ - First line will contain T, number of test cases. Then T test cases follow. - The first line of each test case contains N, the length of the string. - The second line contains S, the string itself. ------ Output Format ------ For each test case, output in a single line the final string after traversing S from left to right and performing the necessary reversals. ------ Constraints ------ $1 ≤ T ≤ 10^{4}$ $1 ≤ N ≤ 10^{6}$ - Sum of $N$ over all test cases does not exceed $10^{6}$. ----- Sample Input 1 ------ 2 10 abcdefghij 7 bcadage ----- Sample Output 1 ------ hgfeabcdij gacbade ----- explanation 1 ------ Test case $1$: The first letter is a vowel, but there is no substring before it to reverse, so we leave it as it is. Next, we reverse abcd and the string becomes dcbaefghij. Next we reach the vowel i and reverse dcbaefgh to get the string hgfeabcdij. Test case $2$: Initially, we reverse bc and the string becomes cbadage. Next we reach the vowel a and reverse cbad to get the string dabcage. Finally we reach the vowel e and reverse dabcag to get the string gacbade.
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_OP VAR VAR NUMBER
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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]) if sums not in dic: dic[sums] = i return longsub
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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]) return leng
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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 - hashMap[remain]) if sum not in hashMap: hashMap[sum] = i return res res = 0 for i in range(n): sum = 0 for j in range(i, n): sum += arr[j] if sum == k: res = max(res, j - i + 1) return res
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR 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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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: mx = max(mx, j - di[s - k]) return mx
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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: length = i - preSumMap[rem] maxLen = max(maxLen, length) if Sum not in preSumMap: preSumMap[Sum] = i return maxLen
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 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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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: reslen = max(reslen, i - dic[cursum - k]) if cursum not in dic: dic[cursum] = i return reslen
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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) if sum_ not in dict_: dict_[sum_] = i return length
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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: sum_indices[s] = i return max_len
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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]) if cur not in dic: dic[cur] = i + 1 return ans
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 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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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 mp: mp[pfs[i]] = i return ans
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 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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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 not in d: d[s] = i return count
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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(ans, i - dict_[arr[i] - k][0]) if arr[i] == k: ans = i + 1 return ans
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 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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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 rem = sum - k if rem in objmap: prev = objmap[rem] n = i - prev if n > maxlen: maxlen = n return maxlen
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 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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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) == True: index_dict[sum_arr[i]] = i for i in range(n): diff = sum_arr[i] - k if diff == 0: result = i + 1 else: j = index_dict.get(diff, -1) if j == -1 or j >= i: continue else: result = i - j if max < result: max = result return max
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 ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN 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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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 += arr[i] if s - k in presum and presum[s - k] <= i: maxlen = max(maxlen, i - presum[s - k]) return maxlen
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 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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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: dic[c] = i + 1 return lon
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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: correction = 0 ans = max(ans, i - mp[sm - k] + correction) if sm not in mp: mp[sm] = i return ans
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 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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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 sumd: c = i - sumd[sum1 - k] if c > l: l = c return l
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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 prefix_map: prefix_map[prefix_sum] = index if prefix_sum - target in prefix_map: res = max(res, index - prefix_map[prefix_sum - target]) return res
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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 return a
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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, length) if ps not in hashmap: hashmap[ps] = i return longest
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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: res = max(res, i - dict1[sum - k]) return res
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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_len = max(maxi_len, i - d[sum - k]) if sum not in d: d[sum] = i return maxi_len
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 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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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: max_length = i + 1 elif prefix_sum[i] - k in hash_map: max_length = max(max_length, i - hash_map[prefix_sum[i] - k]) if prefix_sum[i] not in hash_map: hash_map[prefix_sum[i]] = i return max_length
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 VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR 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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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) max_len = max(max_len, i - j) if prefix_sum.get(sum, True) == True: prefix_sum[sum] = i return max_len
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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: answer = max(answer, index + 1 - sum_map[cumul_sum - k]) if cumul_sum in sum_map: sum_map[cumul_sum] = min(sum_map[cumul_sum], index + 1) else: sum_map[cumul_sum] = index + 1 return answer
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 NUMBER 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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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 if more in map: l = i - map[more] if l > ll: ll = l if sum not in map: map[sum] = i return ll
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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]) if sum not in mydict: mydict[sum] = i return lenn
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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(): pref[res] = i return ans
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 = 6 Output : 0 Explanation: There is no such sub-array with sum 6. Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(N). Constraints: 1<=N<=10^{5} -10^{5}<=A[i], K<=10^{5}
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: if num - k in dic: ans = max(ans, max(dic[num]) - min(dic[num - k])) return ans
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 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 = {3 1 4} Max = 4 4th contiguous subarray = {1 4 5} Max = 5 5th contiguous subarray = {4 5 2} Max = 5 6th contiguous subarray = {5 2 3} Max = 5 7th contiguous subarray = {2 3 6} Max = 6 Example 2: Input: N = 10, K = 4 arr[] = 8 5 10 7 9 4 15 12 90 13 Output: 10 10 10 15 15 90 90 Explanation: 1st contiguous subarray = {8 5 10 7}, Max = 10 2nd contiguous subarray = {5 10 7 9}, Max = 10 3rd contiguous subarray = {10 7 9 4}, Max = 10 4th contiguous subarray = {7 9 4 15}, Max = 15 5th contiguous subarray = {9 4 15 12}, Max = 15 6th contiguous subarray = {4 15 12 90}, Max = 90 7th contiguous subarray = {15 12 90 13}, Max = 90 Your Task: You dont need to read input or print anything. Complete the function max_of_subarrays() which takes the array, N and K as input parameters and returns a list of integers denoting the maximum of every contiguous subarray of size K. Expected Time Complexity: O(N) Expected Auxiliary Space: O(k) Constraints: 1 ≤ N ≤ 10^{5} 1 ≤ K ≤ N 0 ≤ arr[i] ≤ 10^{7}
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[0] <= i - K: q.popleft() while q and arr[i] >= arr[q[-1]]: q.pop() q.append(i) result.append(arr[q[0]]) return result
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 NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR 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 = {3 1 4} Max = 4 4th contiguous subarray = {1 4 5} Max = 5 5th contiguous subarray = {4 5 2} Max = 5 6th contiguous subarray = {5 2 3} Max = 5 7th contiguous subarray = {2 3 6} Max = 6 Example 2: Input: N = 10, K = 4 arr[] = 8 5 10 7 9 4 15 12 90 13 Output: 10 10 10 15 15 90 90 Explanation: 1st contiguous subarray = {8 5 10 7}, Max = 10 2nd contiguous subarray = {5 10 7 9}, Max = 10 3rd contiguous subarray = {10 7 9 4}, Max = 10 4th contiguous subarray = {7 9 4 15}, Max = 15 5th contiguous subarray = {9 4 15 12}, Max = 15 6th contiguous subarray = {4 15 12 90}, Max = 90 7th contiguous subarray = {15 12 90 13}, Max = 90 Your Task: You dont need to read input or print anything. Complete the function max_of_subarrays() which takes the array, N and K as input parameters and returns a list of integers denoting the maximum of every contiguous subarray of size K. Expected Time Complexity: O(N) Expected Auxiliary Space: O(k) Constraints: 1 ≤ N ≤ 10^{5} 1 ≤ K ≤ N 0 ≤ arr[i] ≤ 10^{7}
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: max_element = arr[i] result.append(max_element) return result
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 = {3 1 4} Max = 4 4th contiguous subarray = {1 4 5} Max = 5 5th contiguous subarray = {4 5 2} Max = 5 6th contiguous subarray = {5 2 3} Max = 5 7th contiguous subarray = {2 3 6} Max = 6 Example 2: Input: N = 10, K = 4 arr[] = 8 5 10 7 9 4 15 12 90 13 Output: 10 10 10 15 15 90 90 Explanation: 1st contiguous subarray = {8 5 10 7}, Max = 10 2nd contiguous subarray = {5 10 7 9}, Max = 10 3rd contiguous subarray = {10 7 9 4}, Max = 10 4th contiguous subarray = {7 9 4 15}, Max = 15 5th contiguous subarray = {9 4 15 12}, Max = 15 6th contiguous subarray = {4 15 12 90}, Max = 90 7th contiguous subarray = {15 12 90 13}, Max = 90 Your Task: You dont need to read input or print anything. Complete the function max_of_subarrays() which takes the array, N and K as input parameters and returns a list of integers denoting the maximum of every contiguous subarray of size K. Expected Time Complexity: O(N) Expected Auxiliary Space: O(k) Constraints: 1 ≤ N ≤ 10^{5} 1 ≤ K ≤ N 0 ≤ arr[i] ≤ 10^{7}
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] <= i - k: d.popleft() while len(d) and arr[i] >= arr[d[-1]]: d.pop() d.append(i) res.append(arr[d[0]]) d.popleft() return res
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_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL 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 = {3 1 4} Max = 4 4th contiguous subarray = {1 4 5} Max = 5 5th contiguous subarray = {4 5 2} Max = 5 6th contiguous subarray = {5 2 3} Max = 5 7th contiguous subarray = {2 3 6} Max = 6 Example 2: Input: N = 10, K = 4 arr[] = 8 5 10 7 9 4 15 12 90 13 Output: 10 10 10 15 15 90 90 Explanation: 1st contiguous subarray = {8 5 10 7}, Max = 10 2nd contiguous subarray = {5 10 7 9}, Max = 10 3rd contiguous subarray = {10 7 9 4}, Max = 10 4th contiguous subarray = {7 9 4 15}, Max = 15 5th contiguous subarray = {9 4 15 12}, Max = 15 6th contiguous subarray = {4 15 12 90}, Max = 90 7th contiguous subarray = {15 12 90 13}, Max = 90 Your Task: You dont need to read input or print anything. Complete the function max_of_subarrays() which takes the array, N and K as input parameters and returns a list of integers denoting the maximum of every contiguous subarray of size K. Expected Time Complexity: O(N) Expected Auxiliary Space: O(k) Constraints: 1 ≤ N ≤ 10^{5} 1 ≤ K ≤ N 0 ≤ arr[i] ≤ 10^{7}
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.pop(0) while len(s) != 0 and a[s[-1]] < a[i]: s.pop() s.append(i) o.append(a[s[0]]) return o
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 NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR 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 = {3 1 4} Max = 4 4th contiguous subarray = {1 4 5} Max = 5 5th contiguous subarray = {4 5 2} Max = 5 6th contiguous subarray = {5 2 3} Max = 5 7th contiguous subarray = {2 3 6} Max = 6 Example 2: Input: N = 10, K = 4 arr[] = 8 5 10 7 9 4 15 12 90 13 Output: 10 10 10 15 15 90 90 Explanation: 1st contiguous subarray = {8 5 10 7}, Max = 10 2nd contiguous subarray = {5 10 7 9}, Max = 10 3rd contiguous subarray = {10 7 9 4}, Max = 10 4th contiguous subarray = {7 9 4 15}, Max = 15 5th contiguous subarray = {9 4 15 12}, Max = 15 6th contiguous subarray = {4 15 12 90}, Max = 90 7th contiguous subarray = {15 12 90 13}, Max = 90 Your Task: You dont need to read input or print anything. Complete the function max_of_subarrays() which takes the array, N and K as input parameters and returns a list of integers denoting the maximum of every contiguous subarray of size K. Expected Time Complexity: O(N) Expected Auxiliary Space: O(k) Constraints: 1 ≤ N ≤ 10^{5} 1 ≤ K ≤ N 0 ≤ arr[i] ≤ 10^{7}
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: res.append(arr[dq[0]]) return res
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 = {3 1 4} Max = 4 4th contiguous subarray = {1 4 5} Max = 5 5th contiguous subarray = {4 5 2} Max = 5 6th contiguous subarray = {5 2 3} Max = 5 7th contiguous subarray = {2 3 6} Max = 6 Example 2: Input: N = 10, K = 4 arr[] = 8 5 10 7 9 4 15 12 90 13 Output: 10 10 10 15 15 90 90 Explanation: 1st contiguous subarray = {8 5 10 7}, Max = 10 2nd contiguous subarray = {5 10 7 9}, Max = 10 3rd contiguous subarray = {10 7 9 4}, Max = 10 4th contiguous subarray = {7 9 4 15}, Max = 15 5th contiguous subarray = {9 4 15 12}, Max = 15 6th contiguous subarray = {4 15 12 90}, Max = 90 7th contiguous subarray = {15 12 90 13}, Max = 90 Your Task: You dont need to read input or print anything. Complete the function max_of_subarrays() which takes the array, N and K as input parameters and returns a list of integers denoting the maximum of every contiguous subarray of size K. Expected Time Complexity: O(N) Expected Auxiliary Space: O(k) Constraints: 1 ≤ N ≤ 10^{5} 1 ≤ K ≤ N 0 ≤ arr[i] ≤ 10^{7}
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(arr[i]) if a == maxi: maxi = max(queue) else: maxi = max(maxi, arr[i]) res.append(maxi) return res
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 VAR FUNC_CALL VAR 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 = {3 1 4} Max = 4 4th contiguous subarray = {1 4 5} Max = 5 5th contiguous subarray = {4 5 2} Max = 5 6th contiguous subarray = {5 2 3} Max = 5 7th contiguous subarray = {2 3 6} Max = 6 Example 2: Input: N = 10, K = 4 arr[] = 8 5 10 7 9 4 15 12 90 13 Output: 10 10 10 15 15 90 90 Explanation: 1st contiguous subarray = {8 5 10 7}, Max = 10 2nd contiguous subarray = {5 10 7 9}, Max = 10 3rd contiguous subarray = {10 7 9 4}, Max = 10 4th contiguous subarray = {7 9 4 15}, Max = 15 5th contiguous subarray = {9 4 15 12}, Max = 15 6th contiguous subarray = {4 15 12 90}, Max = 90 7th contiguous subarray = {15 12 90 13}, Max = 90 Your Task: You dont need to read input or print anything. Complete the function max_of_subarrays() which takes the array, N and K as input parameters and returns a list of integers denoting the maximum of every contiguous subarray of size K. Expected Time Complexity: O(N) Expected Auxiliary Space: O(k) Constraints: 1 ≤ N ≤ 10^{5} 1 ≤ K ≤ N 0 ≤ arr[i] ≤ 10^{7}
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[i - k] == max_val: max_val = max(arr[i - k + 1 : i + 1]) m.append(max_val) return m
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 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 = {3 1 4} Max = 4 4th contiguous subarray = {1 4 5} Max = 5 5th contiguous subarray = {4 5 2} Max = 5 6th contiguous subarray = {5 2 3} Max = 5 7th contiguous subarray = {2 3 6} Max = 6 Example 2: Input: N = 10, K = 4 arr[] = 8 5 10 7 9 4 15 12 90 13 Output: 10 10 10 15 15 90 90 Explanation: 1st contiguous subarray = {8 5 10 7}, Max = 10 2nd contiguous subarray = {5 10 7 9}, Max = 10 3rd contiguous subarray = {10 7 9 4}, Max = 10 4th contiguous subarray = {7 9 4 15}, Max = 15 5th contiguous subarray = {9 4 15 12}, Max = 15 6th contiguous subarray = {4 15 12 90}, Max = 90 7th contiguous subarray = {15 12 90 13}, Max = 90 Your Task: You dont need to read input or print anything. Complete the function max_of_subarrays() which takes the array, N and K as input parameters and returns a list of integers denoting the maximum of every contiguous subarray of size K. Expected Time Complexity: O(N) Expected Auxiliary Space: O(k) Constraints: 1 ≤ N ≤ 10^{5} 1 ≤ K ≤ N 0 ≤ arr[i] ≤ 10^{7}
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: max_val = arr[i + k - 1] arr1.append(max_val) return arr1
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_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 = {3 1 4} Max = 4 4th contiguous subarray = {1 4 5} Max = 5 5th contiguous subarray = {4 5 2} Max = 5 6th contiguous subarray = {5 2 3} Max = 5 7th contiguous subarray = {2 3 6} Max = 6 Example 2: Input: N = 10, K = 4 arr[] = 8 5 10 7 9 4 15 12 90 13 Output: 10 10 10 15 15 90 90 Explanation: 1st contiguous subarray = {8 5 10 7}, Max = 10 2nd contiguous subarray = {5 10 7 9}, Max = 10 3rd contiguous subarray = {10 7 9 4}, Max = 10 4th contiguous subarray = {7 9 4 15}, Max = 15 5th contiguous subarray = {9 4 15 12}, Max = 15 6th contiguous subarray = {4 15 12 90}, Max = 90 7th contiguous subarray = {15 12 90 13}, Max = 90 Your Task: You dont need to read input or print anything. Complete the function max_of_subarrays() which takes the array, N and K as input parameters and returns a list of integers denoting the maximum of every contiguous subarray of size K. Expected Time Complexity: O(N) Expected Auxiliary Space: O(k) Constraints: 1 ≤ N ≤ 10^{5} 1 ≤ K ≤ N 0 ≤ arr[i] ≤ 10^{7}
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 queue[j] < arr[i]: j -= 1 queue.pop() queue.append(arr[i]) if i >= k - 1: result.append(queue[0]) if queue[0] == arr[i - k + 1]: queue.pop(0) return result
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_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL 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 = {3 1 4} Max = 4 4th contiguous subarray = {1 4 5} Max = 5 5th contiguous subarray = {4 5 2} Max = 5 6th contiguous subarray = {5 2 3} Max = 5 7th contiguous subarray = {2 3 6} Max = 6 Example 2: Input: N = 10, K = 4 arr[] = 8 5 10 7 9 4 15 12 90 13 Output: 10 10 10 15 15 90 90 Explanation: 1st contiguous subarray = {8 5 10 7}, Max = 10 2nd contiguous subarray = {5 10 7 9}, Max = 10 3rd contiguous subarray = {10 7 9 4}, Max = 10 4th contiguous subarray = {7 9 4 15}, Max = 15 5th contiguous subarray = {9 4 15 12}, Max = 15 6th contiguous subarray = {4 15 12 90}, Max = 90 7th contiguous subarray = {15 12 90 13}, Max = 90 Your Task: You dont need to read input or print anything. Complete the function max_of_subarrays() which takes the array, N and K as input parameters and returns a list of integers denoting the maximum of every contiguous subarray of size K. Expected Time Complexity: O(N) Expected Auxiliary Space: O(k) Constraints: 1 ≤ N ≤ 10^{5} 1 ≤ K ≤ N 0 ≤ arr[i] ≤ 10^{7}
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: r.append(r[-1]) j += 1 return r
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 = {3 1 4} Max = 4 4th contiguous subarray = {1 4 5} Max = 5 5th contiguous subarray = {4 5 2} Max = 5 6th contiguous subarray = {5 2 3} Max = 5 7th contiguous subarray = {2 3 6} Max = 6 Example 2: Input: N = 10, K = 4 arr[] = 8 5 10 7 9 4 15 12 90 13 Output: 10 10 10 15 15 90 90 Explanation: 1st contiguous subarray = {8 5 10 7}, Max = 10 2nd contiguous subarray = {5 10 7 9}, Max = 10 3rd contiguous subarray = {10 7 9 4}, Max = 10 4th contiguous subarray = {7 9 4 15}, Max = 15 5th contiguous subarray = {9 4 15 12}, Max = 15 6th contiguous subarray = {4 15 12 90}, Max = 90 7th contiguous subarray = {15 12 90 13}, Max = 90 Your Task: You dont need to read input or print anything. Complete the function max_of_subarrays() which takes the array, N and K as input parameters and returns a list of integers denoting the maximum of every contiguous subarray of size K. Expected Time Complexity: O(N) Expected Auxiliary Space: O(k) Constraints: 1 ≤ N ≤ 10^{5} 1 ≤ K ≤ N 0 ≤ arr[i] ≤ 10^{7}
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.append(curr) return 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 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: 5 The longest substring is "ababb", as 'a' is repeated 2 times and 'b' is repeated 3 times.
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: 5 The longest substring is "ababb", as 'a' is repeated 2 times and 'b' is repeated 3 times.
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: 5 The longest substring is "ababb", as 'a' is repeated 2 times and 'b' is repeated 3 times.
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: separators.add(char) for i, char in enumerate(s): if char in separators: return max( self.longestSubstring(s[0:i].rstrip(char), k), self.longestSubstring(s[i + 1 :].lstrip(char), k), ) return len(s)
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_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL 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: Input:s1= "ab" s2 = "eidboaoo" Output: False Note: The input strings only contain lower case letters. The length of both given strings is in range [1, 10,000].
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 < length_1 - 1: S2_MAP[ord(s2[index])] += 1 index += 1 while index < length_2: S2_MAP[ord(s2[index])] += 1 if index >= length_1: S2_MAP[ord(s2[index - length_1])] -= 1 if S1_MAP == S2_MAP: return True index += 1 return False
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 VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER
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: Input:s1= "ab" s2 = "eidboaoo" Output: False Note: The input strings only contain lower case letters. The length of both given strings is in range [1, 10,000].
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[i]) c1[c] -= 1 if not c1[c]: n -= 1 if not n: return True for i in range(len(s2) - len(s1)): c = ord(s2[i]) if not c1[c]: n += 1 c1[c] += 1 c = ord(s2[i + len(s1)]) c1[c] -= 1 if not c1[c]: n -= 1 if not n: return True return False
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 NUMBER IF VAR RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER
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: Input:s1= "ab" s2 = "eidboaoo" Output: False Note: The input strings only contain lower case letters. The length of both given strings is in range [1, 10,000].
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 right = len(s1) - 1 while right < len(s2): seen[s2[right]] += 1 if seen == counter: return True right += 1 left = right - len(s1) seen[s2[left]] -= 1 if seen[s2[left]] == 0: del seen[s2[left]] return False
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 IF VAR VAR RETURN NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR RETURN 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, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
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, st + maxSize): if j >= n: break count[s[j]] += 1 if len(count) <= maxLetters: mymap[s[st : j + 1]] += 1 st += 1 maxval = max(list(mymap.values()) or [0]) return maxval
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 VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER RETURN VAR VAR
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, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
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]] += 1 if mapping[s[i]] == 1: count += 1 if count <= maxLetters: counter[s[0:minSize]] += 1 for i in range(1, len(s) - minSize + 1): mapping[s[i - 1]] -= 1 if mapping[s[i - 1]] == 0: count -= 1 mapping[s[i + minSize - 1]] += 1 if mapping[s[i + minSize - 1]] == 1: count += 1 if count <= maxLetters: counter[s[i : i + minSize]] += 1 if not counter: return 0 return max(counter.values())
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 VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
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, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
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] if len(set(curr)) > mxl: break freq[curr] += 1 return max(freq.values() or [0])
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 VAR FUNC_CALL VAR LIST NUMBER VAR
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, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
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]) while ( right <= len(s) and right - left <= maxSize and len(count) <= maxLetters ): if right < len(s): count.add(s[right]) candidates[s[left:right]] += 1 right += 1 left += 1 if not candidates: return 0 return max(candidates.values())
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 FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
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, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
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)): window[s[i]] += 1 window[s[i - k]] -= 1 if window[s[i - k]] == 0: del window[s[i - k]] if len(window) <= maxLetters: count[s[i - k + 1 : i + 1]] += 1 return max(list(count.values()), default=0)
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_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
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, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
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(currDct) <= maxLetters: ansDct[s[l : l + minSize]] += 1 else: l += 1 continue if minSize == maxSize: l += 1 continue r = l + minSize + 1 while r < length and r < l + maxSize: currDct[s[r]] += 1 currDct[s[l]] -= 1 if currDct[s[l]] == 0: del currDct[s[l]] if len(currDct) <= maxLetters: ansDct[s[l : r + 1]] += 1 r += 1 l += 1 return 0 if not ansDct else max(ansDct.values())
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 NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR
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, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
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: M[c] += 1 continue if len(M) <= maxLetters: res[s[i - size : i]] += 1 M[s[i - size]] -= 1 if M[s[i - size]] == 0: del M[s[i - size]] M[c] += 1 if len(M) <= maxLetters: res[s[n - size :]] += 1 size += 1 ans = res.most_common(1) if not ans: return 0 else: return ans[0][1]
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 NUMBER VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR RETURN NUMBER RETURN VAR NUMBER NUMBER VAR
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, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
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: counts[string] = counts.get(string, 0) + 1 if counts: ans = max(ans, max(counts.values())) return ans
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 VAR VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR VAR
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, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
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) if len(distinct) <= maxLetters: occur[sub] = 1 else: occur[sub] += 1 l += 1 r += 1 return max(occur.values()) if len(occur) > 0 else 0
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_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR