description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: vowel = "aeiou" n = len(s) i = k window = s[:k] res = sum([(1) for x in window if x in vowel]) tmp = res while i < n: if s[i - k] in vowel: tmp -= 1 if s[i] in...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR VAR
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: maxNum = -1 currNum = 0 vowels = "aeiou" j = 0 while j < k: if s[j] in vowels: currNum += 1 j += 1 maxNum = max(maxNum, currNum) for i in range(k, len(s)): ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR V...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s, k): vcnt, res = dict(), 0 for i, c in enumerate(s): if i - k >= 0 and s[i - k] in "aeiou": vcnt[s[i - k]] -= 1 if c in "aeiou": vcnt[c] = vcnt.get(c, 0) + 1 res = max(res, sum(vcnt.values())) ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR CLASS_DEF FUNC_DEF...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: l = 0 r = 0 v_set = {"a", "e", "i", "o", "u"} window_len = 0 count = 0 max_len = 0 while r < len(s): if window_len < k: if s[r] in v_set: count += 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VA...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: vowels = {"a", "e", "i", "o", "u"} vowel_count = 0 for i in range(k): if s[i] in vowels: vowel_count += 1 max_vowels = vowel_count for i in range(k, len(s)): if s[i - k] in vo...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING STRING STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR RETURN VAR VAR
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: max_val = 0 tmp = 0 i = 0 he = len(s) for i in range(k): if s[i] in "aeiou": tmp += 1 if tmp == k: return k if tmp > max_val: max_v...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR V...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: vowels = {"a", "e", "i", "o", "u"} current = 0 maxx = 0 start, end = 0, 0 if k == 0: return 0 while end < min(start + k, len(s)): if s[end] in vowels: current += 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR WHILE VAR FUNC_CALL VAR ...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: currMax = 0 curr = 0 vowels = set(["a", "e", "i", "o", "u"]) for i, c in enumerate(s): if c in vowels: curr += 1 if i >= k and s[i - k] in vowels: curr -= 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN VAR VAR
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: vowel = set("aeiou") leftwindow = 0 ans = 0 temp = 0 for rightwindow in range(len(s)): if rightwindow < k: if s[rightwindow] in vowel: temp += 1 an...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUM...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: vowel = {"a", "e", "i", "o", "u"} cnt = 0 for i in range(k): if s[i] in vowel: cnt += 1 if cnt == k: return k i = 0 res = cnt for j in range(k, len(s)): ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING STRING STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETU...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: i = 0 j = i + k - 1 cc = 0 for k in range(i, j + 1): if s[k] == "a" or s[k] == "e" or s[k] == "i" or s[k] == "o" or s[k] == "u": cc += 1 max_c = 0 while j < len(s): if...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR S...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: vo = set(["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]) l, max_l, count = 0, 0, 0 for i in range(len(s)): ch = s[i] if ch in vo: count += 1 if i - l + 1 > k: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: vowel = set({"a", "e", "i", "o", "u"}) curr = 0 maxx = 0 for i in range(k): if s[i] in vowel: curr += 1 maxx += 1 for i in range(1, len(s) - k + 1): if s[i + k...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: maks = 0 string = "" count = 0 lenght = 0 for l in s: if l == "a" or l == "e" or l == "i" or l == "o" or l == "u": count += 1 string += l lenght += 1 i...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBE...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: su, res, vov = 0, 0, ("a", "e", "i", "o", "u") for i, v in enumerate(s): if v in vov: su += 1 if i - k >= 0: if s[i - k] in vov: su -= 1 res = max(res,...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER STRING STRING STRING STRING STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: total = res = 0 for i in range(len(s)): if s[i] in "aeiou": total += 1 if i >= k - 1: res = max(res, total) if s[i - k + 1] in "aeiou": total -= 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR NUMBER RETURN VAR VAR
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: vowels = {"a", "e", "i", "o", "u"} count = 0 maxCount = 0 i = 0 for j in range(len(s)): if s[j] in vowels: count += 1 if j >= k and s[j - k] in vowels: count -...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: vowel = 0 max_vowel = 0 front = 0 for i in range(len(s)): if s[i] == "a" or s[i] == "e" or s[i] == "i" or s[i] == "o" or s[i] == "u": vowel += 1 print(s[i]) if i >= k ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: vowels = {"a", "e", "i", "o", "u"} mx, vowelCount = 0, 0 l, r = 0, 0 while r < len(s): if s[r] in vowels: vowelCount += 1 r += 1 while r - l == k and l < len(s): ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING STRING STRING STRING STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER RETURN ...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: vowels = set("aeiou") init = len([x for x in s[:k] if x in vowels]) ans = init for i in range(1, len(s) - k + 1): if s[i - 1] in vowels: init -= 1 if s[i + k - 1] in vowels: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR R...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: cnt = i = ans = 0 for j in range(len(s)): c = s[j] cnt += s[j] in "aeiou" if j >= k: cnt -= s[i] in "aeiou" i += 1 if j >= k - 1: ans = max(ans...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR STRING IF VAR VAR VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: n = len(s) vowel = set(["a", "e", "i", "o", "u"]) i = 0 res = 0 while i < k: if s[i] in vowel: res += 1 i += 1 j = k i = 0 maxV = res while j <...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBE...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: self.vowels = ["a", "e", "i", "o", "u"] def isVowel(char): return char in self.vowels i = 0 j = 0 cur_count = 0 result = 0 length = len(s) while i < length and j < length: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING FUNC_DEF RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VA...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: a = s[:k] d = {"a": 0, "e": 0, "i": 0, "o": 0, "u": 0} def checkVowels(): total = 0 for key in d: total += d[key] return total for c in s[:k]: if c in d: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR RETURN VAR FOR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR VAR AS...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: ans = 0 cur = 0 for j, c in enumerate(s): cur += c in "aeiou" if j >= k: cur -= s[j - k] in "aeiou" ans = max(ans, cur) return max(ans, cur)
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR STRING IF VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: ans = 0 dic = {"a": 1, "e": 1, "i": 1, "o": 1, "u": 1} for i in range(k): if s[i] in dic: ans += 1 i = 0 j = k temp = ans while j < len(s): if s[j] in dic: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VA...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: def vowel_letters(ch): if ch in ["a", "e", "i", "o", "u"]: return True return False temp = [(1 if vowel_letters(i) else 0) for i in s] su = sum(temp[:k]) m = su for i in ran...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR LIST STRING STRING STRING STRING STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR LIS...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: _start = 0 _end = 0 _max = 0 start = 0 length = 0 count = 0 for end in range(len(s)): length += 1 if self.check(s[end]): count += 1 if length > k: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: vowels = "aeiou" num_vowels = sum(1 for i in range(k) if s[i] in vowels) max_vowels = num_vowels for removed_idx in range(0, len(s) - k): added_idx = removed_idx + k num_vowels += int(s[added_idx] in...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR VAR
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: m, beg, end = len(s), 0, 0 vowels = ["a", "e", "i", "o", "u"] maxi, count = 0, 0 while end < m: if s[end] in vowels: count += 1 if end - beg + 1 >= k: maxi = max(maxi,...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETUR...
Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vowel letters. Example 2: Input: s = "aeiou", k = 2 Output: 2...
class Solution: def maxVowels(self, s: str, k: int) -> int: if not s or not k: return 0 max_vowels = 0 start_pointer = 0 end_pointer = k - 1 vowels = {"a", "e", "i", "o", "u"} num_curr_window_vowels = 0 for i in range(k): if s[i] in vo...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING STRING STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR V...
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform...
class Solution: def isToeplitzMatrix(self, matrix): hashMap = {} for i in range(len(matrix)): for j in range(len(matrix[0])): if hashMap.get(i - j, "no") != "no": if hashMap[i - j] != matrix[i][j]: return False ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR STRING STRING IF VAR BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform...
class Solution: def isToeplitzMatrix(self, matrix): x, y = len(matrix[0]), len(matrix) for i in range(x - 1): for j in range(y - 1): if matrix[j][i] != matrix[j + 1][i + 1]: return False return True
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform...
class Solution: def isToeplitzMatrix(self, matrix): rows = len(matrix) col = len(matrix[0]) i = 0 j = 0 while i < rows - 1: while j < col - 1: print("Comparing: ", matrix[i][j], matrix[i + 1][j + 1]) if matrix[i][j] == matrix[i + 1...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ...
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform...
class Solution: def isToeplitzMatrix(self, matrix): for c in range(len(matrix) - 1): for r in range(len(matrix[0]) - 1): if matrix[c][r] != matrix[c + 1][r + 1]: return False return True
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform...
class Solution: def isToeplitzMatrix(self, matrix): vmap = collections.defaultdict(set) M, N = len(matrix), len(matrix[0]) for x in range(M): for y in range(N): vmap[y - x].add(matrix[x][y]) if len(vmap[y - x]) > 1: return Fals...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform...
class Solution: def isToeplitzMatrix(self, matrix): diagonals_upper = [] x, y = len(matrix[0]), len(matrix) starters = [[0, i] for i in range(x)] + [[i, 0] for i in range(y)] for starter in starters: for j in range(min(x, y)): if starter[0] + j < y and st...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR LIST VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN...
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform...
class Solution: def isToeplitzMatrix(self, matrix): for i in range(0, len(matrix)): for j in range(0, len(matrix[0])): r = i + 1 c = j + 1 while r < len(matrix) and c < len(matrix[0]): if matrix[i][j] == matrix[r][c]: ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform...
class Solution: def isToeplitzMatrix1(self, matrix): row, col = len(matrix), len(matrix[0]) for j in range(col): a = 0 while a + 1 < row and j + a + 1 < col: if matrix[a][j + a] == matrix[a + 1][j + a + 1]: a += 1 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR...
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform...
class Solution: def isToeplitzMatrix(self, matrix): result = True for i in range(len(matrix) - 1): result = result and matrix[i][:-1] == matrix[i + 1][1:] return result
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN VAR
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform...
class Solution: def isToeplitzMatrix(self, matrix): if not matrix: return False colSize = len(matrix[0]) - 1 for row in range(len(matrix) - 1): if matrix[row][:colSize] != matrix[row + 1][1 : colSize + 1]: return False return True
CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform...
class Solution: def isToeplitzMatrix(self, matrix): return all( ( True if len(matrix[i]) == 1 or matrix[i][:-1] == matrix[i + 1][1:] else False ) for i in range(len(matrix) - 1) )
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform...
class Solution: def isToeplitzMatrix(self, matrix): M, N = len(matrix), len(matrix[0]) if M == 1: return True prev_row = matrix[0][:-1] for row in matrix[1:]: if row[1:] != prev_row: return False prev_row = row[:-1] return ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR RETURN NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER
Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order concatenated by a single space. Note that s may contain leading or trailing spaces or multiple spaces...
class Solution: def reverseWords(self, s: str) -> str: s = s.strip().split() l = [] for i in reversed(range(len(s))): l.append(s[i]) return " ".join(l)
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL STRING VAR VAR
Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order concatenated by a single space. Note that s may contain leading or trailing spaces or multiple spaces...
class Solution: def reverseWords(self, s: str) -> str: curr_word = "" ans = [] for char in s: if char == " ": if curr_word != "": ans.append(curr_word) curr_word = "" else: curr_word += char ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR STRING IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING VAR NUMBER VAR
Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order concatenated by a single space. Note that s may contain leading or trailing spaces or multiple spaces...
class Solution: def reverseWords(self, s: str) -> str: sLst = s.split() reverseStr = "" for i in range(len(sLst) - 1, -1, -1): if i == len(sLst) - 1: reverseStr += sLst[i] else: reverseStr += " " + sLst[i] return reverseStr
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR BIN_OP STRING VAR VAR RETURN VAR VAR
Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order concatenated by a single space. Note that s may contain leading or trailing spaces or multiple spaces...
class Solution: def reverseWords(self, s: str) -> str: s = s.strip(" ") ans = "" for segment in s.split(" "): if segment == "": continue ans = segment + " " + ans return ans[:-1]
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR STRING IF VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR RETURN VAR NUMBER VAR
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
t = int(input()) for it in range(t): n, k = input().split(" ") n = int(n) k = int(k) stdin = input().split(" ") a = [int(stdin[i]) for i in range(n)] state = 0 mx = 0 count = 0 maxe = -1 pos = -1 i = 0 while i < n: if state == 0: count += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
for i in range(int(input())): n, k = map(int, input().split()) flag, prevhidx, prevh = 0, 0, 0 urr, mx = 0, 0 idx = [] a = list(map(int, input().split())) for i in range(n): if a[i] > k: if flag == 0: flag = 1 prevhidx = i prevh...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR NUMBER ASSIGN...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
t = int(input()) while t: a = input().split() n = int(a[0]) k = int(a[1]) lst = input().split() for i in range(n): lst[i] = int(lst[i]) greater = 0 length = 0 pos = -1 allTimeLong = 0 for i in range(n): if lst[i] > k and greater != 0 and lst[i] != greater: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR N...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
import sys from sys import stdin, stdout t = int(stdin.readline()) for _ in range(t): n, k = map(int, stdin.readline().strip().split(" ")) arr = list(map(int, stdin.readline().strip().split(" "))) tarr = [] p = -1 for i in range(len(arr)): if arr[i] > k: if p == -1: ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR I...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
T = int(input()) for q in range(T): n, m = map(int, input().strip().split()) arr = list(map(int, input().strip().split())) c = 0 ind = [] mp = {} k = 0 h = 0 arr.append(max(arr) + 1) for i in range(n + 1): if arr[i] <= m: c += 1 elif h == 0: h ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
a = int(input()) for i in range(a): cc = list(map(int, input().split())) dd = list(map(int, input().split())) for i in range(len(dd)): dd[i] -= cc[1] maxs = 0 i = 0 k = 0 while i < len(dd): j = i + 1 if dd[i] > 0: count = 1 + (i - k) k = i + 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VA...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
t = int(input()) while t > 0: n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] first = 0 prev = 0 i = 0 len = 0 maxlen = 0 while i < n: if a[i] > k: if first == 0: first = a[i] prev = i len ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR VA...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
def solve(arr, n, k): if max(arr) <= k: return 0 ans = 0 m = -1 f = 0 i = 0 j = -1 while j < n - 1: if arr[j + 1] <= k: j += 1 elif arr[j + 1] > k: if m == -1: m = arr[j + 1] f += 1 j += 1 ...
FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VA...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
t = int(input()) for i in range(t): n, k = map(int, input().strip().split()) a = list(map(int, input().strip().split())) c = 0 x = 0 b = list() i1 = 0 i2 = 0 for j in range(n): c += 1 if a[j] > k: x += 1 if x == 1: i1 = j ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_C...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
t = int(input()) for _ in range(t): n, k = list(map(int, input().strip().split())) a = list(map(int, input().strip().split())) c = 0 f = 0 b = [] d = [0, 0] for i in range(n): if a[i] > k: f += 1 if f == 1: d[0] = i elif a[i] == a[d...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CA...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
def answer(): for t in range(int(input())): N, K = [int(x) for x in input().split()] l = [-1] l += [int(x) for x in input().split()] green = 0 orange = 0 red = 0 ans = 0 while True: orange += 1 if orange == N + 1: ...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
import sys def _int(): return int(sys.stdin.readline()) def _ints(): return map(int, sys.stdin.readline().split()) def _intarr(): return list(map(int, sys.stdin.readline().split())) def _str(): return sys.stdin.readline() def _strarr(): return sys.stdin.readline().split() t = _int() ans ...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR AS...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
for _ in range(int(input())): n, k = list(map(int, input().split())) arr = list(map(int, input().split())) if n == 1: if arr[0] >= k: print(2) else: print(1) elif n == 2: mx, mn = max(arr[0], arr[1]), min(arr[0], arr[1]) if mn >= k: if ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR N...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
for _ in range(int(input())): n, k = list(map(int, input().split())) a = list(map(int, input().split())) def check(mid): d, left = {}, 0 for i in range(mid): if a[i] > k: if a[i] not in d: d[a[i]] = 1 else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR DICT NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NU...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
for i in range(int(input())): n, k = input().split() n = int(n) k = int(k) arr = list(map(int, input().split())) a = 0 b = 0 count = 0 ans = 0 temp = -1 w = 0 index1 = index2 = None while b < n: if arr[b] > k: if count == 0: index1 = b ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBE...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
for _ in range(int(input())): input_list = input().split() N, K = int(input_list[0]), int(input_list[1]) A = list(map(int, input().split())) index = [] greater_elem = -1 for i in range(0, N): if A[i] > K and A[i] != greater_elem: index.append(i) greater_elem = A[i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
for _ in range(int(input())): n, k = list(map(int, input().split())) ays = list(map(int, input().split())) gt = k gtp = -1 mseg = 0 seg = 0 for ax, a in enumerate(ays): if a <= k: seg += 1 elif a == gt: seg += 1 gtp = ax else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
T = int(input()) for _ in range(T): N, K = map(int, input().split()) A = list(map(int, input().split())) lower = [] ans = [] if A[0] > K: ans.append(1) lower.append(0) M = A[0] else: ans.append(0) lower.append(1) for i in range(1, N): if A[i] >...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FU...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
t = int(input()) for j in range(t): n, k = list(map(int, input().split())) a = list(map(int, input().split())) mm = 0 x = 1 l = 0 m = -1 for i in range(n): if x == 1: if a[i] > k: c = i l = l + 1 m = a[i] x =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VA...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
for _ in range(int(input())): n, k = list(map(int, input().split())) a = list(map(int, input().split())) c = 0 d = {} l = 0 r = 0 sm = 0 m = 1 i = 0 while i < n: if a[i] > k: if a[i] not in d or d[a[i]] == -1: c += 1 d[a[i]] = i ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VA...
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
t = int(input()) for i in range(t): n, k = map(int, input().split()) a = list(map(int, input().split())) lt = list() nos = list() p = -1 for j in range(n): if a[j] > k: nos.append(a[j]) lt.append(j + 1) lt = [0] + lt + [n + 1] l, j = 0, 0 tm = len(lt) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR...
You are given three integers n, k, m and m conditions (l_1, r_1, x_1), (l_2, r_2, x_2), ..., (l_m, r_m, x_m). Calculate the number of distinct arrays a, consisting of n integers such that: * 0 ≤ a_i < 2^k for each 1 ≤ i ≤ n; * bitwise AND of numbers a[l_i] \& a[l_i + 1] \& ... \& a[r_i] = x_i for each 1 ≤ i ≤ m...
import sys def main(): import sys input = sys.stdin.buffer.readline mod = 998244353 N, K, M = map(int, input().split()) cond = [] for _ in range(M): cond.append(tuple(map(int, input().split()))) ans = 1 for k in range(K): one = [0] * (N + 1) zero_cond = [0] * (...
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR N...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], k: int) -> int: flipped = collections.deque() flips = 0 for i in range(len(A)): if flipped and flipped[0] < i: flipped.popleft() if not (len(flipped) & 1) - A[i]: if i <= len(A) - k:...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: is_flipped = [0] * len(A) flipped = result = 0 for i in range(len(A)): if i >= K: flipped ^= is_flipped[i - K] if A[i] == flipped: if i + K > len(A): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: N = len(A) flipped = [(0) for _ in range(N)] curr = 0 ans = 0 for i in range(N): if i >= K: curr ^= flipped[i - K] if curr == A[i]: if i + K > N: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, a: List[int], k: int) -> int: n = len(a) toggles = [0] * (n + 1) min_flips = 0 view = 0 for i, b in enumerate(a): view ^= toggles[i] if b ^ view == 0: if i + k > n: return -1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER RETURN VAR VAR
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], k: int) -> int: c = 0 flippedtill = [(0) for i in range(len(A) + 1)] curr = 0 if len(A) == k: if sum(A) == 0: return 1 elif sum(A) == len(A): return 0 else: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR V...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: n = len(A) num = 0 flip_queue = [] flip_sum = 0 for i in range(n - K + 1): if flip_sum & 1: add = 1 if A[i] == 1 else 0 else: add = 1 if A[i] == 0 els...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR ...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: flips = collections.deque() cnt = 0 for i in range(len(A)): while flips and flips[0] <= i - K: flips.popleft() curtStatus = A[i] + len(flips) if curtStatus % 2 == 0: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR NU...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: nums = A flip_count = 0 flip_hint = [0] * len(nums) total_flips = 0 for i, n in enumerate(nums): if i >= K and flip_hint[i - K]: total_flips -= 1 if total_flips % 2 =...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], k: int) -> int: k_bit_flip_end_indices = deque() switch = 0 flips = 0 for i, bit in enumerate(A): if len(k_bit_flip_end_indices) & 1 ^ bit == 0: flips += 1 k_bit_flip_end_indices.append(...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR VAR NUMBER VAR
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: q = collections.deque() res = 0 for i, num in enumerate(A): while len(q) > 0 and i - q[0] >= K: q.popleft() if len(q) % 2 == 1 and num == 1 or len(q) % 2 == 0 and num == 0: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR R...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: Fliped = [0] * len(A) cnt = 0 for i in range(len(A)): if i >= K: fliped = cnt - Fliped[i - K] else: fliped = cnt if A[i] == 0 and fliped % 2 == 0 or A[i] ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR V...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: l = len(A) flipped = [0] * l res = 0 flipping_count = 0 for i in range(l): if i >= K: flipping_count -= flipped[i - K] if ( flipping_count % 2 == 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER VAR VAR NUM...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: res = 0 queue = collections.deque([]) for i in range(len(A)): while queue and queue[0] < i: queue.popleft() if (A[i] + len(queue)) % 2 == 0: if i + K - 1 >= len(A): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: flip_time = 0 n = len(A) close = [(False) for i in range(n)] res = 0 for i in range(n): if close[i]: flip_time -= 1 if A[i] == 0 and flip_time % 2 == 0 or A[i] == 1 a...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NU...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: counter = 0 q = [] qL = 0 for i in range(len(A) - K + 1): if A[i] == (len(q) - qL) % 2: counter += 1 q.append(i + K - 1) if qL < len(q) and q[qL] == i: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUN...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: ALen = len(A) flips = [] prevF = 0 ans = 0 l = 0 for i, num in enumerate(A): temp = 0 while l + temp < len(flips) and flips[l + temp] + K - 1 < i: temp += 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP ...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: n = len(A) flip = 0 current_flips = 0 queue = [] for i in range(n): if len(queue) > 0 and queue[0] + K == i: queue.pop(0) current_flips = current_flips - 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMB...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: n = len(A) record = [0] * n flip = 0 ans = 0 for i in range(n): if i >= K: flip -= record[i - K] if A[i] == flip % 2: if i > n - K: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR VAR
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: dq = deque() res = 0 for i in range(len(A)): if A[i] == len(dq) % 2: res += 1 dq.append(i + K - 1) if dq and dq[0] <= i: dq.popleft() return r...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR RETURN VAR VAR NUMBER VAR
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: flip_ends = deque() count = 0 for idx, bit in enumerate(A): if len(flip_ends) > 0 and idx >= flip_ends[0]: flip_ends.popleft() val = (bit + len(flip_ends)) % 2 if val == ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: ans = flip = 0 N = len(A) hint = [0] * N for i, x in enumerate(A): flip ^= hint[i] if x ^ flip == 0: ans += 1 if i + K > N: return -1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR VAR
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], k: int) -> int: n = len(A) count = [0] * n ps = 0 res = 0 for i in range(n - k + 1): flip = ps + A[i] if flip % 2 == 0: count[i] = 1 res += 1 ps += 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBE...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: n = len(A) flips = [0] * n flip = 0 ans = 0 def mapping(a: int, flip: int) -> int: return 1 - a if flip % 2 == 1 else a for i, a in enumerate(A): flip += flips[i] ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF VAR VAR RETURN BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR N...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution(object): def minKBitFlips(self, A, K): N = len(A) flip = 0 flip_ends = [0] * (N + 1) res = 0 for i, num in enumerate(A): flip ^= flip_ends[i] if not num ^ flip: if i + K > N: return -1 ...
CLASS_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER RETURN VAR
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: flips = 0 q = deque() for i, x in enumerate(A): if q and q[0] == i: q.popleft() if len(q) & 1: x ^= 1 if x == 0: flips += 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN VAR VAR
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: num = 0 for a in A: num = (num << 1) + a i = 0 pattern = (1 << K) - 1 flips = 0 while i + K <= len(A): while i + K <= len(A) and num & 1 << i: i += 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR FUNC...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: i = 0 c = 0 q = collections.deque() sign = 0 while True: while i < len(A) and A[i] != sign: i += 1 if q and i == q[0]: q.popleft() ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR FUNC_CALL VAR VAR RETURN VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETU...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: n = len(A) ff = [(0) for i in range(n)] cur = 0 f = 0 for i in range(n): cur += ff[i] xo = cur % 2 if xo ^ A[i] == 0: if i + K - 1 > n - 1: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER VAR NUMBER VAR VAR NUMBE...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: i = 0 ans = 0 flips = 0 dq = collections.deque() while i < len(A): while dq and i >= dq[0]: dq.popleft() flips -= 1 if (A[i] + flips) % 2 == 1: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR BIN_...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: n = len(A) ans = 0 flips = 0 addon = 6 m = False for i in range(n): if A[i] > 5: m = True A[i] -= addon if flips % 2 == 0 and A[i] == 0 or fli...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VA...
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of K-bit flips required so that there is no 0 in the array.  If it is not possible, return ...
class Solution: def minKBitFlips(self, A: List[int], K: int) -> int: total_flips = 0 current_effective_flips = 0 flip_indices = [] for current_index, elem in enumerate(A): if flip_indices and current_index == flip_indices[0] + K: flip_indices.pop(0) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR FU...