description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() i, j = 0, len(arr) - 1 res = arr[i] + arr[j] while i < j: cur = arr[i] + arr[j] if abs(cur) == abs(res): res = max(res, cur) elif abs(cur) < abs(res): res ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NU...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() i, j = 0, n - 1 r = 1000001 while i < j: t = arr[i] + arr[j] if t > 0: j -= 1 else: i += 1 if abs(t) < abs(r): r = t ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, numbers, list_size): if list_size < 2: return numbers.sort() left, right = 0, list_size - 1 sum_closest_to_zero = float("inf") while left < right: curr_sum = numbers[left] + numbers[right] if abs(cur...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER V...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() i, j = 0, n - 1 negative_sum, positive_sum = float("-inf"), float("inf") while i < j: s = arr[i] + arr[j] if s < 0: i += 1 negative_sum = max(negative_sum, s) ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN ...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
import sys class Solution: def closestToZero(self, arr, n): arr = sorted(arr) min_sum = sys.maxsize abs_min_sum = sys.maxsize l = 0 r = len(arr) - 1 while l < r: sum = arr[l] + arr[r] abs_sum = abs(sum) if abs_sum < abs_min_sum: ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() l, r = 0, n - 1 res = arr[l] + arr[r] if res == 0: return 0 elif res > 0: r -= 1 else: l += 1 while l < r: temp = arr[l] + arr[r] if abs(te...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASS...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() positive_closest = float("inf") negative_closest = float("-inf") l, r = 0, n - 1 while l < r: if arr[l] + arr[r] > 0: positive_closest = min(arr[l] + arr[r], positive_closest) ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF FU...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() l, r = 0, n - 1 max_close = 10**20 while l < r: if abs(max_close) == abs(arr[l] + arr[r]): max_close = max(max_close, arr[l] + arr[r]) elif abs(max_close) > abs(arr[l] + arr[r]): ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VA...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() if arr[0] <= 0 and arr[-1] <= 0: return arr[-1] + arr[-2] if arr[0] >= 0 and arr[-1] > 0: return arr[0] + arr[1] left, right = 0, len(arr) - 1 min_diff = None while left < right: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NONE WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() left = 0 right = n - 1 maxSum = float("inf") absMaxSum = abs(maxSum) while left < right: temp = arr[left] + arr[right] if temp == 0: return 0 if abs(temp) ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSI...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() s = 1000000000000 l = 0 r = n - 1 while l < r: if abs(arr[l] + arr[r]) == abs(s) and arr[l] + arr[r] > s: s = arr[l] + arr[r] elif abs(arr[l] + arr[r]) < abs(s): ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() start_indx = 0 end_indx = len(arr) - 1 sum_track = float("inf") while start_indx < end_indx: if ( abs(arr[start_indx] + arr[end_indx]) < abs(sum_track) or abs(arr[start_in...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR I...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, a, n): a.sort() i = 0 j = n - 1 mini = 1000000000 while i < j: if abs(mini) > abs(a[j] + a[i]): mini = a[j] + a[i] if abs(mini) == abs(a[j] + a[i]): mini = max(a[j] + a[i], mini) ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR I...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() if n < 2: return 2 * arr[0] elif arr[0] > 0: return arr[0] + arr[1] elif arr[n - 1] < 0: return arr[n - 1] + arr[n - 2] else: i = 0 j = n - 1 s...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR IF VAR NUMBER RETURN BIN_OP NUMBER VAR NUMBER IF VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE ...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): ans = 100000000.0 arr.sort() start = 0 end = n - 1 while start < end: total = arr[start] + arr[end] if total == 0: return total if abs(total) == abs(ans): if ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER RETURN VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMB...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() start, end = 0, len(arr) - 1 result = float("inf") while start < end: diff = arr[start] + arr[end] if diff == 0: return 0 if abs(diff) < abs(result): resul...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VA...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def abs_val(self, n): return -1 * n if n < 0 else n def closestToZero(self, arr, n): arr.sort() i, j = 0, n - 1 m = arr[0] + arr[n - 1] while i < j: c = arr[i] + arr[j] if c == 0: return 0 if c < 0: ...
CLASS_DEF FUNC_DEF RETURN VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): i, j = 0, n - 1 ans = float("inf") arr.sort() while i < j: cur = arr[i] + arr[j] if abs(cur) <= abs(ans): if abs(cur) == abs(ans): ans = max(ans, cur) else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMB...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): ans = 999999 arr.sort() l = 0 r = n - 1 while l < r: val = arr[l] + arr[r] if abs(val) < abs(ans): ans = val if abs(val) == abs(ans): ans = max(ans, val) ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER V...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
import sys class Solution: def closestToZero(self, arr, n): arr.sort() if arr[0] >= 0: return arr[0] + arr[1] elif arr[n - 1] <= 0: return arr[n - 1] + arr[n - 2] else: i = 0 j = n - 1 min = sys.maxsize while ...
IMPORT CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR V...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() diff = arr[0] + arr[n - 1] l = 0 r = n - 1 while l < r: s = arr[l] + arr[r] if s == 0: return 0 if s > 0: r -= 1 if s < 0: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF F...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() diff = 10**6 i = 0 j = n - 1 while i < j: sum = arr[i] + arr[j] if abs(diff) == abs(sum) and sum > diff: diff = sum elif abs(diff) > abs(sum): diff...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR ...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() maxv = 10**6 sumv = 0 i = 0 j = n - 1 while i < j: csum = arr[i] + arr[j] if maxv > abs(csum) or maxv == abs(csum) and csum > sumv: maxv = abs(csum) su...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER RE...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): ans = 10000000 arr.sort() if arr[0] > 0: return arr[0] + arr[1] if arr[-1] < 0: return arr[-1] + arr[-2] i = 0 while arr[i] < 0: i += 1 j = i - 1 if i + 1 < n: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBE...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): arr.sort() maxSum = float("inf") left = 0 right = n - 1 while left < right: tempSum = arr[left] + arr[right] abSum = abs(0 - tempSum) if abSum < abs(maxSum): maxSum = tempSum...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def binary(self, arr, l, r, target): mid = -1 while l <= r: mid = int((l + r) / 2) if arr[mid] == target: return mid elif arr[mid] > target: r = mid - 1 else: l = mid + 1 return m...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, a, n): a.sort() ans = 99999 cneg = 0 cpos = 0 czero = 0 for i in range(n): if a[i] < 0: cneg += 1 elif a[i] > 0: cpos += 1 else: czero += 1 ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR ...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def merge(self, arr, l, mid, h): i = l j = mid + 1 temp = [] while i <= mid and j <= h: if arr[i] <= arr[j]: temp.append(arr[i]) i += 1 else: temp.append(arr[j]) j += 1 wh...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR V...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
class Solution: def closestToZero(self, arr, n): if n == 1: return arr[0] else: arr = sorted(arr) k = float("inf") i = 0 j = n - 1 while i < j: su = arr[i] + arr[j] if su == 0: ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR FUNC_...
Given an integer array of N elements. You need to find the maximum sum of two elements such that sum is closest to zero. Example 1: Input: N = 3 arr[] = {-8 -66 -60} Output: -68 Explanation: Sum of two elements closest to zero is -68 using numbers -60 and -8. Example 2: Input: N = 6 arr[] = {-21 -67 -37 -18 4 -65} Ou...
import sys def get_two_largest_elems(arr): if arr[0] > arr[1]: largest = arr[0] larger = arr[1] else: largest = arr[1] larger = arr[0] for i in range(2, len(arr)): if arr[i] > largest: larger = largest largest = arr[i] elif arr[i] > l...
IMPORT FUNC_DEF IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER ASSIGN VAR V...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def get_arg_list(self, s1: List): args = [] while s1 and isinstance(s1[-1], bool): args.append(s1.pop()) return args def boolEval(self, symbol, s1: List): if symbol == "!": return not s1[0] elif symbol == "&": return a...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF VAR IF VAR STRING RETURN VAR NUMBER IF VAR STRING RETURN FUNC_CALL VAR VAR IF VAR STRING RETURN FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, expression: str) -> bool: ops = {"!", "&", "|"} def parse(start): if expression[start] == "f": return False, start + 1 if expression[start] == "t": return True, start + 1 if expression[start...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR STRING STRING STRING FUNC_DEF IF VAR VAR STRING RETURN NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING RETURN NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF ...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr1(self, expression: str) -> bool: def helper(queue): res = True while queue: c = queue.pop() print("c = {0}".format(c)) if c in {"t", "f"}: return True if c == "t" else False ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR STRING STRING RETURN VAR STRING NUMBER NUMBER IF VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR ASSIGN VAR VAR STRING NUMBER NUMBER ASSIGN VAR VAR...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, expression: str) -> bool: bool_stack = [] expr_stack = [] curr = [] for char in expression: if char == ",": continue elif char == "(": expr_stack.append(curr) curr = [] ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR STRING IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR STRING EXPR FUNC_CALL VAR VAR STRING NUMBER NUMBER IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR LIST IF VAR STRING AS...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, expression: str) -> bool: def parse(e: str, left, right): if right - left == 1: return e[left] == "t" res = e[left] == "&" level, start = 0, left + 2 for i in range(left + 2, right): if ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF VAR IF BIN_OP VAR VAR NUMBER RETURN VAR VAR STRING ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR LIST STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VA...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, expression: str) -> bool: return eval( expression.translate( str.maketrans({"t": "1", "f": "0", "!": "not", "|": "or_", "&": "and_"}) ), {"or_": lambda *a: any(a), "and_": lambda *a: all(a)}, )
CLASS_DEF FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING DICT STRING STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, expression: str) -> bool: exp = collections.deque(expression) def or_opt(exp): exp.popleft() ret = False while exp: ret |= exp_opt(exp) if exp.popleft() == ")": return re...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN V...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, expression: str) -> bool: expression = list(expression) table = {"|": "or", "&": "and", "t": "True", "f": "False"} logic = [] idx, par = 0, True while idx < len(expression): if expression[idx] in ["&", "|"]: ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR LIST STRING STRING EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR STRING EXPR FUNC_C...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, expression: str) -> bool: stack = [] for c in expression: if c not in [",", ")"]: stack.append(True if c == "t" else False if c == "f" else c) elif c == ")": seen = set() while stack[-1] ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST FOR VAR VAR IF VAR LIST STRING STRING EXPR FUNC_CALL VAR VAR STRING NUMBER VAR STRING NUMBER VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING FUNC_CALL VAR ...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, expression: str) -> bool: if expression == "f": return False if expression == "t": return True if expression[0] == "!": return not self.parseBoolExpr(expression[2:-1]) if expression[0] == "|": cu...
CLASS_DEF FUNC_DEF VAR IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR NUMBER STRING RETURN FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NU...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, expression: str) -> bool: def split_into_list(expression): res = [] depth = 0 ss = "" for e in expression: if depth == 0 and e == ",": res.append(ss) ss = "" ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR NUM...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, expression: str) -> bool: if len(expression) == 1: return expression == "t" op = expression[0] boolean_list = [] level = 0 start = 2 for i in range(2, len(expression) - 1): ch = expression[i] ...
CLASS_DEF FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUN...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, expression: str) -> bool: stack = [] for ch in expression: if ch == ",": continue if ch != ")": stack.append(ch) else: temp = "" while stack[-1] != "(": ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER STRING VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR STRING NUMBER STRING STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR STRING NUMBER STRIN...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, ex: str) -> bool: def recur(i): if ex[i] in ("t", "f"): return True if ex[i] == "t" else False, i + 1 op = ex[i] i = i + 2 stack = [] while ex[i] != ")": if ex[i] == ",": ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR VAR STRING STRING RETURN VAR VAR STRING NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR STRING IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING RETURN FUNC_CALL VAR VAR ...
Return the result of evaluating a given boolean expression, represented as a string. An expression can either be: "t", evaluating to True; "f", evaluating to False; "!(expr)", evaluating to the logical NOT of the inner expression expr; "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions ...
class Solution: def parseBoolExpr(self, expression: str) -> bool: expression = list(expression) def replace_or(start: int): braket = 1 for i in range(start, len(expression)): if expression[i] == "(": braket += 1 elif expre...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR STRING ASSIGN VAR VAR STRING IF VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR STRING EXPR...
Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they...
try: for t in range(int(input())): n = int(input()) count = 0 A = list(map(int, input().split())) B = [0] for i in range(n): pos = B.index(A[i]) count += min(pos, len(B) - pos - 1) B.insert(pos + 1, i + 1) print(count) except: p...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER...
Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they...
test_case = int(input()) while test_case > 0: steps = 0 test_case -= 1 n = int(input()) array = list(map(int, input().split())) line = [] for i in range(len(array)): if array[i] == 0: line.insert(0, i + 1) else: location = line.index(array[i]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR ...
Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they...
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) p = [] c = 0 for j in range(1, n + 1): if a[j - 1] == 0: p.insert(0, j) else: l = p.index(a[j - 1]) + 1 if l <= len(p) / 2: c += l ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR ASSIGN...
Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they...
for _ in range(int(input())): n = int(input()) lst = list(map(int, input().split())) st = 0 l = [1] for i in range(1, n): if lst[i] == 0: l.insert(0, i + 1) elif lst[i] in l: inx = l.index(lst[i]) if inx + 1 > len(l) - inx - 1: st +...
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 NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR FU...
Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they...
def getResult(n, arr): a = [0] c = 0 for i in range(n): p = a.index(arr[i]) c += min(p, len(a) - 1 - p) a.insert(p + 1, i + 1) return c t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) print(getResult(n, arr))
FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC...
Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they...
T = int(input()) for _ in range(T): n = int(input()) L = list(map(int, input().split())) M = [] ans = 0 for i in range(n): if L[i] == 0: M.insert(0, i + 1) else: a = L[i] b = M.index(a) m = len(M) ans += min(b + 1, m - b - 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN V...
Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they...
T = int(input()) while T: n = int(input()) li = [int(x) for x in input().split()] order = [] steps = 0 for i in range(len(li)): if li[i] == 0: order.insert(li[i], i + 1) else: len1 = len(order[: order.index(li[i])]) + 1 len2 = len(order[order.index...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FU...
Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they...
t = int(input()) for _ in range(t): n = int(input()) b = list(map(int, input().split(" "))) count = 0 a = [] for i in range(n): c = b[i] if c == 0: if len(a) == 0: a.append(i + 1) else: a.insert(0, i + 1) elif c in a: ...
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 STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BI...
Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they...
for tests in range(int(input())): N = int(input()) A = [int(i) for i in input().split()] S = [] i = 0 moves = 0 for j in range(N): i += 1 new = A[j] if new == 0: S = [i] + S else: for k in range(len(S)): if new == S[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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR FUNC_CALL VAR...
Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they...
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) s = [] c = 0 s.append(1) for k in range(1, n): if a[k] == 0: s.insert(0, k + 1) else: ind = s.index(a[k]) s.insert(ind + 1, k + 1) if ind + 1 <...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR N...
Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they...
def solve(arr, n): line = [1] total = 0 for i in range(1, n): element = arr[i] if element == 0: line.insert(0, i + 1) else: index = line.index(arr[i]) total += min(index + 1, len(line) - index - 1) line.insert(index + 1, i + 1) retu...
FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR ...
Read problems statements in Mandarin Chinese and Russian. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they...
t = int(input().strip()) for _ in range(t): n = int(input().strip()) a = list(map(int, input().strip().split())) b = [0] * 2 * n si = n + 1 ei = n + 1 res = 0 for i, ai in enumerate(a): if ai == 0: si -= 1 b[si] = i + 1 else: idx = b.index(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NU...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: R, C = len(grid), len(grid[0]) def traverse(r, c): if not (0 <= r < R and 0 <= c < C): return 0 if not grid[r][c]: return 0 cur = grid[r][c] grid[...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF NUMBER VAR VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: rrange = range(len(grid)) crange = range(len(grid[0])) max_sum = 0 def helper(row, col, running_sum=0): nonlocal max_sum if not (row in rrange and col in crange and grid[row][col] > 0): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] self.maxgold = 0 def isValid(i, j): if 0 <= i < len(grid) and 0 <= j < len(grid[0]) and grid[i][j] != 0: return True else: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: iMax = len(grid) jMax = len(grid[0]) di = [0, 1, 0, -1] dj = [1, 0, -1, 0] numOfGold = 0 goldNumDict = {} for i in range(iMax): for j in range(jMax): if grid[i...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR N...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: gold = 0 def dfs(self, grid, i, j, current): if i < 0 or j < 0 or i >= len(grid) or j >= len(grid[0]) or grid[i][j] == 0: return current += grid[i][j] temp = grid[i][j] grid[i][j] = 0 self.dfs(grid, i, j - 1, current) self.dfs(grid, i,...
CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: m, n = len(grid), len(grid[0]) visited = [([False] * n) for _ in range(m)] self.ans = 0 def dfs(i, j): if i < 0 or i >= m or j < 0 or j >= n or visited[i][j] or grid[i][j] == 0: retu...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FUNC_C...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: def sorround(curr): posts = [[1, 0], [0, 1], [-1, 0], [0, -1]] for i in posts: ii = i[0] + curr[0] jj = i[1] + curr[1] if ( ii < len(grid) ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER E...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: if not grid or not grid[0]: return 0 self.max_gold = 0 rows = len(grid) cols = len(grid[0]) for row in range(rows): for col in range(cols): self.dfs(grid, row, col...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NU...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: allGod = -1 def getMaximumGold(self, grid: List[List[int]]) -> int: def helper(maxgold, i, j): if 0 <= i < len(grid) and 0 <= j < len(grid[0]) and grid[i][j] > 0: temp = grid[i][j] self.allGod = max(self.allGod, maxgold + temp) ...
CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF VAR VAR VAR FUNC_DEF IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def __init__(self): self.moves = [(-1, 0), (1, 0), (0, -1), (0, 1)] def dfs(self, r, c): if r < 0 or r == self.m or c < 0 or c == self.n or self.grid[r][c] == 0: return 0 original = self.grid[r][c] self.grid[r][c] = 0 maxGold = max(self.dfs(r...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR V...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: M, N = len(grid), len(grid[0]) self.res = 0 def dfs(grid, i, j, cur): nbr = [(i, j + 1), (i, j - 1), (i - 1, j), (i + 1, j)] temp = grid[i][j] self.res = max(self.res, cur + temp) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR LIST VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR VAR VAR IF NUMBER VAR VAR...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: m = len(grid) n = len(grid[0]) grid_visited = [[(0) for i in range(n)] for i in range(m)] max_gold = 0 for i in range(m): for j in range(n): if grid[i][j] != 0: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: ans = 0 for i in range(len(grid)): for j in range(len(grid[0])): if grid[i][j] != 0: ans = max(ans, self.findGold(grid, i, j)) return ans def findGold(self, grid, row...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUM...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: nrow, ncol = len(grid), len(grid[0]) max_len = 0 def dfs(trajectory, r, c): nonlocal max_len count_neighbor = 0 for dr, dc in [[0, 1], [0, -1], [1, 0], [-1, 0]]: nr, ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR NUM...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: self.ans = 0 def dfs(grid, i, j, res): res = res + grid[i][j] tmp = grid[i][j] grid[i][j] = 0 for r, c in ((i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)): if 0 <...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: R, C = len(grid), len(grid[0]) O = [] def check(r, c, Z): if -1 < r < R and -1 < c < C and (r, c) not in Z: return True return False def bt(r, c, res, Z): if...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: n = len(grid) m = len(grid[0]) ones = set([]) start = [] answer = 0 for i in range(n): for j in range(m): if grid[i][j] != 0: ones.add((i, j)) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR FUNC_CALL VAR L...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid): path = [] total = 0 self.rLen = len(grid) self.cLen = len(grid[0]) for i in range(self.rLen): for j in range(self.cLen): if grid[i][j] != 0: retTotal, retPath = self.dfs(grid, i, ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR VAR ASS...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: m = len(grid) - 1 n = len(grid[0]) - 1 def dfs(i, j, visited): val = 0 visited[i][j] = True for co in ((-1, 0), (1, 0), (0, -1), (0, 1)): x = i + co[0] ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF NUMBER VAR...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: nR = len(grid) nC = len(grid[0]) vis = [[(0) for i in range(nC)] for j in range(nR)] steps = [[0, -1], [-1, 0], [1, 0], [0, 1]] _max = 0 for r in range(nR): for c in range(nC): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
DIR = (-1, 0), (1, 0), (0, -1), (0, 1) class Solution: def getMaximumGold(self, grid): res = 0 m, n = len(grid), len(grid[0]) for x in range(m): for y in range(n): if grid[x][y] > 0: res = max(res, self.dfs(grid, x, y, {(x, y)})) ret...
ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF A...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: visited = set() m, n = len(grid), len(grid[0]) def isValid(x, y): return 0 <= x < m and 0 <= y < n dirs = [(-1, 0), (1, 0), (0, 1), (0, -1)] def dfs(x, y): if grid[x][y] == 0: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBE...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: m, n = len(grid), len(grid[0]) l = [(1, 0), (-1, 0), (0, 1), (0, -1)] vis = set() res = [0] z = -float("inf") def fn(a, b): z = -float("inf") for c, d in l: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: def dfs(i, j, cur): nonlocal mx cur += grid[i][j] mx = max(mx, cur) path.add((i, j)) for I, J in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]: if ( ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: max_gold = 0 rows = len(grid) cols = len(grid[0]) for row in range(rows): for col in range(cols): if grid[row][col] > 0: max_gold = max(max_gold, self.get_gold(gri...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FU...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: maxy = [0] print(grid) def gold(grid, summ, i, j): if ( i <= len(grid) - 1 and i > -1 and j <= len(grid[0]) - 1 and j > -1 and...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR EX...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, g: List[List[int]]) -> int: def dfs(i, j, visited): if not ( 0 <= i < len(g) and 0 <= j < len(g[0]) and g[i][j] != 0 and (i, j) not in visited ): return 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR LIST LIST NUMBER NU...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: nrow, ncol = len(grid), len(grid[0]) def getMaximumGold_helper(grid, i, j): if i >= nrow or i < 0 or j >= ncol or j < 0: return 0 if grid[i][j] == 0: return 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_C...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: if not grid: return 0 def dfs(grid, i, j): if i < 0 or i >= len(grid) or j < 0 or j >= len(grid[0]) or grid[i][j] == 0: return 0 res = grid[i][j] grid[i][j] = 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def dfs(self, pos, sum): if ( pos in self.visit or pos[0] < 0 or pos[0] >= self.M or pos[1] < 0 or pos[1] >= self.N or not self.grid[pos[0]][pos[1]] ): return self.visit.add(pos) sum ...
CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BI...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: m, n = len(grid), len(grid[0]) def collect(i, j): if not (0 <= i < m and 0 <= j < n and grid[i][j]): return 0 gold, grid[i][j] = grid[i][j], 0 choices = [ col...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMB...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def __init__(self): self.max_gold = float("-Inf") def getMaximumGold(self, grid: List[List[int]]) -> int: if not grid: return 0 def dfs(current, i, j): if i < 0 or i >= len(grid) or j < 0 or j >= len(grid[0]) or grid[i][j] == 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: def goDfsGo(row, col): ret_max = 0 temp_val = grid[row][col] grid[row][col] = False if ( row + 1 < len(grid) and grid[row + 1][col] != False ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: self.dirs = (1, 0), (0, 1), (-1, 0), (0, -1) self.nrow = len(grid) self.ncol = len(grid[0]) max_gold = 0 for i in range(self.nrow): for j in range(self.ncol): if grid[i][j] !=...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR IF VAR VAR ASS...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def dfs(self, grid, i, j, m, n): tmp = 0 if grid[i][j] == 0 or self.visited[i][j] == 1: return 0 self.visited[i][j] = 1 for x, y in self.direction: x = i + x y = j + y if ( x >= 0 and y >...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: di = [(-1, 0), (0, 1), (1, 0), (0, -1)] ans = 0 for i in range(len(grid)): for j in range(len(grid[0])): if grid[i][j] != 0: v = self.bfs(grid, i, j, di) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR F...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: def q(g, i, j, t, s, vis): if ( i >= len(g) or j >= len(g[0]) or i < 0 or j < 0 or g[i][j] == 0 or vis[i][j] == 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUM...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: def neighbor(r, c): for dr, dc in ((r + 1, c), (r - 1, c), (r, c + 1), (r, c - 1)): if 0 <= dr < nrow and 0 <= dc < ncol: yield dr, dc self.cur_gold = 0 self.max_gold = ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF FOR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF NUMBER VAR VAR NUMBER VAR VAR EXPR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: ROWS = len(grid) COLS = len(grid[0]) self.mx = 0 seen = set() def dfs(r, c): if ( not 0 <= r < ROWS or not 0 <= c < COLS or (r, c) in seen ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_O...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: m = len(grid) n = len(grid[0]) def dfs(x, y, visited, res): maxi = res[:] for i, j in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]: if ( i >= 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: if not grid: return 0 res = 0 M = len(grid) N = len(grid[0]) cords = [[0, 1], [0, -1], [-1, 0], [1, 0]] def recur(x, y): if x < 0 or x >= M or y < 0 or y >= N or grid[x][...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: nrow, ncol = len(grid), len(grid[0]) possible_starts = [ (i, j) for i in range(nrow) for j in range(ncol) if grid[i][j] != 0 ] max_gold = 0 for start in possible_starts: path_stac...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR ASSIGN VAR NUMBER ...
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cell you will collect all the gold in that cell. From your position you can wa...
class Solution: def getMaximumGold(self, grid: List[List[int]]) -> int: if not grid: return 0 self.answer = 0 def dfs(i, j): if i < 0 or i >= len(grid): return 0 if j < 0 or j >= len(grid[0]): return 0 if grid[...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR...