description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: curr_sum = 0 intervals = [(-200002, -100001), (-200002, -100001)] h = {(0): -1} f = [([100001] * len(arr)) for i in range(2)] for index, a in enumerate(arr): curr_sum += a ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BI...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: if not arr: return -1 def getMinSub(arr, target): dp = [float("inf")] * len(arr) total = 0 lookup = defaultdict(int) for index, val in enumerate(arr): ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: lens_s = [math.inf] * len(arr) lens_e = [math.inf] * len(arr) cs = s = e = 0 for i in range(len(arr)): cs += arr[e] while cs >= target: if cs == target: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: prefix = {(0): -1} best_sofar_arr = [math.inf] best_sofar = math.inf curr_best = math.inf ans = math.inf new_ans = math.inf for i, curr in enumerate(itertools.accumulate(arr)): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN 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 EXPR FUNC_CALL VAR V...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: prefix, suffix = [float("inf")] * len(arr), [float("inf")] * len(arr) curSum, l = 0, 0 for r in range(1, len(arr)): prefix[r] = prefix[r - 1] curSum += arr[r - 1] while curSum ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN V...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: l = 0 currentSum = 0 res = -1 record = [-1] * len(arr) for r in range(len(arr)): currentSum += arr[r] while currentSum > target and l < r: currentSum -= arr...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VA...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: n = len(arr) dp = [100001] * n presum = {(0): -1} s = 0 ans = 100001 best_so_far = sys.maxsize for i in range(n): s += arr[i] presum[s] = i if s...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP ...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: prefix_sum = [float("inf")] * len(arr) suffix_sum = [float("inf")] * len(arr) prefix_map = {(0): -1} suffix_map = {(0): len(arr)} cur_sum = 0 _min_till_now = float("inf") for i in ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR DICT NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR V...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: if not arr: return 0 n = len(arr) dp = [float("inf")] * n presum = 0 indexes = {(0): -1} res = float("inf") for i, a in enumerate(arr): presum += a ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: d = {} d[0] = -1 possible_sum = {0} cur_sum = 0 for i, a in enumerate(arr): cur_sum += a possible_sum.add(cur_sum) d[cur_sum] = i till_len = [float("inf...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: prefix = [0] d = {(0): -1} for i in range(len(arr)): prefix.append(arr[i] + prefix[-1]) d[prefix[-1]] = i ans = first = second = float("inf") for i in range(len(arr)): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIG...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: smallest = [math.inf] * len(arr) q = deque() curr_sum = 0 result = math.inf for i, n in enumerate(arr): curr_sum += n q.append(i) while curr_sum > target: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR FUNC_CALL VAR IF VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FU...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: MAX = float("inf") n = len(arr) + 1 best_till = [MAX for i in range(n + 1)] presum = 0 maps = {} maps[0] = -1 ans = best = MAX for i, v in enumerate(arr): presu...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: pre_index, curr_sum = 0, 0 f = [100001] * (len(arr) + 1) ans = 100001 for index, a in enumerate(arr): curr_sum += a while curr_sum > target: curr_sum -= arr[pre_ind...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: sums_list = [0] sums_dict = {(0): 0} s = 0 for i in range(len(arr)): s += arr[i] sums_dict[s] = i + 1 sums_list.append(s) lengths = [0] * len(sums_list) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP F...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: length = len(arr) cumulative = [0] * length reverse_cumulative = [0] * length s = 0 sr = 0 for i in range(length): s = s + arr[i] cumulative[i] = s sr +...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT NUMBER NU...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: minlen = [float("inf")] * len(arr) res = float("inf") l, r, windsum = 0, 0, 0 for r in range(len(arr)): windsum += arr[r] while windsum > target: windsum -= arr[l] ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING ASSIGN VA...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: prefix = {(0): -1} current = 0 queue = [] for i in range(len(arr)): current += arr[i] prefix[current] = i if not prefix.get(current - target) is None: i...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NONE IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP V...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: premin = [float("inf")] * len(arr) l, cur, res = 0, 0, float("inf") for r, num in enumerate(arr): if r > 0: premin[r] = premin[r - 1] cur += num while cur > tar...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUM...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: preSum = [0] for val in arr: preSum.append(preSum[-1] + val) sumMap = {} preCands = [sys.maxsize] * len(arr) sufCands = [sys.maxsize] * len(arr) for i, val in enumerate(preSum)...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution(object): def minSumOfLengths(self, arr: List[int], target: int) -> int: prefix = {(0): -1} best_till = [math.inf] * len(arr) ans = best = math.inf for i, curr in enumerate(itertools.accumulate(arr)): if curr - target in prefix: end = prefix...
CLASS_DEF VAR FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL V...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: n = len(arr) left_presum = {(0): 0} left_dp = [float("inf")] * (n + 1) total = 0 for i in range(1, n + 1): total += arr[i - 1] if total - target in left_presum: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR ...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: n = len(arr) def aux(arr): h = {(0): 0} preSum = 0 left = [(n + 1) for i in range(n)] for i in range(1, n + 1): preSum = preSum + arr[i - 1] ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VA...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: min_range = None left = self.get_list(arr, target) right = list(reversed(self.get_list(list(reversed(arr)), target))) print(left) print(right) min_length = None for i in range(len(...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NU...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: n = len(arr) best_to = [(n + 1) for _ in range(n)] best_from = dict() min_total = n + 1 min_left = n + 1 sum_left = 0 s_left = 0 e_left = 0 for i in range(n): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP B...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: psum = {(0): -1} csum = 0 re = 100001 dp = [100001] * len(arr) best = 100001 for i, csum in enumerate(itertools.accumulate(arr)): psum[csum] = i if csum - target in...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR FU...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: prefxSum, prefx = 0, [] suffxSum, suffx = sum(arr), [] dct = {(0): -1} dp = [float("inf")] * len(arr) for i in range(0, len(arr)): x = arr[i] prefxSum += x pref...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER LIST ASSIGN VAR VAR FUNC_CALL VAR VAR LIST ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSI...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: dp = [float("inf") for i in range(len(arr))] curr_sum = 0 hist = {(0): -1} res = float("inf") shortest_length = float("inf") for i, num in enumerate(arr): curr_sum += num ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: def getPrefix(arr): m = {(0): -1} prefix = [float("inf")] s = 0 for i, n in enumerate(arr): s += n minn = prefix[-1] if s - target ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR LIST FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CA...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: n = len(arr) acc = dict() acc[-1] = 0 for i in range(0, n): acc[i] = acc[i - 1] + arr[i] best_to = [(n + 1) for _ in range(n)] best_from = dict() min_total = n + 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FO...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: lengths = [len(arr) + 1] * (len(arr) + 1) i = 0 j = 0 s = 0 min_two_sum = len(arr) + 1 while j <= len(arr): if s < target: if j == len(arr): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP V...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: def get_shortest(array): shortest = [float("infinity") for _ in range(len(arr))] prefix_pos = {} prefix_sum = 0 for i in range(len(array)): prefix_sum += array[i] ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: n = len(arr) min_lens = [sys.maxsize] * n l = 0 min_len = sys.maxsize prefix = 0 ans = sys.maxsize for r in range(n): prefix += arr[r] while prefix > target...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER V...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: n = len(arr) curr_sum = 0 curr_best = -1 lo = hi = 0 lmin = [] while lo <= hi < n: curr_sum += arr[hi] while curr_sum > target and lo <= hi: curr_su...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ...
Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required su...
class Solution: def minSumOfLengths(self, arr: List[int], target: int) -> int: presum = [0] * len(arr) c = 0 for i in range(len(arr)): c += arr[i] presum[i] = c dic = {(0): -1} index = [0] * len(arr) short = [0] * len(arr) temp = sys.m...
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 VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUN...
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing N integers. Consider any subarray [A_{L}, A_{L+1}, \ldots, A_{R}] of this subarray (where 1≤ L ≤ R ≤ N). Ther weirdness of this subarray, denoted w(L, R), is defined to be the number of indices L ≤ i ≤ R such that A_{i} equals the number of occurrence...
t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) hm = {} for i in range(len(arr)): if arr[i] in hm: hm[arr[i]].append(i) else: hm[arr[i]] = [i] ans = 0 for i in hm: x = len(hm[i]) if x >= i: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR NUMBER F...
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing N integers. Consider any subarray [A_{L}, A_{L+1}, \ldots, A_{R}] of this subarray (where 1≤ L ≤ R ≤ N). Ther weirdness of this subarray, denoted w(L, R), is defined to be the number of indices L ≤ i ≤ R such that A_{i} equals the number of occurrence...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) adict = {} for i in range(n): if a[i] in adict: adict[a[i]].append(i) else: adict[a[i]] = [i] w = 0 for key in adict: alist = adict[key] prev = 0 for...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR...
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing N integers. Consider any subarray [A_{L}, A_{L+1}, \ldots, A_{R}] of this subarray (where 1≤ L ≤ R ≤ N). Ther weirdness of this subarray, denoted w(L, R), is defined to be the number of indices L ≤ i ≤ R such that A_{i} equals the number of occurrence...
for tc in range(int(input())): n = int(input()) ls = list(map(int, input().split())) freq = dict() for x in ls: if freq.get(x) is None: freq[x] = 1 else: freq[x] += 1 dis = dict() for x in range(len(ls)): if freq[ls[x]] >= ls[x]: if dis...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR...
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing N integers. Consider any subarray [A_{L}, A_{L+1}, \ldots, A_{R}] of this subarray (where 1≤ L ≤ R ≤ N). Ther weirdness of this subarray, denoted w(L, R), is defined to be the number of indices L ≤ i ≤ R such that A_{i} equals the number of occurrence...
def read_int_ist(): lst = list(map(int, input().split(" "))) return lst def read_int_values(): return map(int, input().split(" ")) def solve(len1, a) -> int: ans = 0 lst_indices = [[] for _ in range(len1 + 1)] for i in range(1, len(a) + 1): if a[i - 1] <= len1: lst_indice...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUM...
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing N integers. Consider any subarray [A_{L}, A_{L+1}, \ldots, A_{R}] of this subarray (where 1≤ L ≤ R ≤ N). Ther weirdness of this subarray, denoted w(L, R), is defined to be the number of indices L ≤ i ≤ R such that A_{i} equals the number of occurrence...
for _ in range(int(input())): n = int(input()) x = list(map(int, input().split())) for i in range(n): x[i] = [x[i], i] x = sorted(x) xd = [] xd += [x[0][0], [x[0][1]]] for i in range(1, n): if x[i][0] == x[i - 1][0]: xd[-1] += [x[i][1]] else: x...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR LIST VAR NUMBER NUMBER LIST VAR NUMBER NUMBER FOR VAR FUN...
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing N integers. Consider any subarray [A_{L}, A_{L+1}, \ldots, A_{R}] of this subarray (where 1≤ L ≤ R ≤ N). Ther weirdness of this subarray, denoted w(L, R), is defined to be the number of indices L ≤ i ≤ R such that A_{i} equals the number of occurrence...
for t in range(int(input())): N = int(input()) A = list(map(int, input().split())) dic = {} count = 0 for i in range(N): if A[i] not in dic: dic[A[i]] = [] dic[A[i]].append(i) for i in dic.keys(): if len(dic.get(i)) < i: continue temp = [] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR IF FUNC_CALL...
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing N integers. Consider any subarray [A_{L}, A_{L+1}, \ldots, A_{R}] of this subarray (where 1≤ L ≤ R ≤ N). Ther weirdness of this subarray, denoted w(L, R), is defined to be the number of indices L ≤ i ≤ R such that A_{i} equals the number of occurrence...
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) d = {} for i in range(n): if l[i] not in d: d[l[i]] = [0, i + 1] else: d[l[i]].append(i + 1) ans = 0 for k, v in d.items(): v.append(n + 1) if len(v) >= k + ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NU...
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing N integers. Consider any subarray [A_{L}, A_{L+1}, \ldots, A_{R}] of this subarray (where 1≤ L ≤ R ≤ N). Ther weirdness of this subarray, denoted w(L, R), is defined to be the number of indices L ≤ i ≤ R such that A_{i} equals the number of occurrence...
def correction(lst, n, m): lst.append(n) lst.append(None) for i in range(m, -1, -1): lst[i + 1] = lst[i] lst[0] = -1 def solve(): n = int(input()) arr = [[] for i in range(n + 1)] count = 0 for x in map(int, input().split()): if x <= n: arr[x].append(count) ...
FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NONE FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CAL...
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing N integers. Consider any subarray [A_{L}, A_{L+1}, \ldots, A_{R}] of this subarray (where 1≤ L ≤ R ≤ N). Ther weirdness of this subarray, denoted w(L, R), is defined to be the number of indices L ≤ i ≤ R such that A_{i} equals the number of occurrence...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) freq = [] d = {} for i in range(len(a)): if a[i] in d: d[a[i]] += [i] else: d[a[i]] = [-1, i] result = 0 for item in d: if len(d[item]) < item: ...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR LIST VAR ASSIGN VAR VAR VAR LIST NUMBER VAR ASSIGN...
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing N integers. Consider any subarray [A_{L}, A_{L+1}, \ldots, A_{R}] of this subarray (where 1≤ L ≤ R ≤ N). Ther weirdness of this subarray, denoted w(L, R), is defined to be the number of indices L ≤ i ≤ R such that A_{i} equals the number of occurrence...
import sys input = sys.stdin.readline def solve(a, x): m = len(a) if m == 0: return 0 ans = 0 for i in range(m - x + 1): L, R = i, i + x - 1 l = a[L] - (a[L - 1] if L else -1) r = (a[R + 1] if R + 1 < m else n) - a[R] ans += l * r return ans for _ in rang...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR N...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
t = int(input()) for _ in range(t): n, k = list(map(int, input().split())) a = input() pre = [0] * n post = [0] * n count = 0 for i in range(n): if a[i] == "1": count += 1 else: count = 0 pre[i] = count count = 0 for i in range(n - 1, -1, -...
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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): n, k = map(int, input().split()) l = list(input()) l1 = [0] * n l2 = [0] * n for i in range(1, n): if l[i - 1] == "1": l1[i] = l1[i - 1] + 1 for i in range(n - 2, -1, -1): if l[i + 1] == "1": l2[i] = l2[i + 1] + 1 ans = 0 ...
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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMB...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for z in range(int(input())): n, k = map(int, input().split()) s = input() maxl = 0 for i in range(0, n - k + 1): j = i - 1 c0 = 0 c1 = 0 while j >= 0: if s[j] == "1": c0 += 1 j -= 1 else: break ...
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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER V...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): n, k = map(int, input().split()) arr = list(input()) final_ans = 0 count = 0 for i in range(n - k + 1): for j in range(i + k, n): if arr[j] == "1": count += 1 else: break m = i - 1 while m >...
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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): a, k = map(int, input().split()) inp = [int(i) for i in input()] conright = list(inp) prev = conright[0] for i in range(1, a): if conright[i] == 1: if prev == 1: conright[i] = conright[i - 1] + 1 else: prev...
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 FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): n, k = list(map(int, input().split())) arr = str(input()) m = 0 for i in range(n - k + 1): count = k j = i - 1 while j > -1 and j < n: if arr[j] == "1": count += 1 j -= 1 else: b...
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR IF VAR VAR STRING VAR ...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def binary_search(start, end, l, p): m = (start + end) // 2 if start >= end: if l[start] < p: return start + 1 return start if l[m] > p: return binary_search(start, m - 1, l, p) elif l[m] < p: return binary_search(m + 1, end, l, p) elif l[m] == p: ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR RETURN BIN_OP VAR NUMBER RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def fun(li, k): head = [0] * len(li) tail = [0] * len(li) for i in range(1, len(li)): if li[i - 1] == "1": head[i] = head[i - 1] + 1 else: head[i] = 0 for i in range(len(li) - 2, -1, -1): if li[i + 1] == "1": tail[i] = tail[i + 1] + 1 e...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NU...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def pizza_time(a, k, p, n): return (a.index("0", p + k) if "0" in a[p + k :] else n) - ( a.rindex("0", 0, p) + 1 if "0" in a[:p] else 0 ) for i in range(int(input())): n, k = map(int, input().split()) a = input()[:n] if not "0" in a: print(len(a)) continue if not "1" in...
FUNC_DEF RETURN BIN_OP STRING VAR BIN_OP VAR VAR FUNC_CALL VAR STRING BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER VAR NUMBER NUMBER 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 FUNC_CALL VAR VAR IF STRING VAR EXPR FUNC_CAL...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def solve(arr, n, k): D = [0] * (n + 1) D[n] = 0 for i in range(n - 1, -1, -1): if arr[i] == 1: D[i] = D[i + 1] + 1 else: D[i] = 0 I = [0] * (n + 1) I[0] = 0 for i in range(1, n + 1): if arr[i - 1] == 1: I[i] = I[i - 1] + 1 else...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR N...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def cob(l, n): i = n - 1 count = 0 while i != -1 and l[i] != 0: i -= 1 count += 1 return count def coa(l, n, ll): i = n + 1 count = 0 while i != ll and l[i] != 0: i += 1 count += 1 return count tc = int(input()) for _ in range(tc): n, k = map(int, ...
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR F...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
t = int(input()) for _ in range(t): n, k = list(map(int, input().split())) string = list(map(int, input())) max_count = k for i in range(n - k + 1): count = k j = i + k while j < n and string[j] == 1: count += 1 j += 1 j = i - 1 while j >= ...
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 VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR VAR VA...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for t in range(int(input())): N = input() A = input() N = N.split(" ") k = int(N[1]) N = int(N[0]) longest = 0 max_ = k for i in range(0, N): if A[i] == "0": if i + k >= N: max_ = max(max_, longest + (N - i)) break else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): n, k = map(int, input().split()) a = input() heads = [(0) for i in range(n)] tails = [(0) for i in range(n)] heads[0] = 0 for i in range(1, n): if a[i - 1] == "1": heads[i] = heads[i - 1] + 1 else: heads[i] = 0 tails[-1] =...
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 FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): N, K = list(map(int, input().split())) S = input() left = [0] * N right = [0] * N left[0] = 1 * (S[0] == "1") right[-1] = 1 * (S[-1] == "1") for i in range(1, N): if S[i] == "1": left[i] = left[i - 1] + 1 else: left[i] = 0...
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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER STRING ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER STRING FOR VA...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): n, k = map(int, input().split()) l = [*map(int, input())] count = [0] * (n + 1) for i in range(n - 1, -1, -1): if l[i] == 1: count[i] = count[i + 1] + 1 x, y = 0, 0 for i in range(n): if l[i] == 1: x += 1 else: ...
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 LIST FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER N...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def create(lst): A = [] B = 0 for num in lst: if num == 0: B = 0 else: B += 1 A.append(B) return A T = int(input()) for _ in range(T): N, K = [int(s) for s in input().split()] days = [0] + [int(s) for s in input()] + [0] left = create(days) ...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUN...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def main(): t = int(input()) for _ in range(t): n, k = map(int, input().split()) a = list(map(int, list(input()))) i = 0 nootn = 0 nool = [0] * (n + 1) max = k while i <= n - k: if i > 0 and a[i - 1] == 1: nootn += 1 ...
FUNC_DEF 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 VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VA...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def fun(s): p = 0 m = 0 for i in range(n - 1): if s[i] == "1" and s[i + 1] == "1": p += 1 else: p = 0 m = max(m, p) return m + 1 for __ in range(int(input())): n, k = map(int, input().split()) s = input() r = 0 for i in range(n - k + 1): ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CAL...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): n, k = list(map(int, input().split())) arr = list(map(int, list(input()))) right = [0] * (n + 1) count = 0 for i in range(n - 1, -1, -1): if arr[i] == 1: count += 1 else: count = 0 right[i] = count count = 0 ans = ...
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 VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR V...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): n, k = map(int, input().split()) arr = input() pre = [0] * n suf = [0] * n i, j = 0, 1 flag = arr[0] != "0" while i < n and j < n: if not flag and arr[j] == "1": i = j flag = True elif flag and arr[j] == "0": i...
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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER STRING WHILE VAR VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR ASS...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def solve(): N, K = map(int, input().split()) S = input() eleje = [(0) for i in range(N)] vege = [(0) for i in range(N)] if S[0] == "1": vege[0] = 1 for i in range(1, N): if S[i] == "1": vege[i] = vege[i - 1] + 1 else: vege[i] = 0 if S[N - 1] =...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER A...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) st = list(input()) ans = 0 i = 0 while i <= n - k: count = k for j in range(i + k, n): if st[j] == "1": count += 1 else: break for j in range(i - 1, -1...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
t = int(input()) for i in range(t): st = input().split() N = int(st[0]) K = int(st[1]) s = input().strip() F = [0] * (N + 2) R = [0] * (N + 2) p = 0 c = 0 for k in range(1, N + 1): if s[p] == "1": c += 1 else: c = 0 F[k] = c p +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for t in range(int(input())): n, k = map(int, input().split()) s = input().strip() left = [(0) for i in range(n)] right = [(0) for i in range(n)] if s[0] == "1": left[0] = 1 for i in range(1, n): if s[i] == "1": left[i] = left[i - 1] + 1 if s[-1] == "1": r...
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING A...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
T = int(input()) while T > 0: N, K = [int(x) for x in input().split()] s = list(input()) l = [0] * N r = [0] * N temp = 0 for i in range(N): if s[i] == "1": temp += 1 l[i] = temp else: temp = 0 temp = 0 for i in range(N - 1, -1, -1): ...
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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSI...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
T = int(input()) for _ in range(0, T): N, K = map(int, input().split()) S = input() ans = -1 for i in range(0, N - K + 1): count = K j = i - 1 while -1 < j < N: if S[j] == "1": count += 1 j -= 1 else: break ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER VAR VAR IF VAR VAR STRING VAR NUM...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
num = int(input()) t = 0 while t < num: n, k = map(int, input().split()) s = str(input()) count = 0 pos = [] for i in range(n): if s[i] == "0": pos.append(i) for i in range(len(pos)): ind = pos[i] val = 0 if ind - k + 1 < 0: val += ind + 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR V...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() m = k head = [0] * n tail = [0] * n head[0] = 0 tail[-1] = 0 for i in range(1, n): if s[i - 1] == "1": head[i] = 1 + head[i - 1] for i in range(n - 2, -1, -1): if s[i + 1] == "1": ...
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 FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMB...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for t in range(int(input())): n, k = map(int, input().split()) arr = list(input()) for i in range(len(arr)): arr[i] = int(arr[i]) head = [(0) for i in range(n)] for i in range(1, n): if arr[i - 1] == 0: head[i] = 0 elif arr[i - 1] == 1: head[i] = head[...
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 FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
N_cases = int(input()) for case in range(N_cases): N, K = [int(n) for n in input().split(" ")] A = input() patches = N - K + 1 pizza_time = 0 for i in range(patches): cprev = 0 cpost = 0 c = 1 while True and i - c >= 0: if A[i - c] == "1": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER BIN_OP VAR ...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def solve(n, k, s): l = [None] * (n + 1) l[0] = 0 for i in range(n): if int(s[i]): l[i + 1] = l[i] + 1 else: l[i + 1] = 0 r = [None] * (n + 1) r[n] = 0 for i in reversed(range(n)): if int(s[i]): r[i] = r[i + 1] + 1 else: ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VA...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def solve(arr, n, k): lbs = 0 for i in range(0, n - k + 1): cnt = k for j in range(i - 1, -1, -1): if arr[j] == 1: cnt += 1 else: break for j in range(i + k, n): if arr[j] == 1: cnt += 1 else:...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VA...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
t = int(input()) for _ in range(t): n, k = (int(x) for x in input().split()) as_ = [int(x) for x in input()] assert len(as_) == n left_streak = [0] ct_left = 0 for ii in as_[: n - k]: ct_left += 1 if ii == 0: ct_left = 0 left_streak.append(ct_left) right_s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
t = int(input()) for i in range(0, t): n, k = map(int, input().split()) arr = input() x = 0 y = 0 left = [] right = [0] * n for i in range(0, n): left.append(x) if arr[i] == "1": x = x + 1 else: x = 0 for i in range(n - 1, -1, -1): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): n, k = map(int, input().split()) a = list(input()) l = [0] * (n + 2) r = [0] * (n + 2) result = 0 for i in range(n): if a[i] == "1": l[i + 1] = l[i] + 1 for i in range(n - 1, -1, -1): if a[i] == "1": r[i + 1] = r[i + 2] + ...
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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_O...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
t = int(input()) for i in range(t): n, k = [int(x) for x in input().split()] arr = [int(x) for x in input()] index = k - 1 start = 0 res = 0 while index < n: tmp_res = k tmp_index = index while tmp_index + 1 < n and arr[tmp_index + 1] == 1: tmp_res += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): n, k = (int(x) for x in input().split()) a = input() hidari = [0] * n migi = [0] * n for i in range(n - k + 1): loli = i i -= 1 num = 0 while i >= 0: if a[i] == "1": num += 1 i -= 1 ...
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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF V...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def pizzatime(s, a, k): cont1, m_time = 0, 0 for i in range(len(s)): if s[i] == "1": cont1 += 1 else: try: m_time = max(m_time, cont1 + k + a[i + k]) except: m_time = max(m_time, cont1 + min(k, len(s) - i)) cont1 = 0...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETUR...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def solve(): n, k = map(int, input().split()) a = input() r = [0] * (n + 1) l = [0] * n for i in range(n): if a[i] == "1": l[i] = 1 if i > 0: l[i] += l[i - 1] j = n - i - 1 if a[j] == "1": r[j] = 1 + r[j + 1] mx = 0 ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMB...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): n, k = map(int, input().split()) a = input() left = [0] * n right = [0] * n if a[0] == "0": co = 0 else: co = 1 for i in range(1, n): left[i] = co if a[i] == "0": co = 0 else: co += 1 if a[n - 1...
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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR ...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): N, K = list(map(int, input().split())) A = ["0"] A.extend(input()) A.extend(["0"]) B = [0] * (N + 2) C = B.copy() for i, j in enumerate(A[1:], start=1): if j == "1": B[i] = B[i - 1] + 1 A.reverse() for i, j in enumerate(A[1:], start=1...
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 LIST STRING EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER NU...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
def pizzaOrBroc(n, k, a): L = [0] * n R = [0] * n maxpizza = 0 for i in range(1, n): if int(a[i - 1]) == 1: L[i] = L[i - 1] + 1 for i in range(n - 2, -1, -1): if int(a[i + 1]) == 1: R[i] = R[i + 1] + 1 for i in range(0, n - k + 1): maxpizza = max(m...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NU...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
te = int(input()) while te > 0: te -= 1 n, k = list(map(int, input().split())) dishes = list(input()) heads = [0] * n tails = [0] * n for i in range(1, n): if dishes[i - 1] == "1": heads[i] = heads[i - 1] + 1 else: heads[i] = 0 j = n - 2 while j >=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR...
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day. Chefu...
for _ in range(int(input())): n, k = map(int, input().split()) l = input() head, tail = [0] * n, [0] * n for i in range(1, n): if l[i - 1] == "0": head[i] = 0 else: head[i] += head[i - 1] + 1 temp = l[::-1] for i in range(1, n): if temp[i - 1] == "...
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 FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUM...
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not...
class Solution: def maxArea(self, height): area = (len(height) - 1) * min([height[0], height[-1]]) left_idx = 0 right_idx = len(height) - 1 while left_idx < right_idx: if height[left_idx] < height[right_idx]: start = left_idx + 1 while sta...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_C...
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not...
class Solution: def maxArea(self, items): max_area = 0 lo = 0 hi = len(items) - 1 while lo < hi: height_a = items[lo] height_b = items[hi] width = hi - lo height = min(height_a, height_b) area = height * width i...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not...
class Solution: def maxArea(self, height): left = 0 right = len(height) - 1 if height[left] > height[right]: minH = height[right] minIndex = right else: minH = height[left] minIndex = left area = (right - left) * minH m...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR WHILE VAR VAR VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VA...
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not...
class Solution: def get_ans(self, l, r): return (r - l) * min(self.__height[l], self.__height[r]) def rmove(self, l): for i in range(l + 1, len(self.__height)): if self.__height[i] > self.__height[l]: return i return 10000000 def lmove(self, r): ...
CLASS_DEF FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ...
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not...
class Solution: def maxArea(self, height): left, right = 0, len(height) - 1 area = 0 while left < right: if height[left] <= height[right]: h = height[left] tmp = (right - left) * h left += 1 else: h = he...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not...
class Solution: def maxArea(self, height): h = height most = 0 i = 0 j = len(h) - 1 while i < j: most = max(most, (j - i) * min(h[i], h[j])) if h[i] < h[j]: i += 1 else: j -= 1 return most
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not...
class Solution: def maxArea(self, height): if len(height) < 2: return False if len(height) == 2: return min(height[0], height[1]) current_highest = 0 i, j = 0, len(height) - 1 while i < j: left = height[i] right = height[j] ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP...
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not...
class Solution: def maxArea(self, height): left = 0 right = len(height) - 1 max_area = 0 while left < right: area = min(height[left], height[right]) * (right - left) if area > max_area: max_area = area if height[left] < height[righ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not...
class Solution: def maxArea(self, height): if height == []: return 0 l = len(height) p1 = 0 p2 = l - 1 area = 0 while p1 < p2: if height[p1] <= height[p2]: area = max(area, height[p1] * (p2 - p1)) p1 += 1 ...
CLASS_DEF FUNC_DEF IF VAR LIST RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN V...
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not...
class Solution: def maxArea(self, height): left_index = 0 right_index = len(height) - 1 water = 0 while True: if left_index >= right_index: break left_height = height[left_index] right_height = height[right_index] water...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR