description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: sub = dict() for i in range(len(s) - minSize + 1): d = dict() for k in range(i, i + minSize): if s[k] in d: d[s[k]] += 1 else: ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: toSearch = {} for size in range(minSize, maxSize + 1): for i in range(len(s) - size + 1): S = s[i : i + size] letters = len(set(S)) if letters <...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VA...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: for i in range(minSize, maxSize + 1): max_freq = self.maxFreqSetSize(s, maxLetters, i) if max_freq > 0: return max_freq return 0 def maxFreqSetSize(self, s, ma...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FU...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: feq = collections.Counter() N = len(s) for i in range(N): letters = set([c for c in s[i : i + minSize - 1]]) for j in range(minSize, maxSize + 1): k = i + j...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL ...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: maxi = 0 for index in range(minSize, maxSize + 1): result = self.getAllSubstringsWithRules(s, maxLetters, index) if result > maxi: maxi = result return maxi...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMB...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxy: int, m: int, mm: int) -> int: i, j = 0, 0 count = collections.Counter() count[s[0]] += 1 ans = collections.Counter() u, n = 1, len(s) key = s[0] while True: if u <= maxy and m <= i - j + 1 <= mm: ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER WHILE NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VA...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: cache = collections.defaultdict(int) for i in range(len(s) + 1 - minSize): if len(set(s[i : i + minSize])) <= maxLetters: cache[s[i : i + minSize]] += 1 res = 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN V...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: n = len(s) results = 0 for l in range(minSize, maxSize + 1): if l <= n: maps = {} for i in range(n - l + 1): subs = s[i : i + l] ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VA...
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: candidates = collections.Counter() for i in range(len(s) - minSize + 1): if len(set(list(s[i : i + minSize]))) <= maxLetters: candidates[s[i : i + minSize]] += 1 return...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSiz...
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: mymap = {} for i in range(len(s) - minSize + 1): if len(set(list(s[i : i + minSize]))) <= maxLetters: print(s[i : i + minSize]) if s[i : i + minSize] in mymap: ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: max_q, min_q = [], [] ans = 1 l = 0 for i, num in enumerate(nums): while len(max_q) and nums[max_q[-1]] < num: max_q.pop(-1) while len(min_q) and nums[min_q[-1]] > ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE BIN_OP V...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: asc, desc = deque(), deque() left = 0 longest = 0 for i, n in enumerate(nums): if not asc: asc.append([n, i]) else: while asc and asc[-1][0] > n: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR LIST VAR VAR WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR EXPR FUNC_CALL VAR LIST VAR VAR WHILE VAR VAR NUMBE...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if len(nums) == 1: return 1 maxL = 0 beg = 0 minQueue, maxQueue = collections.deque([]), collections.deque([]) end = beg while end < len(nums): while len(minQueue) ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR LIST FUNC_CALL VAR LIST ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if not nums: return 0 if len(nums) == 1: return 1 l = 0 r = 1 curmax = nums[0] curmin = nums[0] maxlen = 1 while l <= r and r < len(nums): ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: decStack = collections.deque() incStack = collections.deque() ans = 0 l = 0 for r, n in enumerate(nums): while decStack and decStack[-1][0] <= n: decStack.pop() ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: maximums = [(-nums[0], 0)] minimums = [(nums[0], 0)] left = 0 if len(nums) > 1 else 1 right = 1 while right < len(nums): heapq.heappush(maximums, (-nums[right], right)) hea...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR NUMBER NUMBER VAR EXPR FUNC_CALL V...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class minMonotonicQueue(object): def __init__(self): self.queue = collections.deque([]) def push(self, num, idx): while len(self.queue) != 0 and self.queue[-1][0] > num: self.queue.pop() self.queue.append((num, idx)) def pop(self, idx): if self.queue[0][1] == i...
CLASS_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST FUNC_DEF WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR CLASS_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST FUNC_DEF WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER NU...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: low = None curr_max = None curr_low = -1 max_len = 0 min_queue = [] max_queue = [] for i in range(len(nums)): curr_num = nums[i] self.queue_add_max(max_queu...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: l = 0 thing = 0 curMin = 9999999 curMax = -9999999 numMap = {} i = 0 while i < len(nums): if nums[i] not in numMap: numMap[nums[i]] = 0 numM...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class MinMaxList(object): def __init__(self): self._container = {} self._max = -6665677 self._min = 6665677 def min_val(self) -> int: return self._min def max_val(self) -> int: return self._max def append_val(self, val: int): if val in self._container:...
CLASS_DEF VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF RETURN VAR VAR FUNC_DEF RETURN VAR VAR FUNC_DEF VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_DEF VAR IF VAR VAR IF VAR VAR NUMBER ASSIGN...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if len(nums) == 0: return 0 max_q = MonoQueue(False) min_q = MonoQueue(True) l, r = 0, 0 max_q.push(nums[0]) min_q.push(nums[0]) def in_limit(): if max_q.i...
CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF FUNC_CALL VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: min_deque = collections.deque() max_deque = collections.deque() l = 0 ans = 0 for r, num in enumerate(nums): while min_deque and nums[min_deque[-1]] >= num: min_deque.p...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR WHILE VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: i, j = 0, 0 nums.append(float("inf")) qmin = collections.deque() qmax = collections.deque() qmin.append(0) qmax.append(0) ans = 0 while j < len(nums) - 1: while...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR N...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: max_deque = collections.deque() min_deque = collections.deque() n = len(nums) l = 0 res = 0 for r in range(n): self.push_max_deque(max_deque, nums, r) self.push_min...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR IF...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: answer = 1 counts = {nums[0]: 1} subarray = deque([nums[0]]) max_val = nums[0] min_val = nums[0] for i in range(1, len(nums)): counts[nums[i]] = counts.get(nums[i], 0) + 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if len(nums) == 0: return 0 if len(nums) == 1: return 1 maxStack = [] minStack = [] result = 1 leftPos = 0 for i in range(0, len(nums)): while m...
CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if not nums or len(nums) == 1: return len(nums) n = len(nums) i = 0 j = 1 res = 1 min_in_window = nums[0] max_in_window = nums[0] while j < n: max_i...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_C...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: result = 0 min_deque = [] max_deque = [] start = 0 for index, value in enumerate(nums): while len(min_deque) and value < min_deque[-1]: min_deque.pop() whil...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER VAR N...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: currMax = nums[0] currMin = nums[0] maxSize = 1 beg = 0 end = 0 while end < len(nums): currMax = max(currMax, nums[end]) currMin = min(currMin, nums[end]) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR NUMBE...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: n = len(nums) res = 0 left, right = 0, 0 minimum, maximum = [], [] while right < n: heapq.heappush(minimum, (nums[right], right)) heapq.heappush(maximum, (-nums[right], rig...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR LIST LIST WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR WHILE VAR VAR NUMBER NUMBER VAR EXPR FUN...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if len(nums) == 0: return 0 dec_stack = [] inc_stack = [] max_interval = 1 l, r = 0, 0 min_v, max_v = nums[0], nums[0] dec_stack.append((nums[0], 0)) inc_stack....
CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR WHILE B...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: currmax = currmin = nums[0] start = 0 res = 1 for i in range(1, len(nums)): currmax = max(currmax, nums[i]) currmin = min(currmin, nums[i]) if currmax - currmin <= limi...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: p1, p2, ans, cnt, min_, max_ = 0, 0, 0, {nums[0]: 1}, nums[0], nums[0] while True: if max_ - min_ <= limit: ans = max(ans, p2 - p1 + 1) if p2 == len(nums) - 1: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER DICT VAR NUMBER NUMBER VAR NUMBER VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSI...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: n = len(nums) max_stack = collections.deque([0]) min_stack = collections.deque([0]) begin, end, longest = 0, 0, 0 while end < n: while True: diff = nums[max_stack[0]] -...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR EXPR ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: mx, mi = [0], [0] res = 1 left = 0 for c in range(1, len(nums)): num = nums[c] while mx and nums[mx[-1]] < num: mx.pop() mx.append(c) while ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR LIST NUMBER LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: incr_q = [nums[0]] decr_q = [nums[0]] res = 1 left = 0 right = 1 while right < len(nums): while incr_q and incr_q[-1] > nums[right]: incr_q.pop() in...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR WHI...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: maxheap, minheap = [(-nums[0], 0)], [(nums[0], 0)] l, maxindex, res = 0, 0, 1 for i, val in enumerate(nums[1:], 1): if val - minheap[0][0] <= limit and -maxheap[0][0] - val <= limit: r...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR LIST VAR NUMBER NUMBER LIST VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR BIN_OP ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: n = len(nums) res = 0 left, right = 0, 0 inc, dec = collections.deque(), collections.deque() while right < n: while inc and nums[inc[-1]] >= nums[right]: inc.pop() ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NU...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: n = len(nums) max_q = deque() min_q = deque() start = 0 ans = 0 for end in range(n): while max_q and max_q[-1] < nums[end]: max_q.pop() while min_q ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR WHILE VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VA...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if len(nums) == 0: return 0 if len(nums) == 1: return 1 ans = 1 minNum = nums[0] maxNum = nums[0] i = 0 j = 0 n = len(nums) while i < n and ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CAL...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if not nums: return 0 n = len(nums) i = j = 0 curr_max = curr_min = nums[0] maxes = [(-curr_max, 0)] mins = [(curr_min, 0)] best = 0 while i <= j < n: ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP B...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, A, limit): M = collections.deque() m = collections.deque() i = 0 for a in A: while M and a > M[-1]: M.pop() while m and a < m[-1]: m.pop() M.append(a) m.append(a...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR IF VAR NUM...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: max_deque = collections.deque() min_deque = collections.deque() start = 0 end = 0 max_limit_subarray = 0 for end in range(len(nums)): while min_deque and nums[end] < nums[min_d...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: maxd, mind = collections.deque(), collections.deque() l, r, res = 0, 0, 0 while r < len(nums): while len(maxd) and maxd[-1] < nums[r]: maxd.pop() while len(mind) and mind[-...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: min_deque, max_deque = deque(), deque() l = r = 0 ans = 0 while r < len(nums): while min_deque and nums[r] <= nums[min_deque[-1]]: min_deque.pop() while max_deque a...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if not nums: return 0 i = 0 j = 0 n = len(nums) maxq = [] minq = [] max_l = 0 while i < n and j < n: while maxq and nums[j] > maxq[-1]: ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUN...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if len(nums) <= 1: return len(nums) queue = [nums[0]] small = queue[0] large = queue[0] ans = 1 for i in range(1, len(nums)): if abs(nums[i] - small) <= limit and a...
CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: maxque = collections.deque([]) minque = collections.deque([]) start = end = 0 count = 0 while end < len(nums): while len(maxque) and nums[end] > nums[maxque[-1]]: maxqu...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR F...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class MinMaxStack: def __init__(self): self.s = [] self.mins = [] self.maxes = [] def append(self, x): self.s.append(x) if not self.mins or x <= self.mins[-1]: self.mins.append(x) if not self.maxes or x >= self.maxes[-1]: self.maxes.appen...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF RET...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: maxq = collections.deque() minq = collections.deque() start = 0 for i, n in enumerate(nums): while maxq and maxq[-1][0] < n: maxq.pop() while minq and minq[-1][0] >...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR IF BIN_OP VAR NUMBER NUMB...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: maxD = [] minD = [] ind = 0 res = 0 slow = 0 fast = 0 while slow <= fast and fast < len(nums): while len(maxD) > 0 and maxD[len(maxD) - 1] < nums[fast]: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
def add_to_max_heap(heap, value): heapq.heappush(heap, value) def add_to_min_heap(heap, value): heapq.heappush(heap, value) def get_max_val(heap): return heap[0][0] def get_min_val(heap): return heap[0][0] class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: ...
FUNC_DEF EXPR FUNC_CALL VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN VAR NUMBER NUMBER FUNC_DEF RETURN VAR NUMBER NUMBER CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CAL...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if len(nums) < 2: return 1 longestSize = 1 left = 0 lo_q, hi_q = [], [] heapq.heappush(lo_q, (nums[0], 0)) heapq.heappush(hi_q, (-nums[0], 0)) for idx in range(1, len(n...
CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR LIST LIST EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR LIST IF VAR V...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: l = len(nums) if l == 1: if limit >= 0: return 1 return 0 max_count = i = 0 j = 1 def get_min(): while min_list[0][1] < i: heap...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF WHILE VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER NUMBER FUNC_DEF WHILE VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER N...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: start = 0 end = 0 longest_size = 0 maxa = nums[0] mina = nums[0] while end < len(nums): if maxa - mina <= limit: longest_size = max(longest_size, end - start) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR V...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: winMax = [0] winMin = [0] i = j = 0 res = 0 while i < len(nums) - 1 and j < len(nums) - 1: diff = nums[winMax[0]] - nums[winMin[0]] if diff <= limit: res = ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR V...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: begin = end = 0 l = len(nums) d = 0 heap_min = [] heap_max = [] heapq.heapify(heap_min) heapq.heapify(heap_max) while end < l: heapq.heappush(heap_min, (nums[en...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER BIN_OP VAR VA...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if limit < 0: return 0 i, j = 0, 1 res = 0 max_q, min_q = collections.deque(), collections.deque() max_q.append((0, nums[0])) min_q.append((0, nums[0])) while j < len(n...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR WHILE VAR VAR VAR V...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: minheap = [] maxheap = [] heapq.heapify(minheap) heapq.heapify(maxheap) length = 1 i = 0 j = 1 heapq.heappush(minheap, [nums[0], 0]) heapq.heappush(maxheap, [-nums[...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR LIST VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR LIST VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER NU...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: l = ans = 0 maxh, minh = [], [] for r, num in enumerate(nums): heapq.heappush(maxh, (-1 * num, r)) heapq.heappush(minh, (num, r)) while maxh[0][0] * -1 - minh[0][0] > limit: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR WHILE BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER VAR WHILE VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER N...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: maxs, mins = [], [] res = 0 start = 0 for i, n in enumerate(nums): while maxs and maxs[-1] < n: maxs.pop() while mins and mins[-1] > n: mins.pop() ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR NUMBER VAR VAR EXP...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if len(nums) == 1 and limit >= 0: return 1 longest_subarray = 0 right = 0 left = 0 min_val = nums[left] max_val = nums[left] min_dq = [] max_dq = [] whi...
CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if not nums: return 0 curr_max = nums[0] curr_min = nums[0] sub_nums = [] for num in nums: if ( abs(num - curr_max) <= limit and abs(num - c...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: min_heap = [] max_heap = [] longest_window = 1 min_idx = 0 for i, num in enumerate(nums): heapq.heappush(min_heap, (num, i)) heapq.heappush(max_heap, (-num, i)) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR WHILE VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: i = 0 j = 0 max_length = 1 cur_max = cur_min = nums[0] while j < len(nums): dif = cur_max - cur_min if dif <= limit: max_length = j - i + 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VA...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: max_queue = collections.deque() min_queue = collections.deque() l = r = 0 max_len = 0 while r < len(nums): while max_queue and nums[r] >= max_queue[-1][0]: max_queue.po...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: n = len(nums) i, j, ans = 0, 0, 0 min_heap, max_heap = [], [] heapq.heapify(min_heap) heapq.heapify(max_heap) while i <= j < n: heapq.heappush(min_heap, (nums[j], j)) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR LIST LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: VALUE, INDEX = 0, 1 left = 0 min_h, max_h = [], [] max_len = 0 for right, num in enumerate(nums): heappush(min_h, (num, right)) heappush(max_h, (-num, right)) w...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR WHILE BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: ans = 1 st = en = 0 min_q = collections.deque() max_q = collections.deque() while en < len(nums): while min_q and nums[en] <= nums[min_q[-1]]: min_q.pop() w...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if not nums: return 0 cur_max = nums[0] cur_min = nums[0] sub_nums = [] for i in nums: cur_max = max(i, cur_max) cur_min = min(i, cur_min) if cur_ma...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: count = collections.defaultdict(int) min_heap = [] max_heap = [] ans = [] max_length = 0 for num in nums: ans.append(num) count[num] += 1 if count[num] ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: max_list = [] min_list = [] j = 0 for i in range(len(nums)): while max_list and max_list[-1] < nums[i]: max_list.pop() while min_list and min_list[-1] > nums[i]: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR WHILE VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR NUMBER...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: hmin, hmax = [], [] heapq.heapify(hmin), heapq.heapify(hmax) max_length = 0 i, j = 0, 0 heapq.heappush(hmin, (nums[0], 0)), heapq.heappush(hmax, (-1 * nums[0], 0)) while j < len(nums): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR LIST LIST EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR WHILE ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: minHeap = [] maxHeap = [] l = 0 maxSize = 0 for r, num in enumerate(nums): heappush(minHeap, (num, r)) heappush(maxHeap, (-num, r)) minElement, minIndex = minHe...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR VAR VAR NUMBER WHILE VAR NUMBER NUMBER VA...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: minHeap, maxHeap = [], [] left = maxLen = 0 for right in range(len(nums)): heappush(minHeap, (nums[right], right)) heappush(maxHeap, (-nums[right], right)) while nums[right] - ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMB...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: result = 1 start = 0 end = start + result mini = float("inf") maxi = float("-inf") while end <= len(nums): mini = min(nums[start:end]) maxi = max(nums[start:end]) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: def addToDeqs(min_deq, max_deq, curr, start_i): while min_deq and min_deq[-1] > curr: min_deq.pop() min_deq.append(curr) while max_deq and max_deq[-1] < curr: ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMB...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if not nums: return 0 rlt = 1 q = collections.deque([nums[0]]) max_stack, min_stack = [nums[0]], [nums[0]] for i in range(1, len(nums)): while max_stack and ( ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR VAR LIST VAR NUMBER LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR NUMBER EX...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: sd = collections.deque() ld = collections.deque() def smallpush(d, i): while d and d[-1][0] > nums[i]: d.pop() d.append((nums[i], i)) def largepush(d, i): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF WHILE VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF WHILE VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF WHILE VAR VAR NUMBER NUMBER VAR EXPR FUN...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if len(nums) == 1: return 1 left = right = 0 min_n = max_n = nums[0] max_size = 0 while right < len(nums): if nums[right] > max_n: max_n = nums[right] ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR WHILE BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBE...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: min_heap, max_heap = deque([0]), deque([0]) res = 1 far = -1 for i in range(1, len(nums)): while min_heap and nums[min_heap[-1]] > nums[i]: min_heap.pop() while max...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR LIST NUMBER FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR BIN_OP VAR ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: max_len = 1 maxi = nums[0] mini = nums[0] start = 0 temp = nums[start : start + 1] for i in range(1, len(nums)): temp.append(nums[i]) if nums[i] > maxi: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN V...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: i = 0 j = 1 n = len(nums) if n == 0: return 0 mn = nums[0] mx = nums[0] l = 1 while i <= j and j < n: if mn > nums[j]: mn = nums[j] ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR V...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: begin, end = 0, 0 n = len(nums) heap_min = [] heapq.heapify(heap_min) heap_max = [] heapq.heapify(heap_max) heapq.heappush(heap_min, (nums[0], 0)) heapq.heappush(heap_max, ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL V...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums, limit): _min = _max = nums[0] count = 0 res, start = 1, 0 for right in range(len(nums)): if _min > nums[right]: _min = nums[right] if _max < nums[right]: _max = nums[right] ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VA...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: mxh, mnh = [], [] i = j = 0 ans = 0 while i < len(nums): if j < len(nums) and ( not mxh or not mnh or abs(mxh[0][0] + mnh[0][0]) <= limit ): heappus...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR LIST VAR VAR VAR VAR NUMBER IF VAR VAR ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: min_h = [(nums[0], 0)] max_h = [(-nums[0], 0)] heapq.heapify(min_h) heapq.heapify(max_h) max_v, min_v = nums[0], nums[0] l, r = 0, 0 res = 1 while r < len(nums): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR ...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: min_deque = [nums[0]] max_deque = [nums[0]] max_stretch = 1 start = 0 end = 0 while end < len(nums) - 1: end += 1 while len(min_deque) > 0 and nums[end] < min_deque...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER V...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums, limit): mini, maxi, res, i = deque([]), deque([]), 0, 0 for j in range(len(nums)): while mini and mini[-1][0] > nums[j]: mini.pop() mini.append((nums[j], j)) while maxi and maxi[-1][0] < nums[j]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR LIST FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR WHILE FUNC_CAL...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: if nums is None or len(nums) == 0: return 0 queue = collections.deque([]) max_len = 0 right = 0 min_heap = [] max_heap = [] for left in range(len(nums)): if...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR NONE FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER WHILE VA...
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.   Example 1: Input: nums = [8,2,4,7], limit = 4 Output: 2 Explanation: All subarrays are: [8] with maximum...
class Solution: def longestSubarray(self, nums: List[int], limit: int) -> int: n = len(nums) minh = [] maxh = [] start = 0 ans = 0 deleted = set() for end in range(n): x = nums[end] heappush(minh, (x, end)) heappush(maxh, (...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR WHILE...
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). Example: Input: S = "ADOBECODEBANC", T = "ABC" Output: "BANC" Note: If there is no such window in S that covers all characters in T, return the empty string "". If there is s...
class Solution: def minWindow(self, s, t): table = {} for c in t: table[c] = table[c] + 1 if c in table else 1 start, end, count = 0, 0, len(t) min_start, min_end = None, None for i in range(len(s)): if s[i] in table: if table[s[i]] > ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NONE NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER IF VAR ...
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). Example: Input: S = "ADOBECODEBANC", T = "ABC" Output: "BANC" Note: If there is no such window in S that covers all characters in T, return the empty string "". If there is s...
class Solution: def minWindow(self, s, t): left = -1 right = 0 result = "" totalMatch = 0 d = {} for c in t: d[c] = d.get(c, 0) + 1 for right in range(len(s)): c = s[right] d[c] = d.get(c, 0) - 1 if d[c] >= 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER IF VA...
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). Example: Input: S = "ADOBECODEBANC", T = "ABC" Output: "BANC" Note: If there is no such window in S that covers all characters in T, return the empty string "". If there is s...
class Solution: def minWindow(self, s, t): if len(t) > len(s): return "" dic = {} for i in t: if i in dic: dic[i] += 1 else: dic[i] = 1 counter = len(dic) start = end = 0 minl = len(s) + 1 re...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN STRING ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VA...
Given an integer array arr of size N and an integer k, return the number of good subarrays of arr. A good array is an array where the number of different integers in that is exactly k. For example, {1, 3, 4, 4, 1} has 3 different integers: 1, 3, and 4. Note : A subarray is a contiguous part of an array. Example 1: Inp...
class Solution: def subarrayCount(self, arr, N, k): def atmost(arr, k): l, r, count = 0, 0, 0 mp = {} while r < len(arr): mp[arr[r]] = 1 + mp.get(arr[r], 0) while len(mp) > k: mp[arr[l]] -= 1 if mp[...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NU...
Given an integer array arr of size N and an integer k, return the number of good subarrays of arr. A good array is an array where the number of different integers in that is exactly k. For example, {1, 3, 4, 4, 1} has 3 different integers: 1, 3, and 4. Note : A subarray is a contiguous part of an array. Example 1: Inp...
class Solution: def atmost(self, arr, k): left = 0 suma = 0 d = dict() for i in range(len(arr)): if arr[i] in d: d[arr[i]] += 1 else: d[arr[i]] = 1 while len(d) > k: d[arr[left]] -= 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC...
Given an integer array arr of size N and an integer k, return the number of good subarrays of arr. A good array is an array where the number of different integers in that is exactly k. For example, {1, 3, 4, 4, 1} has 3 different integers: 1, 3, and 4. Note : A subarray is a contiguous part of an array. Example 1: Inp...
class Solution: def subarrayCount(self, arr, N, k): return self.subArrayMax(arr, N, k) - self.subArrayMax(arr, N, k - 1) def subArrayMax(self, arr, N, k): i, j, ans = 0, 0, 0 state = {} for j in range(N): state[arr[j]] = 1 + state.get(arr[j], 0) while le...
CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER...
Given an integer array arr of size N and an integer k, return the number of good subarrays of arr. A good array is an array where the number of different integers in that is exactly k. For example, {1, 3, 4, 4, 1} has 3 different integers: 1, 3, and 4. Note : A subarray is a contiguous part of an array. Example 1: Inp...
class Solution: def subarrayCount(self, arr, N, k): return self.atMost(arr, N, k) - self.atMost(arr, N, k - 1) def atMost(self, arr, n, k): i = 0 j = 0 count = 0 map = {} while j < n: map[arr[j]] = map.get(arr[j], 0) + 1 while len(map) > ...
CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMB...
Given an integer array arr of size N and an integer k, return the number of good subarrays of arr. A good array is an array where the number of different integers in that is exactly k. For example, {1, 3, 4, 4, 1} has 3 different integers: 1, 3, and 4. Note : A subarray is a contiguous part of an array. Example 1: Inp...
class Solution: def solve(self, arr, N, k): count, i = 0, 0 d = {} for j in range(N): d[arr[j]] = 1 + d.get(arr[j], 0) while i <= j and len(d) > k: d[arr[i]] = -1 + d.get(arr[i], 0) if not d[arr[i]]: del d[arr[i]] ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER...
Given an integer array arr of size N and an integer k, return the number of good subarrays of arr. A good array is an array where the number of different integers in that is exactly k. For example, {1, 3, 4, 4, 1} has 3 different integers: 1, 3, and 4. Note : A subarray is a contiguous part of an array. Example 1: Inp...
class Solution: def subarrayCount(self, nums, N, k): ans = 0 n = len(nums) latest = {} unique = 0 prev = 0 for i in range(n): if nums[i] not in latest: unique += 1 latest[nums[i]] = i if unique > k: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR WHILE NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER AS...