diff --git "a/masked_leetcode_standalone_words.python.test.csv" "b/masked_leetcode_standalone_words.python.test.csv" deleted file mode 100644--- "a/masked_leetcode_standalone_words.python.test.csv" +++ /dev/null @@ -1,30570 +0,0 @@ -id,comefrom,code,masked,words,unique_words_num -0,1064_Fixed_Point_2.py,"def fixedPoint( A): - l, h = 0, len(A) - 1 - while l <= h: - mid = (l + h) // 2 - if A[mid] < mid: - l = mid + 1 - elif A[mid] > mid: - h = mid - 1 - else: - return mid - return -1","def sample_funcname ( var_0 ) : - var_2 , var_5 = 0 , len ( var_0 ) - 1 - while var_2 <= var_5 : - var_7 = ( var_2 + var_5 ) // 2 - if var_0 [ var_7 ] < var_7 : - var_2 = var_7 + 1 - elif var_0 [ var_7 ] > var_7 : - var_5 = var_7 - 1 - else : - return var_7 - return - 1 -",102,3 -1,066_Plus_One_1.py,"def plusOne( digits): - ls = len(digits) - curr, pos = 1, 0 - while pos < ls: - index = ls - pos - 1 - curr += digits[index] - digits[index] = curr % 10 - curr /= 10 - if curr == 0: - - break - pos += 1 - if curr > 0: - digits.insert(0, curr) - return digits","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_4 , var_6 = 1 , 0 - while var_6 < var_2 : - var_7 = var_2 - var_6 - 1 - var_4 += var_0 [ var_7 ] - var_0 [ var_7 ] = var_4 % 10 - var_4 /= 10 - if var_4 == 0 : - break - var_6 += 1 - if var_4 > 0 : - var_0.insert ( 0 , var_4 ) - return var_0 -",1010,3 -2,443_String_Compression_1.py,"def compress( chars): - anchor = write = 0 - for read, c in enumerate(chars): - if read + 1 == len(chars) or chars[read + 1] != c: - chars[write] = chars[anchor] - write += 1 - if read > anchor: - for digit in str(read - anchor + 1): - chars[write] = digit - write += 1 - anchor = read + 1 - return write","def sample_funcname ( var_0 ) : - var_3 = var_1 = 0 - for var_5 , var_6 in enumerate ( var_0 ) : - if var_5 + 1 == len ( var_0 ) or var_0 [ var_5 + 1 ] != var_6 : - var_0 [ var_1 ] = var_0 [ var_3 ] - var_1 += 1 - if var_5 > var_3 : - for var_10 in str ( var_5 - var_3 + 1 ) : - var_0 [ var_1 ] = var_10 - var_1 += 1 - var_3 = var_5 + 1 - return var_1 -",10,2 -3,027_Remove_Element_1.py,"def removeElement( nums, val): - ls = len(nums) - if ls == 0: - return ls - pos = 0 - for i in range(ls): - if nums[i] == val: - continue - else: - nums[pos] = nums[i] - pos += 1 - - return pos","def sample_funcname ( var_0 , var_1 ) : - var_3 = len ( var_0 ) - if var_3 == 0 : - return var_3 - var_5 = 0 - for var_7 in range ( var_3 ) : - if var_0 [ var_7 ] == var_1 : - continue - else : - var_0 [ var_5 ] = var_0 [ var_7 ] - var_5 += 1 - return var_5 -",10,2 -4,019_Remove_Nth_Node_From_End_of_List_1.py,"def removeNthFromEnd( head, n): - index = [] - pos = head - while pos is not None: - index.append(pos) - pos = pos.next - ls = len(index) - if n == ls: - if ls > 1: - return index[1] - else: - return None - else: - index_pos = ls - n - 1 - index[index_pos].next = index[index_pos + 1].next - return head","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - var_3 = var_0 - while var_3 is not None : - var_2.append ( var_3 ) - var_3 = var_3.next - var_8 = len ( var_2 ) - if var_1 == var_8 : - if var_8 > 1 : - return var_2 [ 1 ] - else : - return None - else : - var_10 = var_8 - var_1 - 1 - var_2 [ var_10 ].next = var_2 [ var_10 + 1 ].next - return var_0 -",1None,2 -5,119_Pascal's_Triangle_II_1.py,"def getRow( rowIndex): - last = [1] - res = [1] - for r in range(1, rowIndex + 1): - res = [1] - for index in range(len(last) - 1): - res.append(last[index] + last[index + 1]) - res.append(1) - last = res - return res","def sample_funcname ( var_0 ) : - var_2 = [ 1 ] - var_3 = [ 1 ] - for var_5 in range ( 1 , var_0 + 1 ) : - var_3 = [ 1 ] - for var_7 in range ( len ( var_2 ) - 1 ) : - var_3.append ( var_2 [ var_7 ] + var_2 [ var_7 + 1 ] ) - var_3.append ( 1 ) - var_2 = var_3 - return var_3 -",1,1 -6,389_Find_the_Difference_2.py,"def findTheDifference( s, t): - res = 0 - for c in s + t: - res ^= ord(c) - return chr(res)","def sample_funcname ( var_0 , var_1 ) : - var_3 = 0 - for var_4 in var_0 + var_1 : - var_3 ^= ord ( var_4 ) - return chr ( var_3 ) -",0,1 -7,388_Longest_Absolute_File_Path_1.py,"def lengthLongestPath( input): - if input is None or len(input) == 0: - return 0 - lines = input.split('\n') - last_level_len = [0] * (len(lines) + 1); max_len = 0 - for line in lines: - try: - level = line.rindex('\t') + 1 - except: - level = 0 - cur_len = last_level_len[level + 1] = last_level_len[level] + len(line) - level + 1 - if '.' in line: - max_len = max(max_len, cur_len - 1) - return max_len","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return 0 - var_6 = var_0.split ( '\n' ) - var_8 = [ 0 ] * ( len ( var_6 ) + 1 ) ; var_9 = 0 - for var_10 in var_6 : - try : - var_13 = var_10.rindex ( '\t' ) + 1 - except : - var_13 = 0 - var_14 = var_8 [ var_13 + 1 ] = var_8 [ var_13 ] + len ( var_10 ) - var_13 + 1 - if '.' in var_10 : - var_9 = max ( var_9 , var_14 - 1 ) - return var_9 -",\n0None\t.1,6 -8,461_Hamming_Distance_1.py,"def hammingDistance( x, y): - return bin(x ^ y).count('1')","def sample_funcname ( var_0 , var_1 ) : - return bin ( var_0 ^ var_1 ).count ( '1' ) -",1,1 -9,092_Reverse_Linked_Lis_ II_1.py,"def reverseBetween( head, m, n): - if m == n: - return head - split_node, prev, curr = None, None, head - count = 1 - while count <= m and curr is not None: - if count == m: - split_node = prev - prev = curr - curr = curr.next - count += 1 - tail, next_node = prev, None - while curr is not None and count <= n: - next_temp = curr.next - curr.next = prev - prev = curr - curr = next_temp - count += 1 - if split_node is not None: - split_node.next = prev - if tail is not None: - tail.next = curr - if m == 1: - return prev - return head","def sample_funcname ( var_0 , var_1 , var_2 ) : - if var_1 == var_2 : - return var_0 - var_4 , var_5 , var_6 = None , None , var_0 - var_8 = 1 - while var_8 <= var_1 and var_6 is not None : - if var_8 == var_1 : - var_4 = var_5 - var_5 = var_6 - var_6 = var_6.next - var_8 += 1 - var_10 , var_11 = var_5 , None - while var_6 is not None and var_8 <= var_2 : - var_12 = var_6.next - var_6.next = var_5 - var_5 = var_6 - var_6 = var_12 - var_8 += 1 - if var_4 is not None : - var_4.next = var_5 - if var_10 is not None : - var_10.next = var_6 - if var_1 == 1 : - return var_5 - return var_0 -",1None,2 -10,088_Merge_Sorted_Array_1.py,"def merge( nums1, m, nums2, n): - p1, p2 = m - 1, n - 1 - pos = m + n - 1 - while p1 >= 0 and p2 >= 0: - if nums1[p1] >= nums2[p2]: - nums1[pos] = nums1[p1] - p1 -= 1 - else: - nums1[pos] = nums2[p2] - p2 -= 1 - pos -= 1 - while p2 >= 0: - nums1[pos] = nums2[p2] - p2 -= 1 - pos -= 1","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - var_5 , var_6 = var_1 - 1 , var_3 - 1 - var_7 = var_1 + var_3 - 1 - while var_5 >= 0 and var_6 >= 0 : - if var_0 [ var_5 ] >= var_2 [ var_6 ] : - var_0 [ var_7 ] = var_0 [ var_5 ] - var_5 -= 1 - else : - var_0 [ var_7 ] = var_2 [ var_6 ] - var_6 -= 1 - var_7 -= 1 - while var_6 >= 0 : - var_0 [ var_7 ] = var_2 [ var_6 ] - var_6 -= 1 - var_7 -= 1 -",10,2 -11,408_Valid_Word_Abbreviation_1.py,"def validWordAbbreviation( word, abbr): - if word == abbr: - return True - pos1 = pos2 = 0 - curr = 0 - while pos1 < len(abbr) and pos2 < len(word): - try: - num = int(abbr[pos1]) - - if num == 0 and curr == 0: - return False - curr = curr * 10 + num - except ValueError: - if curr > 0: - pos2 += curr - - if pos2 >= len(word): - return False - curr = 0 - if abbr[pos1] != word[pos2]: - return False - pos2 += 1 - pos1 += 1 - - if curr > 0: - pos2 += curr - if pos1 == len(abbr) and pos2 == len(word): - return True - return False","def sample_funcname ( var_0 , var_1 ) : - if var_0 == var_1 : - return True - var_5 = var_3 = 0 - var_6 = 0 - while var_5 < len ( var_1 ) and var_3 < len ( var_0 ) : - try : - var_9 = int ( var_1 [ var_5 ] ) - if var_9 == 0 and var_6 == 0 : - return False - var_6 = var_6 * 10 + var_9 - except ValueError : - if var_6 > 0 : - var_3 += var_6 - if var_3 >= len ( var_0 ) : - return False - var_6 = 0 - if var_1 [ var_5 ] != var_0 [ var_3 ] : - return False - var_3 += 1 - var_5 += 1 - if var_6 > 0 : - var_3 += var_6 - if var_5 == len ( var_1 ) and var_3 == len ( var_0 ) : - return True - return False -",1001,3 -12,018_4Sum_2.py,"def fourSum( nums, target): - index_pairs = dict() - combos = dict() - n = len(nums) - for i in range(0,n): - for j in range(i+1,n): - sum = nums[i] + nums[j] - if index_pairs.get(target - sum) is not None: - for pair in index_pairs[target - sum]: - if i != pair[0] and i != pair[1] and j != pair[0] and j != pair[1]: - combo = sorted((nums[i], nums[j], nums[pair[0]], nums[pair[1]])) - combos[tuple(combo)] = True - if index_pairs.get(sum) is not None: - index_pairs[sum].append((i,j)) - else: - index_pairs[sum] = [(i,j)] - return combos.keys()","def sample_funcname ( var_0 , var_1 ) : - var_3 = dict ( ) - var_4 = dict ( ) - var_6 = len ( var_0 ) - for var_9 in range ( 0 , var_6 ) : - for var_11 in range ( var_9 + 1 , var_6 ) : - var_12 = var_0 [ var_9 ] + var_0 [ var_11 ] - if var_3.get ( var_1 - var_12 ) is not None : - for var_15 in var_3 [ var_1 - var_12 ] : - if var_9 != var_15 [ 0 ] and var_9 != var_15 [ 1 ] and var_11 != var_15 [ 0 ] and var_11 != var_15 [ 1 ] : - var_17 = sorted ( ( var_0 [ var_9 ] , var_0 [ var_11 ] , var_0 [ var_15 [ 0 ] ] , var_0 [ var_15 [ 1 ] ] ) ) - var_4 [ tuple ( var_17 ) ] = True - if var_3.get ( var_12 ) is not None : - var_3 [ var_12 ].append ( ( var_9 , var_11 ) ) - else : - var_3 [ var_12 ] = [ ( var_9 , var_11 ) ] - return var_4.keys ( ) -",10None,3 -13,014_Longest_Common_Prefix_1.py,"def longestCommonPrefix( strs): - ls = len(strs) - if ls == 1: - return strs[0] - prefix = '' - pos = 0 - while True: - try: - current = strs[0][pos] - except IndexError: - break - index = 1 - while index < ls: - try: - if strs[index][pos] != current: - break - except IndexError: - break - index += 1 - if index == ls: - prefix = prefix + current - else: - break - pos += 1 - return prefix","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - if var_2 == 1 : - return var_0 [ 0 ] - var_6 = '' - var_7 = 0 - while True : - try : - var_9 = var_0 [ 0 ] [ var_7 ] - except IndexError : - break - var_11 = 1 - while var_11 < var_2 : - try : - if var_0 [ var_11 ] [ var_7 ] != var_9 : - break - except IndexError : - break - var_11 += 1 - if var_11 == var_2 : - var_6 = var_6 + var_9 - else : - break - var_7 += 1 - return var_6 -",10,3 -14,280_Wiggle_Sort_1.py,"def wiggleSort( nums): - if nums is None or len(nums) == 0: - return - nums.sort() - - wiggle = (len(nums) - 1) / 2 - for i in range(wiggle): - pos = i * 2 + 1 - nums.insert(pos, nums.pop(-1))","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return - var_0.sort ( ) - var_7 = ( len ( var_0 ) - 1 ) / 2 - for var_9 in range ( var_7 ) : - var_10 = var_9 * 2 + 1 - var_0.insert ( var_10 , var_0.pop ( - 1 ) ) -",10None2,4 -15,074_Search_a_2D_Matrix_1.py,"def search_row( matrix, row, target): - if target < matrix[row][0]: - return -1 - elif target > matrix[row][-1]: - return 1 - begin, end = 0, len(matrix[row]) - 1 - while begin <= end: - mid = (begin + end) / 2 - if matrix[row][mid] == target: - return 0 - elif matrix[row][mid] < target: - begin = mid + 1 - else: - end = mid - 1 - return 1","def sample_funcname ( var_0 , var_1 , var_2 ) : - if var_2 < var_0 [ var_1 ] [ 0 ] : - return - 1 - elif var_2 > var_0 [ var_1 ] [ - 1 ] : - return 1 - var_5 , var_7 = 0 , len ( var_0 [ var_1 ] ) - 1 - while var_5 <= var_7 : - var_9 = ( var_5 + var_7 ) / 2 - if var_0 [ var_1 ] [ var_9 ] == var_2 : - return 0 - elif var_0 [ var_1 ] [ var_9 ] < var_2 : - var_5 = var_9 + 1 - else : - var_7 = var_9 - 1 - return 1 -",102,3 -16,043_Multiply_Strings_1.py,"def add_strings( s_list): - if len(s_list) == 0: - return '0' - res = '' - curr, pos = 0, 0 - max_ls = max([len(t) for t in s_list]) - while pos < max_ls: - for s in s_list: - if len(s) <= pos: - continue - curr += int(s[len(s) - pos - 1]) - res = str(curr % 10) + res - curr /= 10 - pos += 1 - if curr > 0: - res = str(curr) + res - return res","def sample_funcname ( var_0 ) : - if len ( var_0 ) == 0 : - return '0' - var_5 = '' - var_6 , var_7 = 0 , 0 - var_10 = max ( [ len ( var_9 ) for var_9 in var_0 ] ) - while var_7 < var_10 : - for var_11 in var_0 : - if len ( var_11 ) <= var_7 : - continue - var_6 += int ( var_11 [ len ( var_11 ) - var_7 - 1 ] ) - var_5 = str ( var_6 % 10 ) + var_5 - var_6 /= 10 - var_7 += 1 - if var_6 > 0 : - var_5 = str ( var_6 ) + var_5 - return var_5 -",10001,5 -17,351_Android_Unlock_Patterns_1.py,"def is_valid( used, index, last): - if used[index]: - return False - if last == -1: - return True - if (last + index) % 2 == 1: - return True - mid = (last + index) / 2 - if mid == 4: - return used[mid] - if (index % 3 != last % 3) and (index / 3 != last / 3): - return True - return used[mid]","def sample_funcname ( var_0 , var_1 , var_2 ) : - if var_0 [ var_1 ] : - return False - if var_2 == - 1 : - return True - if ( var_2 + var_1 ) % 2 == 1 : - return True - var_7 = ( var_2 + var_1 ) / 2 - if var_7 == 4 : - return var_0 [ var_7 ] - if ( var_1 % 3 != var_2 % 3 ) and ( var_1 / 3 != var_2 / 3 ) : - return True - return var_0 [ var_7 ] -",3142,4 -18,070_Climbing_Stairs_1.py,"def climbStairs( n): - dp = [0] * (n + 1) - dp[0] = 1 - dp[1] = 1 - for i in range(2, n + 1): - dp[i] = dp[i - 2] + dp[i- 1] - return dp[n]","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * ( var_0 + 1 ) - var_3 [ 0 ] = 1 - var_3 [ 1 ] = 1 - for var_6 in range ( 2 , var_0 + 1 ) : - var_3 [ var_6 ] = var_3 [ var_6 - 2 ] + var_3 [ var_6 - 1 ] - return var_3 [ var_0 ] -",102,3 -19,405_Convert_a_Number_to_Hexadecimal_2.py,"def tohex(val, nbits): - return hex((val + (1 << nbits)) % (1 << nbits))","def sample_funcname ( var_0 , var_1 ) : - return hex ( ( var_0 + ( 1 << var_1 ) ) % ( 1 << var_1 ) ) -",1,1 -20,084_Largest_Rectangle_in_Histogram_1.py,"def largestRectangleArea( heights): - largest_rectangle = 0 - ls = len(heights) - stack = [-1] - top, pos = 0, 0 - for pos in range(ls): - while top > 0 and heights[stack[top]] > heights[pos]: - largest_rectangle = max(largest_rectangle, heights[stack[top]] * (pos - stack[top - 1] - 1)) - top -= 1 - stack.pop() - stack.append(pos) - top += 1 - while top > 0: - largest_rectangle = max(largest_rectangle, heights[stack[top]] * (ls - stack[top - 1] - 1)) - top -= 1 - return largest_rectangle","def sample_funcname ( var_0 ) : - var_2 = 0 - var_4 = len ( var_0 ) - var_6 = [ - 1 ] - var_7 , var_8 = 0 , 0 - for var_8 in range ( var_4 ) : - while var_7 > 0 and var_0 [ var_6 [ var_7 ] ] > var_0 [ var_8 ] : - var_2 = max ( var_2 , var_0 [ var_6 [ var_7 ] ] * ( var_8 - var_6 [ var_7 - 1 ] - 1 ) ) - var_7 -= 1 - var_6.pop ( ) - var_6.append ( var_8 ) - var_7 += 1 - while var_7 > 0 : - var_2 = max ( var_2 , var_0 [ var_6 [ var_7 ] ] * ( var_4 - var_6 [ var_7 - 1 ] - 1 ) ) - var_7 -= 1 - return var_2 -",10,2 -21,049_Group_Anagrams_1.py,"def hash_key( s): - table = [0] * 26 - for ch in s: - index = ord(ch) - ord('a') - table[index] += 1 - return str(table)","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * 26 - for var_4 in var_0 : - var_7 = ord ( var_4 ) - ord ( 'a' ) - var_3 [ var_7 ] += 1 - return str ( var_3 ) -",a0126,4 -22,221_Maximal_Square_3.py,"def maximalSquare( matrix): - if matrix is None or len(matrix) == 0: - return 0 - rows, cols, res, prev = len(matrix), len(matrix[0]), 0, 0 - dp = [0] * (cols + 1) - for i in range(1, rows + 1): - for j in range(1, cols + 1): - temp = dp[j] - if matrix[i - 1][j - 1] == '1': - dp[j] = min(dp[j - 1], dp[j], prev) + 1 - res = max(res, dp[j]) - else: - dp[j] = 0 - prev = temp - return res * res","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return 0 - var_4 , var_5 , var_6 , var_7 = len ( var_0 ) , len ( var_0 [ 0 ] ) , 0 , 0 - var_9 = [ 0 ] * ( var_5 + 1 ) - for var_11 in range ( 1 , var_4 + 1 ) : - for var_12 in range ( 1 , var_5 + 1 ) : - var_13 = var_9 [ var_12 ] - if var_0 [ var_11 - 1 ] [ var_12 - 1 ] == '1' : - var_9 [ var_12 ] = min ( var_9 [ var_12 - 1 ] , var_9 [ var_12 ] , var_7 ) + 1 - var_6 = max ( var_6 , var_9 [ var_12 ] ) - else : - var_9 [ var_12 ] = 0 - var_7 = var_13 - return var_6 * var_6 -",10None1,4 -23,1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number_1.py,"def smallerNumbersThanCurrent( nums: List[int]) -> List[int]: - sorted_index = {} - - for pos, value in enumerate(sorted(nums)): - if value in sorted_index: - continue - sorted_index[value] = pos - res = [] - for value in nums: - res.append(sorted_index[value]) - return res","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_3 = { } - for var_5 , var_7 in enumerate ( sorted ( var_0 ) ) : - if var_7 in var_3 : - continue - var_3 [ var_7 ] = var_5 - var_8 = [ ] - for var_7 in var_0 : - var_8.append ( var_3 [ var_7 ] ) - return var_8 -",,0 -24,383_Ransom_Note_1.py,"def canConstruct( ransomNote, magazine): - letter_map = {} - for letter in magazine: - letter_map[letter] = letter_map.get(letter, 0) + 1 - for letter in ransomNote: - letter_map[letter] = letter_map.get(letter, 0) - 1 - if letter_map[letter] < 0: - return False - return True","def sample_funcname ( var_0 , var_1 ) : - var_2 = { } - for var_3 in var_1 : - var_2 [ var_3 ] = var_2.get ( var_3 , 0 ) + 1 - for var_3 in var_0 : - var_2 [ var_3 ] = var_2.get ( var_3 , 0 ) - 1 - if var_2 [ var_3 ] < 0 : - return False - return True -",10,2 -25,128_Longest_Consecutive_Sequence_1.py,"def longestConsecutive( num): - num = set(num) - maxLen = 0 - while num: - n = num.pop() - i = n + 1 - l1 = 0 - l2 = 0 - while i in num: - num.remove(i) - i += 1 - l1 += 1 - i = n - 1 - while i in num: - num.remove(i) - i -= 1 - l2 += 1 - maxLen = max(maxLen, l1 + l2 + 1) - return maxLen","def sample_funcname ( var_0 ) : - var_0 = set ( var_0 ) - var_3 = 0 - while var_0 : - var_5 = var_0.pop ( ) - var_7 = var_5 + 1 - var_8 = 0 - var_9 = 0 - while var_7 in var_0 : - var_0.remove ( var_7 ) - var_7 += 1 - var_8 += 1 - var_7 = var_5 - 1 - while var_7 in var_0 : - var_0.remove ( var_7 ) - var_7 -= 1 - var_9 += 1 - var_3 = max ( var_3 , var_8 + var_9 + 1 ) - return var_3 -",10,2 -26,167_Two_Sum_II_Input_array_is_sorted_1.py,"def twoSum( numbers, target): - begin, end = 0, len(numbers) - 1 - while begin < end: - curr = numbers[begin] + numbers[end] - if curr == target: - return [begin + 1, end + 1] - elif curr < target: - begin += 1 - else: - end -= 1","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_6 = 0 , len ( var_0 ) - 1 - while var_3 < var_6 : - var_7 = var_0 [ var_3 ] + var_0 [ var_6 ] - if var_7 == var_1 : - return [ var_3 + 1 , var_6 + 1 ] - elif var_7 < var_1 : - var_3 += 1 - else : - var_6 -= 1 -",10,2 -28,061_Rotate_List_1.py,"def rotate( head, fast, slow): - fast.next = head - head = slow.next - slow.next = None - return head","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_1.next = var_0 - var_0 = var_2.next - var_2.next = None - return var_0 -",None,1 -29,1260_Shift_2D_Grid_1.py,"def shiftGrid( grid, k): - new_grid = [[0] * len(grid[0]) for _ in range(len(grid))] - m = len(grid) - n = len(grid[0]) - true_k = k % (m * n) - move_i = true_k / n - move_j = true_k % n - - for i in range(m): - for j in range(n): - new_i = i + move_i - if move_j + j >= n: - new_i += 1 - new_i %= m - new_j = (j + move_j) % n - new_grid[new_i][new_j] = grid[i][j] - return new_grid","def sample_funcname ( var_0 , var_1 ) : - var_6 = [ [ 0 ] * len ( var_0 [ 0 ] ) for var_4 in range ( len ( var_0 ) ) ] - var_7 = len ( var_0 ) - var_8 = len ( var_0 [ 0 ] ) - var_9 = var_1 % ( var_7 * var_8 ) - var_10 = var_9 / var_8 - var_11 = var_9 % var_8 - for var_12 in range ( var_7 ) : - for var_13 in range ( var_8 ) : - var_14 = var_12 + var_10 - if var_11 + var_13 >= var_8 : - var_14 += 1 - var_14 %= var_7 - var_16 = ( var_13 + var_11 ) % var_8 - var_6 [ var_14 ] [ var_16 ] = var_0 [ var_12 ] [ var_13 ] - return var_6 -",10,2 -30,766_Toeplitz_Matrix_1.py,"def isToeplitzMatrix( matrix): - for r in range(len(matrix) - 1): - for c in range(len(matrix[0]) - 1): - if matrix[r][c] != matrix[r + 1][c + 1]: - return False - return True","def sample_funcname ( var_0 ) : - for var_4 in range ( len ( var_0 ) - 1 ) : - for var_6 in range ( len ( var_0 [ 0 ] ) - 1 ) : - if var_0 [ var_4 ] [ var_6 ] != var_0 [ var_4 + 1 ] [ var_6 + 1 ] : - return False - return True -",10,2 -31,073_Set_Matrix_Zeroes_1.py,"def setZeroes( matrix): - if not matrix: - return - m = len(matrix) - if m == 0: - return - r = [] - c = [] - n = len(matrix[0]) - for i in range(m): - for j in range(n): - if matrix[i][j] == 0: - r.append(i) - c.append(j) - r = set(r) - c = set(c) - for i in r: - for j in range(n): - matrix[i][j] = 0 - for i in range(m): - for j in c: - matrix[i][j] = 0","def sample_funcname ( var_0 ) : - if not var_0 : - return - var_2 = len ( var_0 ) - if var_2 == 0 : - return - var_4 = [ ] - var_5 = [ ] - var_6 = len ( var_0 [ 0 ] ) - for var_8 in range ( var_2 ) : - for var_9 in range ( var_6 ) : - if var_0 [ var_8 ] [ var_9 ] == 0 : - var_4.append ( var_8 ) - var_5.append ( var_9 ) - var_4 = set ( var_4 ) - var_5 = set ( var_5 ) - for var_8 in var_4 : - for var_9 in range ( var_6 ) : - var_0 [ var_8 ] [ var_9 ] = 0 - for var_8 in range ( var_2 ) : - for var_9 in var_5 : - var_0 [ var_8 ] [ var_9 ] = 0 -",0,1 -32,937_Reorder_Log_Files_1.py,"def f(log): - id_, rest = log.split("" "", 1) - return (0, rest, id_) if rest[0].isalpha() else (1,)","def sample_funcname ( var_0 ) : - var_2 , var_5 = var_0.split ( "" "" , 1 ) - return ( 0 , var_5 , var_2 ) if var_5 [ 0 ].isalpha ( ) else ( 1 , ) -",1 0,3 -33,997_Find_The_Town_Judge_1.py,"def findJudge( N: int, trust: List[List[int]]) -> int: - if N==1: - return 1 - d1={} - d2={} - for i, j in trust: - if j in d1: - d1[j]+=1 - else: - d1[j]=1 - if i in d2: - d2[i]+=1 - else: - d2[i]=1 - for i,j in d1.items(): - if j==N-1: - if i not in d2: - return i - return -1","def sample_funcname ( var_0 : int , var_2 : List [ List [ int ] ] ) -> int : - if var_0 == 1 : - return 1 - var_5 = { } - var_6 = { } - for var_7 , var_8 in var_2 : - if var_8 in var_5 : - var_5 [ var_8 ] += 1 - else : - var_5 [ var_8 ] = 1 - if var_7 in var_6 : - var_6 [ var_7 ] += 1 - else : - var_6 [ var_7 ] = 1 - for var_7 , var_8 in var_5.items ( ) : - if var_8 == var_0 - 1 : - if var_7 not in var_6 : - return var_7 - return - 1 -",1,1 -34,165_Compare_Version_Numbers_1.py,"def compareVersion( version1: str, version2: str) -> int: - l1=list(map(int,version1.split('.'))) - l2=list(map(int,version2.split('.'))) - if l1==l2: - return(0) - - a=len(l1) - b=len(l2) - - if a>b: - for i in range(a-b): - l2.append(""0"") - - else: - for i in range(b-a): - l1.append(""0"") - - for i in range(len(l1)): - if int(l1[i])>int(l2[i]): - return(1) - - elif int(l1[i]) int : - var_8 = list ( map ( int , var_0.split ( '.' ) ) ) - var_9 = list ( map ( int , var_2.split ( '.' ) ) ) - if var_8 == var_9 : - return ( 0 ) - var_12 = len ( var_8 ) - var_13 = len ( var_9 ) - if var_12 > var_13 : - for var_15 in range ( var_12 - var_13 ) : - var_9.append ( ""0"" ) - else : - for var_15 in range ( var_13 - var_12 ) : - var_8.append ( ""0"" ) - for var_15 in range ( len ( var_8 ) ) : - if int ( var_8 [ var_15 ] ) > int ( var_9 [ var_15 ] ) : - return ( 1 ) - elif int ( var_8 [ var_15 ] ) < int ( var_9 [ var_15 ] ) : - return ( - 1 ) - else : - pass - return ( 0 ) -",100.,4 -35,075_Sort_Colors_1.py,"def sortColors( nums): - count = [0] * 3 - for num in nums: - count[num] += 1 - pos = 0 - for index in range(3): - while count[index] > 0: - nums[pos] = index - pos += 1 - count[index] -= 1 - return","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * 3 - for var_4 in var_0 : - var_3 [ var_4 ] += 1 - var_6 = 0 - for var_8 in range ( 3 ) : - while var_3 [ var_8 ] > 0 : - var_0 [ var_6 ] = var_8 - var_6 += 1 - var_3 [ var_8 ] -= 1 - return -",130,3 -37,206_Reverse_Linked_List_1.py,"def reverseList( head): - if head is None: - return - stack = [] - pos = start = head - while pos is not None: - stack.append(pos) - pos = pos.next - while len(stack) > 0: - if len(stack) >= 2: - stack[0].val, stack[-1].val = stack[-1].val, stack[0].val - stack.pop(0) - stack.pop() - else: - stack.pop() - return head","def sample_funcname ( var_0 ) : - if var_0 is None : - return - var_2 = [ ] - var_4 = var_3 = var_0 - while var_4 is not None : - var_2.append ( var_4 ) - var_4 = var_4.next - while len ( var_2 ) > 0 : - if len ( var_2 ) >= 2 : - var_2 [ 0 ].val , var_2 [ - 1 ].val = var_2 [ - 1 ].val , var_2 [ 0 ].val - var_2.pop ( 0 ) - var_2.pop ( ) - else : - var_2.pop ( ) - return var_0 -",10None2,4 -38,136_Single_Number_3.py,"def singleNumber( nums): - res = 0 - for num in nums: - res ^= num - return res","def sample_funcname ( var_0 ) : - var_2 = 0 - for var_3 in var_0 : - var_2 ^= var_3 - return var_2 -",0,1 -39,422_Valid_Word_Square_1.py,"def validWordSquare( words): - if words is None or len(words) == 0: - return True - ls = len(words) - for i in range(ls): - for j in range(1, len(words[i])): - if j >= ls: - return False - if i >= len(words[j]): - return False - if words[i][j] != words[j][i]: - return False - return True","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return True - var_5 = len ( var_0 ) - for var_7 in range ( var_5 ) : - for var_9 in range ( 1 , len ( var_0 [ var_7 ] ) ) : - if var_9 >= var_5 : - return False - if var_7 >= len ( var_0 [ var_9 ] ) : - return False - if var_0 [ var_7 ] [ var_9 ] != var_0 [ var_9 ] [ var_7 ] : - return False - return True -",10None,3 -40,852_Peak_Index_in_a_Mountain_Array_1.py,"def peakIndexInMountainArray( A): - i = 0 - while A[i + 1] >= A[i]: - i += 1 - return i","def sample_funcname ( var_0 ) : - var_2 = 0 - while var_0 [ var_2 + 1 ] >= var_0 [ var_2 ] : - var_2 += 1 - return var_2 -",10,2 -41,263_Ugly_Number_2.py,"def isUgly( num): - if num <= 0: - return False - divisors = [2, 3, 5] - for d in divisors: - while num % d == 0: - num /= d - return num == 1","def sample_funcname ( var_0 ) : - if var_0 <= 0 : - return False - var_6 = [ 2 , 3 , 5 ] - for var_7 in var_6 : - while var_0 % var_7 == 0 : - var_0 /= var_7 - return var_0 == 1 -",50213,5 -42,1342_Number_of_Steps_to_Reduce_a_Number_to_Zero_1.py,"def numberOfSteps ( num: int) -> int: - ans = 0 - - while num: - ans += (num & 1) + 1 - num >>= 1 - return ans - 1","def sample_funcname ( var_0 : int ) -> int : - var_3 = 0 - while var_0 : - var_3 += ( var_0 & 1 ) + 1 - var_0 >>= 1 - return var_3 - 1 -",10,2 -43,046_Permutations_1.py,"def permute( nums): - res = [[]] - for i in range(len(nums)): - cache = set() - while len(res[0]) == i: - curr = res.pop(0) - for j in range(len(curr) + 1): - - new_perm = curr[:j] + [nums[i]] + curr[j:] - stemp = ''.join(map(str, new_perm)) - if stemp not in cache: - cache.add(stemp) - res.append(new_perm) - return res","def sample_funcname ( var_0 ) : - var_1 = [ [ ] ] - for var_4 in range ( len ( var_0 ) ) : - var_6 = set ( ) - while len ( var_1 [ 0 ] ) == var_4 : - var_9 = var_1.pop ( 0 ) - for var_11 in range ( len ( var_9 ) + 1 ) : - var_12 = var_9 [ : var_11 ] + [ var_0 [ var_4 ] ] + var_9 [ var_11 : ] - var_17 = ''.join ( map ( str , var_12 ) ) - if var_17 not in var_6 : - var_6.add ( var_17 ) - var_1.append ( var_12 ) - return var_1 -",10,3 -44,090_Subsets_II_1.py,"def get_subsets( nums, magic): - res = [] - for i in range(len(nums)): - if (1 << i) & magic != 0: - res.append(nums[i]) - return res","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - for var_5 in range ( len ( var_0 ) ) : - if ( 1 << var_5 ) & var_1 != 0 : - var_2.append ( var_0 [ var_5 ] ) - return var_2 -",10,2 -45,274_H-Index_3.py,"def hIndex( citations): - ls = len(citations) - papers = [0] * (ls + 1) - for c in citations: - papers[min(ls, c)] += 1 - k, s = ls, papers[ls] - while k > s: - k -= 1 - s += papers[k] - return k","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_5 = [ 0 ] * ( var_2 + 1 ) - for var_6 in var_0 : - var_5 [ min ( var_2 , var_6 ) ] += 1 - var_8 , var_9 = var_2 , var_5 [ var_2 ] - while var_8 > var_9 : - var_8 -= 1 - var_9 += var_5 [ var_8 ] - return var_8 -",10,2 -46,076_Minimum_Window_Substring_1.py,"def minWindow( s, t): - ls_s, ls_t = len(s), len(t) - need_to_find = [0] * 256 - has_found = [0] * 256 - min_begin, min_end = 0, -1 - min_window = 100000000000000 - for index in range(ls_t): - need_to_find[ord(t[index])] += 1 - count, begin = 0, 0 - for end in range(ls_s): - end_index = ord(s[end]) - if need_to_find[end_index] == 0: - continue - has_found[end_index] += 1 - if has_found[end_index] <= need_to_find[end_index]: - count += 1 - if count == ls_t: - begin_index = ord(s[begin]) - while need_to_find[begin_index] == 0 or\ - has_found[begin_index] > need_to_find[begin_index]: - if has_found[begin_index] > need_to_find[begin_index]: - has_found[begin_index] -= 1 - begin += 1 - begin_index = ord(s[begin]) - window_ls = end - begin + 1 - if window_ls < min_window: - min_begin = begin - min_end = end - min_window = window_ls - if count == ls_t: - return s[min_begin: min_end + 1] - else: - return ''","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = len ( var_0 ) , len ( var_1 ) - var_7 = [ 0 ] * 256 - var_8 = [ 0 ] * 256 - var_9 , var_11 = 0 , - 1 - var_13 = 100000000000000 - for var_15 in range ( var_4 ) : - var_7 [ ord ( var_1 [ var_15 ] ) ] += 1 - var_17 , var_18 = 0 , 0 - for var_19 in range ( var_3 ) : - var_20 = ord ( var_0 [ var_19 ] ) - if var_7 [ var_20 ] == 0 : - continue - var_8 [ var_20 ] += 1 - if var_8 [ var_20 ] <= var_7 [ var_20 ] : - var_17 += 1 - if var_17 == var_4 : - var_21 = ord ( var_0 [ var_18 ] ) - while var_7 [ var_21 ] == 0 or var_8 [ var_21 ] > var_7 [ var_21 ] : - if var_8 [ var_21 ] > var_7 [ var_21 ] : - var_8 [ var_21 ] -= 1 - var_18 += 1 - var_21 = ord ( var_0 [ var_18 ] ) - var_22 = var_19 - var_18 + 1 - if var_22 < var_13 : - var_9 = var_18 - var_11 = var_19 - var_13 = var_22 - if var_17 == var_4 : - return var_0 [ var_9 : var_11 + 1 ] - else : - return '' -",02561100000000000000,5 -47,151_Reverse_Words_in_a_String_1.py,"def reverseWords( s): - if len(s) == 0: - return s - temp = s.split(' ') - temp = [t for t in temp if len(t) > 0] - temp = reversed(temp) - return ' '.join(temp)","def sample_funcname ( var_0 ) : - if len ( var_0 ) == 0 : - return var_0 - var_5 = var_0.split ( ' ' ) - var_5 = [ var_6 for var_6 in var_5 if len ( var_6 ) > 0 ] - var_5 = reversed ( var_5 ) - return ' '.join ( var_5 ) -",0 ,2 -48,905_Sort_Array_By_Parity_3.py,"def sortArrayByParity( A): - lo, hi = 0, len(A) - 1 - while lo < hi: - if A[lo] % 2 > A[hi] % 2: - A[lo], A[hi] = A[hi], A[lo] - if A[lo] % 2 == 0: lo += 1 - if A[hi] % 2 == 1: hi -= 1 - return A","def sample_funcname ( var_0 ) : - var_2 , var_5 = 0 , len ( var_0 ) - 1 - while var_2 < var_5 : - if var_0 [ var_2 ] % 2 > var_0 [ var_5 ] % 2 : - var_0 [ var_2 ] , var_0 [ var_5 ] = var_0 [ var_5 ] , var_0 [ var_2 ] - if var_0 [ var_2 ] % 2 == 0 : var_2 += 1 - if var_0 [ var_5 ] % 2 == 1 : var_5 -= 1 - return var_0 -",102,3 -49,217_Contains_Duplicate_1.py,"def containsDuplicate( nums): - return len(nums) != len(set(nums))","def sample_funcname ( var_0 ) : - return len ( var_0 ) != len ( set ( var_0 ) ) -",,0 -50,159_Longest_Substring_with_At_Most_Two_Distinct_Characters_1.py,"def lengthOfLongestSubstringTwoDistinct( s): - i, j, maxLen = 0, -1, 0 - for k in range(1, len(s)): - if s[k] == s[k - 1]: - continue - if j >= 0 and s[j] != s[k]: - maxLen = max(k - i, maxLen) - i = j + 1 - j = k - 1 - return max(len(s) - i, maxLen)","def sample_funcname ( var_0 ) : - var_2 , var_4 , var_5 = 0 , - 1 , 0 - for var_8 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_8 ] == var_0 [ var_8 - 1 ] : - continue - if var_4 >= 0 and var_0 [ var_4 ] != var_0 [ var_8 ] : - var_5 = max ( var_8 - var_2 , var_5 ) - var_2 = var_4 + 1 - var_4 = var_8 - 1 - return max ( len ( var_0 ) - var_2 , var_5 ) -",10,2 -51,416_Partition_Equal_Subset_Sum_2.py,"def canPartition( nums): - total_sum = sum(nums) - if total_sum & 1: - return False - target = total_sum >> 1 - dp = [0] * (target + 1) - dp[0] = 1 - for num in nums: - for i in range(target, num - 1, -1): - dp[i] = dp[i] | dp[i - num] - return dp[target] == 1","def sample_funcname ( var_0 ) : - var_2 = sum ( var_0 ) - if var_2 & 1 : - return False - var_5 = var_2 >> 1 - var_7 = [ 0 ] * ( var_5 + 1 ) - var_7 [ 0 ] = 1 - for var_8 in var_0 : - for var_10 in range ( var_5 , var_8 - 1 , - 1 ) : - var_7 [ var_10 ] = var_7 [ var_10 ] | var_7 [ var_10 - var_8 ] - return var_7 [ var_5 ] == 1 -",10,2 -52,724_Find_Pivot_Index_1.py,"def pivotIndex( nums): - totalsum = sum(nums) - leftsum = 0 - for i, v in enumerate(nums): - if leftsum == totalsum - leftsum - v: - return i - leftsum += v - return -1","def sample_funcname ( var_0 ) : - var_2 = sum ( var_0 ) - var_4 = 0 - for var_6 , var_7 in enumerate ( var_0 ) : - if var_4 == var_2 - var_4 - var_7 : - return var_6 - var_4 += var_7 - return - 1 -",10,2 -53,221_Maximal_Square_2.py,"def maximalSquare( matrix): - if matrix is None or len(matrix) == 0: - return 0 - rows, cols, res = len(matrix), len(matrix[0]), 0 - dp = [[0] * (cols + 1) for _ in range(rows + 1)] - for i in range(1, rows + 1): - for j in range(1, cols + 1): - if matrix[i - 1][j - 1] == '1': - dp[i][j] = min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1 - res = max(res, dp[i][j]) - return res * res","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return 0 - var_4 , var_5 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) , 0 - var_10 = [ [ 0 ] * ( var_5 + 1 ) for var_8 in range ( var_4 + 1 ) ] - for var_11 in range ( 1 , var_4 + 1 ) : - for var_12 in range ( 1 , var_5 + 1 ) : - if var_0 [ var_11 - 1 ] [ var_12 - 1 ] == '1' : - var_10 [ var_11 ] [ var_12 ] = min ( var_10 [ var_11 ] [ var_12 - 1 ] , var_10 [ var_11 - 1 ] [ var_12 ] , var_10 [ var_11 - 1 ] [ var_12 - 1 ] ) + 1 - var_6 = max ( var_6 , var_10 [ var_11 ] [ var_12 ] ) - return var_6 * var_6 -",10None1,4 -54,044_Wildcard_Matching_2.py,"def isMatch( s, p): - s_index, p_index = 0, 0 - star, s_star = -1, 0 - s_len, p_len = len(s), len(p) - while s_index < s_len: - if p_index < p_len and (s[s_index] == p[p_index] or p[p_index] == '?'): - s_index += 1 - p_index += 1 - elif p_index < p_len and p[p_index] == '*': - star = p_index - s_star = s_index - p_index += 1 - elif star != -1: - p_index = star + 1 - s_star += 1 - s_index = s_star - else: - return False - while p_index < p_len and p[p_index] == '*': - p_index += 1 - return p_index == p_len","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = 0 , 0 - var_6 , var_7 = - 1 , 0 - var_9 , var_10 = len ( var_0 ) , len ( var_1 ) - while var_3 < var_9 : - if var_4 < var_10 and ( var_0 [ var_3 ] == var_1 [ var_4 ] or var_1 [ var_4 ] == '?' ) : - var_3 += 1 - var_4 += 1 - elif var_4 < var_10 and var_1 [ var_4 ] == '*' : - var_6 = var_4 - var_7 = var_3 - var_4 += 1 - elif var_6 != - 1 : - var_4 = var_6 + 1 - var_7 += 1 - var_3 = var_7 - else : - return False - while var_4 < var_10 and var_1 [ var_4 ] == '*' : - var_4 += 1 - return var_4 == var_10 -",10*?,4 -55,024_Swap_Nodes_in_Pairs_1.py,"def swapPairs( head): - current = last = last2 = head - while current is not None: - nex = current.next - if current == last.next: - last.next = nex - current.next = last - if last == head: - head = current - else: - last2.next = current - last2 = last - last = nex - current = nex - return head","def sample_funcname ( var_0 ) : - var_3 = var_1 = var_2 = var_0 - while var_3 is not None : - var_6 = var_3.next - if var_3 == var_1.next : - var_1.next = var_6 - var_3.next = var_1 - if var_1 == var_0 : - var_0 = var_3 - else : - var_2.next = var_3 - var_2 = var_1 - var_1 = var_6 - var_3 = var_6 - return var_0 -",None,1 -56,036_Valid Sudoku_2.py,"def isValidSudoku( board): - if board is None: - return True - for i in range(9): - table = {} - for j in range(9): - curr = board[i][j] - if curr == '.': - continue - else: - try: - table[curr] += 1 - return False - except KeyError: - table[curr] = 1 - for j in range(9): - table = {} - for i in range(9): - curr = board[i][j] - if curr == '.': - continue - else: - try: - table[curr] += 1 - return False - except KeyError: - table[curr] = 1 - for i in range(3): - for j in range(3): - table = {} - for k in range(9): - curr = board[i * 3 + k / 3][j * 3 + k % 3] - if curr == '.': - continue - else: - try: - table[curr] += 1 - return False - except KeyError: - table[curr] = 1 - return True","def sample_funcname ( var_0 ) : - if var_0 is None : - return True - for var_5 in range ( 9 ) : - var_6 = { } - for var_7 in range ( 9 ) : - var_8 = var_0 [ var_5 ] [ var_7 ] - if var_8 == '.' : - continue - else : - try : - var_6 [ var_8 ] += 1 - return False - except KeyError : - var_6 [ var_8 ] = 1 - for var_7 in range ( 9 ) : - var_6 = { } - for var_5 in range ( 9 ) : - var_8 = var_0 [ var_5 ] [ var_7 ] - if var_8 == '.' : - continue - else : - try : - var_6 [ var_8 ] += 1 - return False - except KeyError : - var_6 [ var_8 ] = 1 - for var_5 in range ( 3 ) : - for var_7 in range ( 3 ) : - var_6 = { } - for var_14 in range ( 9 ) : - var_8 = var_0 [ var_5 * 3 + var_14 / 3 ] [ var_7 * 3 + var_14 % 3 ] - if var_8 == '.' : - continue - else : - try : - var_6 [ var_8 ] += 1 - return False - except KeyError : - var_6 [ var_8 ] = 1 - return True -",None.193,5 -57,412_Fizz_Buzz_3.py,"def fizzBuzz( n): - return [str(i) * (i % 3 != 0 and i % 5 != 0) + ""Fizz"" * (i % 3 == 0) + ""Buzz"" * (i % 5 == 0) - for i in range(1, n + 1)]","def sample_funcname ( var_0 ) : - return [ str ( var_2 ) * ( var_2 % 3 != 0 and var_2 % 5 != 0 ) + ""Fizz"" * ( var_2 % 3 == 0 ) + ""Buzz"" * ( var_2 % 5 == 0 ) for var_2 in range ( 1 , var_0 + 1 ) ] -",50Fizz1Buzz3,6 -58,068_Text_Justification_2.py,"def fullJustify( words, maxWidth): - i, N, result = 0, len(words), [] - while i < N: - - oneLine, j, currWidth, positionNum, spaceNum = [words[i]], i + 1, len(words[i]), 0, maxWidth - len(words[i]) - while j < N and currWidth + 1 + len(words[j]) <= maxWidth: - oneLine.append(words[j]) - currWidth += 1 + len(words[j]) - spaceNum -= len(words[j]) - positionNum, j = positionNum + 1, j + 1 - i = j - - if i < N and positionNum: - spaces = [' ' * (spaceNum / positionNum + (k < spaceNum % positionNum)) for k in range(positionNum)] + [ - ''] - else: - spaces = [' '] * positionNum + [' ' * (maxWidth - currWidth)] - result.append(''.join([s for pair in zip(oneLine, spaces) for s in pair])) - return result","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_5 , var_6 = 0 , len ( var_0 ) , [ ] - while var_3 < var_5 : - var_7 , var_9 , var_10 , var_11 , var_12 = [ var_0 [ var_3 ] ] , var_3 + 1 , len ( var_0 [ var_3 ] ) , 0 , var_1 - len ( var_0 [ var_3 ] ) - while var_9 < var_5 and var_10 + 1 + len ( var_0 [ var_9 ] ) <= var_1 : - var_7.append ( var_0 [ var_9 ] ) - var_10 += 1 + len ( var_0 [ var_9 ] ) - var_12 -= len ( var_0 [ var_9 ] ) - var_11 , var_9 = var_11 + 1 , var_9 + 1 - var_3 = var_9 - if var_3 < var_5 and var_11 : - var_18 = [ '' * ( var_12 / var_11 + ( var_14 < var_12 % var_11 ) ) for var_14 in range ( var_11 ) ] + [ '' ] - else : - var_18 = [ '' ] * var_11 + [ '' * ( var_1 - var_10 ) ] - var_6.append ( ''.join ( [ var_20 for var_22 in zip ( var_7 , var_18 ) for var_20 in var_22 ] ) ) - return var_6 -",10,3 -59,292_Nim_Game_1.py,"def canWinNim( n): - return n % 4 != 0","def sample_funcname ( var_0 ) : - return var_0 % 4 != 0 -",04,2 -60,126_Word_Ladder_II_2.py,"def construct_paths(begin, end, tree, path, paths): - if begin == end: - paths.append(path) - return - if begin in tree: - for elem in tree[begin]: - construct_paths(elem, end, tree, path + [elem], paths)","def sample_funcname ( var_1 , var_2 , var_3 , var_4 , var_5 ) : - if var_1 == var_2 : - var_5.append ( var_4 ) - return - if var_1 in var_3 : - for var_7 in var_3 [ var_1 ] : - var_0 ( var_7 , var_2 , var_3 , var_4 + [ var_7 ] , var_5 ) -",,0 -61,709_To_Lower_Case_1.py,"def toLowerCase( str): - res = [] - gap = ord('a') - ord('A') - for c in str: - if ord(c) >= ord('A') and ord(c) <= ord('Z'): - res.append(chr(ord(c) + gap)) - else: - res.append(c) - return ''.join(res)","def sample_funcname ( var_0 ) : - var_1 = [ ] - var_5 = ord ( 'a' ) - ord ( 'A' ) - for var_6 in var_0 : - if ord ( var_6 ) >= ord ( 'A' ) and ord ( var_6 ) <= ord ( 'Z' ) : - var_1.append ( chr ( ord ( var_6 ) + var_5 ) ) - else : - var_1.append ( var_6 ) - return ''.join ( var_1 ) -",aAZ,4 -62,219_Contains_Duplicate_II_1.py,"def containsNearbyDuplicate( nums, k): - check = {} - for i in range(len(nums)): - try: - check[nums[i]].append(i) - except: - check[nums[i]] = [i] - - - for _, v in check.items(): - if len(v) >= 2: - pos = 0 - while pos + 1 < len(v): - if v[pos + 1] - v[pos] <= k: - return True - pos += 1 - return False","def sample_funcname ( var_0 , var_1 ) : - var_2 = { } - for var_5 in range ( len ( var_0 ) ) : - try : - var_2 [ var_0 [ var_5 ] ].append ( var_5 ) - except : - var_2 [ var_0 [ var_5 ] ] = [ var_5 ] - for var_8 , var_9 in var_2.items ( ) : - if len ( var_9 ) >= 2 : - var_12 = 0 - while var_12 + 1 < len ( var_9 ) : - if var_9 [ var_12 + 1 ] - var_9 [ var_12 ] <= var_1 : - return True - var_12 += 1 - return False -",102,3 -63,136_Single_Number_2.py,"def singleNumber( nums): - s = set() - for num in nums: - if num in s: - s.remove(num) - else: - s.add(num) - return s.pop()","def sample_funcname ( var_0 ) : - var_2 = set ( ) - for var_3 in var_0 : - if var_3 in var_2 : - var_2.remove ( var_3 ) - else : - var_2.add ( var_3 ) - return var_2.pop ( ) -",,0 -64,326_Power_of_Three_2.py,"def isPowerOfThree( n): - max3pow = 1162261467 - if n <= 0 or n > max3pow: - return False - return max3pow % n == 0","def sample_funcname ( var_0 ) : - var_2 = 1162261467 - if var_0 <= 0 or var_0 > var_2 : - return False - return var_2 % var_0 == 0 -",11622614670,2 -66,345_Reverse_Vowels_of_a_String_1.py,"def reverseVowels( s): - str_index = [] - vowel = [] - res = [] - pos = -1 - for index, value in enumerate(s): - if value in 'aeiouAEIOU': - str_index.append(-1) - vowel.append(value) - else: - str_index.append(index) - for index in str_index: - if index < 0: - res.append(vowel[pos]) - pos -= 1 - else: - res.append(s[index]) - return ''.join(res)","def sample_funcname ( var_0 ) : - var_1 = [ ] - var_2 = [ ] - var_3 = [ ] - var_5 = - 1 - for var_7 , var_8 in enumerate ( var_0 ) : - if var_8 in 'aeiouAEIOU' : - var_1.append ( - 1 ) - var_2.append ( var_8 ) - else : - var_1.append ( var_7 ) - for var_7 in var_1 : - if var_7 < 0 : - var_3.append ( var_2 [ var_5 ] ) - var_5 -= 1 - else : - var_3.append ( var_0 [ var_7 ] ) - return ''.join ( var_3 ) -",1aeiouAEIOU0,4 -67,299_Bulls_and_Cows_1.py,"def getHint( secret, guess): - check = {} - ls = len(secret) - bull, cow = 0, 0 - different = [] - for i in range(ls): - if guess[i] == secret[i]: - bull += 1 - else: - different.append(i) - try: - check[secret[i]] += 1 - except KeyError: - check[secret[i]] = 1 - for i in different: - try: - if check[guess[i]] > 0: - cow += 1 - check[guess[i]] -= 1 - except: - pass - return ""%dA%dB"" % (bull, cow)","def sample_funcname ( var_0 , var_1 ) : - var_2 = { } - var_4 = len ( var_0 ) - var_6 , var_7 = 0 , 0 - var_8 = [ ] - for var_10 in range ( var_4 ) : - if var_1 [ var_10 ] == var_0 [ var_10 ] : - var_6 += 1 - else : - var_8.append ( var_10 ) - try : - var_2 [ var_0 [ var_10 ] ] += 1 - except KeyError : - var_2 [ var_0 [ var_10 ] ] = 1 - for var_10 in var_8 : - try : - if var_2 [ var_1 [ var_10 ] ] > 0 : - var_7 += 1 - var_2 [ var_1 [ var_10 ] ] -= 1 - except : - pass - return ""%dA%dB"" % ( var_6 , var_7 ) -",10%dA%dB,3 -68,213_House_Robber_II_2.py,"def rob_helper( nums, low, high): - prevMax = currMax = 0 - for index in range(low, high + 1): - temp = currMax - currMax = max(prevMax + nums[index], currMax) - prevMax = temp - return currMax","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_5 = var_3 = 0 - for var_8 in range ( var_1 , var_2 + 1 ) : - var_9 = var_3 - var_3 = max ( var_5 + var_0 [ var_8 ] , var_3 ) - var_5 = var_9 - return var_3 -",10,2 -69,205_Isomorphic_Strings_1.py,"def isIsomorphic( s, t): - if len(s) != len(t): - return False - check = [False] * len(s) - for i in range(len(s)): - if check[i]: - continue - temp = s.count(s[i]) - if temp != t.count(t[i]): - return False - if temp >= 2: - for j in range(i + 1, len(s)): - if s[j] == s[i]: - check[j] = True - if t[j] != t[i]: - return False - check[i] = True - return True","def sample_funcname ( var_0 , var_1 ) : - if len ( var_0 ) != len ( var_1 ) : - return False - var_4 = [ False ] * len ( var_0 ) - for var_6 in range ( len ( var_0 ) ) : - if var_4 [ var_6 ] : - continue - var_8 = var_0.count ( var_0 [ var_6 ] ) - if var_8 != var_1.count ( var_1 [ var_6 ] ) : - return False - if var_8 >= 2 : - for var_11 in range ( var_6 + 1 , len ( var_0 ) ) : - if var_0 [ var_11 ] == var_0 [ var_6 ] : - var_4 [ var_11 ] = True - if var_1 [ var_11 ] != var_1 [ var_6 ] : - return False - var_4 [ var_6 ] = True - return True -",12,2 -71,228_Summary_Ranges_1.py,"def summaryRanges( nums): - if nums is None or len(nums) == 0: - return [] - res = [] - start, prev, ls = nums[0], nums[0], len(nums) - for i in range(ls): - curr = nums[i] - if curr - prev > 1: - if start == prev: - res.append(""%d"" % start) - else: - res.append(""%d->%d"" % (start, prev)) - start = curr - prev = curr - if start == prev: - res.append(""%d"" % start) - else: - res.append(""%d->%d"" % (start, prev)) - return res","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return [ ] - var_4 = [ ] - var_5 , var_6 , var_7 = var_0 [ 0 ] , var_0 [ 0 ] , len ( var_0 ) - for var_9 in range ( var_7 ) : - var_10 = var_0 [ var_9 ] - if var_10 - var_6 > 1 : - if var_5 == var_6 : - var_4.append ( ""%d"" % var_5 ) - else : - var_4.append ( ""%d->%d"" % ( var_5 , var_6 ) ) - var_5 = var_10 - var_6 = var_10 - if var_5 == var_6 : - var_4.append ( ""%d"" % var_5 ) - else : - var_4.append ( ""%d->%d"" % ( var_5 , var_6 ) ) - return var_4 -",0None%d->%d1%d,5 -72,557_Reverse_Words_in_a_String_III_1.py,"def reverseWords( s): - return ' '.join([word[::-1] for word in s.split(' ')])","def sample_funcname ( var_0 ) : - return ' '.join ( [ var_3 [ : : - 1 ] for var_3 in var_0.split ( ' ' ) ] ) -",1 ,2 -73,274_H-Index_2.py,"def hIndex( citations): - citations.sort() - i = 0 - while i < len(citations) and citations[len(citations) - 1 - i] > i: - i += 1 - return i","def sample_funcname ( var_0 ) : - var_0.sort ( ) - var_3 = 0 - while var_3 < len ( var_0 ) and var_0 [ len ( var_0 ) - 1 - var_3 ] > var_3 : - var_3 += 1 - return var_3 -",10,2 -75,368_Largest_Divisible_Subset_2.py,"def largestDivisibleSubset( nums): - ls = len(nums) - S = {-1: set()} - for num in sorted(nums): - candicate = [] - for key in S: - if num % key == 0: - candicate.append(S[key]) - S[num] = max(candicate, key=len) | {num} - return","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_5 = { - 1 : set ( ) } - for var_7 in sorted ( var_0 ) : - var_8 = [ ] - for var_9 in var_5 : - if var_7 % var_9 == 0 : - var_8.append ( var_5 [ var_9 ] ) - var_5 [ var_7 ] = max ( var_8 , var_9 = len ) | { var_7 } - return -",10,2 -76,093_Restore_IP_Addresses_1.py,"def isNum( prefix): - curr = int(prefix) - if curr > 255: - return False - if len(prefix) == 1: - return True - if prefix[0] == '0': - return False - return True","def sample_funcname ( var_0 ) : - var_2 = int ( var_0 ) - if var_2 > 255 : - return False - if len ( var_0 ) == 1 : - return True - if var_0 [ 0 ] == '0' : - return False - return True -",102550,4 -77,905_Sort_Array_By_Parity_2.py,"def sortArrayByParity( A): - return ([x for x in A if x % 2 == 0] + - [x for x in A if x % 2 == 1])","def sample_funcname ( var_0 ) : - return ( [ var_1 for var_1 in var_0 if var_1 % 2 == 0 ] + [ var_1 for var_1 in var_0 if var_1 % 2 == 1 ] ) -",102,3 -78,280_Wiggle_Sort_4.py,"def wiggleSort( nums): - for i in range(len(nums) - 1): - if (i % 2 == 0 and nums[i] > nums[i + 1]) or\ - (i % 2 == 1 and nums[i] < nums[i + 1]): - nums[i], nums[i + 1] = nums[i + 1], nums[i]","def sample_funcname ( var_0 ) : - for var_4 in range ( len ( var_0 ) - 1 ) : - if ( var_4 % 2 == 0 and var_0 [ var_4 ] > var_0 [ var_4 + 1 ] ) or ( var_4 % 2 == 1 and var_0 [ var_4 ] < var_0 [ var_4 + 1 ] ) : - var_0 [ var_4 ] , var_0 [ var_4 + 1 ] = var_0 [ var_4 + 1 ] , var_0 [ var_4 ] -",102,3 -79,387_First_Unique_Character_in_a_String_1.py,"def firstUniqChar( s): - count_map = {} - for c in s: - count_map[c] = count_map.get(c, 0) + 1 - for i, c in enumerate(s): - if count_map[c] == 1: - return i - return -1","def sample_funcname ( var_0 ) : - var_1 = { } - for var_2 in var_0 : - var_1 [ var_2 ] = var_1.get ( var_2 , 0 ) + 1 - for var_7 , var_2 in enumerate ( var_0 ) : - if var_1 [ var_2 ] == 1 : - return var_7 - return - 1 -",10,2 -80,276_Paint_Fence_1.py,"def numWays( n, k): - w = [0, k, k*k] - while len(w) <= n: - w += sum(w[-2:]) * (k-1), - return w[n]","def sample_funcname ( var_0 , var_1 ) : - var_3 = [ 0 , var_1 , var_1 * var_1 ] - while len ( var_3 ) <= var_0 : - var_3 += sum ( var_3 [ - 2 : ] ) * ( var_1 - 1 ) , - return var_3 [ var_0 ] -",102,3 -81,242_Valid_Anagram_2.py,"def isAnagram( s, t): - if len(s) != len(t): - return False - counter = [0] * 26 - for i in range(len(s)): - counter[ord(s[i]) - ord('a')] += 1 - counter[ord(t[i]) - ord('a')] -= 1 - for num in counter: - if num != 0: - return False - return True","def sample_funcname ( var_0 , var_1 ) : - if len ( var_0 ) != len ( var_1 ) : - return False - var_6 = [ 0 ] * 26 - for var_8 in range ( len ( var_0 ) ) : - var_6 [ ord ( var_0 [ var_8 ] ) - ord ( 'a' ) ] += 1 - var_6 [ ord ( var_1 [ var_8 ] ) - ord ( 'a' ) ] -= 1 - for var_12 in var_6 : - if var_12 != 0 : - return False - return True -",a0126,4 -82,733_Flood_Fill_2.py,"def floodFill( image, sr, sc, newColor): - r_ls, c_ls = len(image), len(image[0]) - color = image[sr][sc] - if color == newColor: - return image - queue = [(sr, sc)] - while len(queue) > 0: - r, c = queue.pop(0) - if image[r][c] == color: - image[r][c] = newColor - if r - 1 >= 0: queue.append((r - 1, c)) - if r + 1 < r_ls: queue.append((r + 1, c)) - if c - 1 >= 0: queue.append((r, c - 1)) - if c + 1 < c_ls: queue.append((r, c + 1)) - return image","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - var_5 , var_7 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_8 = var_0 [ var_1 ] [ var_2 ] - if var_8 == var_3 : - return var_0 - var_9 = [ ( var_1 , var_2 ) ] - while len ( var_9 ) > 0 : - var_11 , var_12 = var_9.pop ( 0 ) - if var_0 [ var_11 ] [ var_12 ] == var_8 : - var_0 [ var_11 ] [ var_12 ] = var_3 - if var_11 - 1 >= 0 : var_9.append ( ( var_11 - 1 , var_12 ) ) - if var_11 + 1 < var_5 : var_9.append ( ( var_11 + 1 , var_12 ) ) - if var_12 - 1 >= 0 : var_9.append ( ( var_11 , var_12 - 1 ) ) - if var_12 + 1 < var_7 : var_9.append ( ( var_11 , var_12 + 1 ) ) - return var_0 -",10,2 -83,145_Binary_Tree_Postorder_Traversal_1.py,"def postorderTraversal( root): - if root is None: - return [] - res = [] - stack = [root] - while len(stack) > 0: - curr = stack.pop() - res.insert(0, curr.val) - if curr.left is not None: - stack.append(curr.left) - if curr.right is not None: - stack.append(curr.right) - return res","def sample_funcname ( var_0 ) : - if var_0 is None : - return [ ] - var_2 = [ ] - var_3 = [ var_0 ] - while len ( var_3 ) > 0 : - var_7 = var_3.pop ( ) - var_2.insert ( 0 , var_7.val ) - if var_7.left is not None : - var_3.append ( var_7.left ) - if var_7.right is not None : - var_3.append ( var_7.right ) - return var_2 -",0None,2 -84,665_Non-decreasing_Array_1.py,"def checkPossibility( nums): - pos = None - - - for i in range(len(nums) - 1): - if nums[i] > nums[i + 1]: - if pos is not None: - return False - pos = i - if pos is None or pos == 0 or pos == len(nums) - 2: - return True - - return (nums[pos - 1] <= nums[pos + 1] or nums[pos] <= nums[pos + 2])","def sample_funcname ( var_0 ) : - var_2 = None - for var_6 in range ( len ( var_0 ) - 1 ) : - if var_0 [ var_6 ] > var_0 [ var_6 + 1 ] : - if var_2 is not None : - return False - var_2 = var_6 - if var_2 is None or var_2 == 0 or var_2 == len ( var_0 ) - 2 : - return True - return ( var_0 [ var_2 - 1 ] <= var_0 [ var_2 + 1 ] or var_0 [ var_2 ] <= var_0 [ var_2 + 2 ] ) -",1None02,4 -85,129_Sum_Root_to_Leaf_Numbers_1.py,"def sumNumbers( root): - if root is None: - return 0 - res = 0 - queue = [(root, root.val)] - while len(queue) > 0: - curr, curr_value = queue.pop(0) - if curr.left is None and curr.right is None: - res += curr_value - continue - if curr.left: - queue.append((curr.left, curr_value * 10 + curr.left.val)) - if curr.right: - queue.append((curr.right, curr_value * 10 + curr.right.val)) - return res","def sample_funcname ( var_0 ) : - if var_0 is None : - return 0 - var_3 = 0 - var_5 = [ ( var_0 , var_0.val ) ] - while len ( var_5 ) > 0 : - var_8 , var_9 = var_5.pop ( 0 ) - if var_8.left is None and var_8.right is None : - var_3 += var_9 - continue - if var_8.left : - var_5.append ( ( var_8.left , var_9 * 10 + var_8.left.val ) ) - if var_8.right : - var_5.append ( ( var_8.right , var_9 * 10 + var_8.right.val ) ) - return var_3 -",100None,3 -86,094_Binary_Tree_Inorder_Traversal_2.py,"def inorderTraversal( root): - res = [] - stack = [] - while root is not None: - stack.append(root) - root = root.left - while root is None: - if len(stack) == 0: - return res - root = stack.pop() - res.append(root.val) - root = root.right - return res","def sample_funcname ( var_0 ) : - var_1 = [ ] - var_2 = [ ] - while var_0 is not None : - var_2.append ( var_0 ) - var_0 = var_0.left - while var_0 is None : - if len ( var_2 ) == 0 : - return var_1 - var_0 = var_2.pop ( ) - var_1.append ( var_0.val ) - var_0 = var_0.right - return var_1 -",0None,2 -87,448_Find_All_Numbers_Disappeared_in_an_Array_1.py,"def findDisappearedNumbers( nums): - res = [] - if nums: - n = len(nums) - for i in range(n): - val = abs(nums[i]) - 1 - if nums[val] > 0: - nums[val] = -nums[val] - for i in range(n): - if nums[i] > 0: - res.append(i + 1) - return res","def sample_funcname ( var_0 ) : - var_1 = [ ] - if var_0 : - var_3 = len ( var_0 ) - for var_5 in range ( var_3 ) : - var_8 = abs ( var_0 [ var_5 ] ) - 1 - if var_0 [ var_8 ] > 0 : - var_0 [ var_8 ] = - var_0 [ var_8 ] - for var_5 in range ( var_3 ) : - if var_0 [ var_5 ] > 0 : - var_1.append ( var_5 + 1 ) - return var_1 -",10,2 -88,674_Longest_Continuous_Increasing_Subsequence_1.py,"def findLengthOfLCIS( nums): - if not nums or len(nums) == 0: - return 0 - ans = curr = 1 - for i in range(len(nums) - 1): - if nums[i] < nums[i + 1]: - curr += 1 - ans = max(ans, curr) - else: - curr = 1 - return ans","def sample_funcname ( var_0 ) : - if not var_0 or len ( var_0 ) == 0 : - return 0 - var_5 = var_3 = 1 - for var_7 in range ( len ( var_0 ) - 1 ) : - if var_0 [ var_7 ] < var_0 [ var_7 + 1 ] : - var_3 += 1 - var_5 = max ( var_5 , var_3 ) - else : - var_3 = 1 - return var_5 -",10,2 -89,062_Unique_Paths_1.py,"def uniquePaths( m, n): - dmap = [[0] * n for _ in range(m)] - for i in range(m): - dmap[i][0] = 1 - for j in range(n): - dmap[0][j] = 1 - for i in range(1, m): - for j in range(1, n): - l = u = 0 - if i-1 >= 0: - u = dmap[i-1][j] - if j-1>= 0: - l = dmap[i][j-1] - dmap[i][j] = l + u - return dmap[m-1][n-1]","def sample_funcname ( var_0 , var_1 ) : - var_5 = [ [ 0 ] * var_1 for var_3 in range ( var_0 ) ] - for var_6 in range ( var_0 ) : - var_5 [ var_6 ] [ 0 ] = 1 - for var_8 in range ( var_1 ) : - var_5 [ 0 ] [ var_8 ] = 1 - for var_6 in range ( 1 , var_0 ) : - for var_8 in range ( 1 , var_1 ) : - var_10 = var_9 = 0 - if var_6 - 1 >= 0 : - var_9 = var_5 [ var_6 - 1 ] [ var_8 ] - if var_8 - 1 >= 0 : - var_10 = var_5 [ var_6 ] [ var_8 - 1 ] - var_5 [ var_6 ] [ var_8 ] = var_10 + var_9 - return var_5 [ var_0 - 1 ] [ var_1 - 1 ] -",10,2 -90,031_Next_Permutation_2.py,"def re_order( a, start, end): - for i in range(0, (end - start + 1) // 2): - a[start + i], a[end - i] = a[end - i], a[start + i]","def sample_funcname ( var_0 , var_1 , var_2 ) : - for var_7 in range ( 0 , ( var_2 - var_1 + 1 ) // 2 ) : - var_0 [ var_1 + var_7 ] , var_0 [ var_2 - var_7 ] = var_0 [ var_2 - var_7 ] , var_0 [ var_1 + var_7 ] -",102,3 -91,438_Find_All_Anagrams_in_a_String_1.py,"def findAnagrams( s, p): - res = [] - if s is None or p is None or len(s) == 0 or len(p) == 0: - return res - char_map = [0] * 256 - for c in p: - char_map[ord(c)] += 1 - left, right, count = 0, 0, len(p) - while right < len(s): - if char_map[ord(s[right])] >= 1: - count -= 1 - char_map[ord(s[right])] -= 1 - right += 1 - if count == 0: - res.append(left) - if right - left == len(p): - if char_map[ord(s[left])] >= 0: - count += 1 - char_map[ord(s[left])] += 1 - left += 1 - return res","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - if var_0 is None or var_1 is None or len ( var_0 ) == 0 or len ( var_1 ) == 0 : - return var_2 - var_7 = [ 0 ] * 256 - for var_8 in var_1 : - var_7 [ ord ( var_8 ) ] += 1 - var_11 , var_12 , var_13 = 0 , 0 , len ( var_1 ) - while var_12 < len ( var_0 ) : - if var_7 [ ord ( var_0 [ var_12 ] ) ] >= 1 : - var_13 -= 1 - var_7 [ ord ( var_0 [ var_12 ] ) ] -= 1 - var_12 += 1 - if var_13 == 0 : - var_2.append ( var_11 ) - if var_12 - var_11 == len ( var_1 ) : - if var_7 [ ord ( var_0 [ var_11 ] ) ] >= 0 : - var_13 += 1 - var_7 [ ord ( var_0 [ var_11 ] ) ] += 1 - var_11 += 1 - return var_2 -",10None256,4 -92,560_Subarray_Sum_Equals_K_1.py,"def subarraySum( nums, k): - sum_map = {} - sum_map[0] = 1 - count = curr_sum = 0 - for num in nums: - curr_sum += num - count += sum_map.get(curr_sum - k, 0) - sum_map[curr_sum] = sum_map.get(curr_sum, 0) + 1 - return count","def sample_funcname ( var_0 , var_1 ) : - var_2 = { } - var_2 [ 0 ] = 1 - var_6 = var_5 = 0 - for var_7 in var_0 : - var_5 += var_7 - var_6 += var_2.get ( var_5 - var_1 , 0 ) - var_2 [ var_5 ] = var_2.get ( var_5 , 0 ) + 1 - return var_6 -",10,2 -93,154_Find_Minimum_in_Rotated_Sorted_Array_II_2.py,"def findMin( nums): - l, r = 0, len(nums) - 1 - while l < r and nums[l] >= nums[r]: - mid = (l + r) / 2 - if nums[mid] > nums[r]: - l = mid + 1 - elif nums[mid] < nums[l]: - r = mid - else: - l += 1 - return nums[l]","def sample_funcname ( var_0 ) : - var_2 , var_5 = 0 , len ( var_0 ) - 1 - while var_2 < var_5 and var_0 [ var_2 ] >= var_0 [ var_5 ] : - var_7 = ( var_2 + var_5 ) / 2 - if var_0 [ var_7 ] > var_0 [ var_5 ] : - var_2 = var_7 + 1 - elif var_0 [ var_7 ] < var_0 [ var_2 ] : - var_5 = var_7 - else : - var_2 += 1 - return var_0 [ var_2 ] -",102,3 -94,868_Binary_Gap_2.py,"def binaryGap( n: int) -> int: - res = 0 - last = -1 - - for i, curr in enumerate(bin(n)[2:]): - if curr == '1': - if last >= 0: - res = max(res, i - last) - last = i - return res","def sample_funcname ( var_0 : int ) -> int : - var_3 = 0 - var_5 = - 1 - for var_7 , var_10 in enumerate ( bin ( var_0 ) [ 2 : ] ) : - if var_10 == '1' : - if var_5 >= 0 : - var_3 = max ( var_3 , var_7 - var_5 ) - var_5 = var_7 - return var_3 -",1021,4 -95,415_Add_Strings_1.py,"def addStrings( num1, num2): - if num1 is None: - num1 = '0' - if num2 is None: - num2 = '0' - res = [] - carry = 0 - ls = min(len(num1), len(num2)) - pos = -1 - while pos + ls >= 0: - curr = int(num1[pos]) + int(num2[pos]) + carry - res.insert(0, str(curr % 10)) - carry = curr / 10 - pos -= 1 - while pos + len(num1) >= 0: - curr = int(num1[pos]) + carry - res.insert(0, str(curr % 10)) - carry = curr / 10 - pos -= 1 - while pos + len(num2) >= 0: - curr = int(num2[pos]) + carry - res.insert(0, str(curr % 10)) - carry = curr / 10 - pos -= 1 - if carry != 0: - res.insert(0, str(carry)) - return ''.join(res)","def sample_funcname ( var_0 , var_1 ) : - if var_0 is None : - var_0 = '0' - if var_1 is None : - var_1 = '0' - var_4 = [ ] - var_6 = 0 - var_9 = min ( len ( var_0 ) , len ( var_1 ) ) - var_11 = - 1 - while var_11 + var_9 >= 0 : - var_13 = int ( var_0 [ var_11 ] ) + int ( var_1 [ var_11 ] ) + var_6 - var_4.insert ( 0 , str ( var_13 % 10 ) ) - var_6 = var_13 / 10 - var_11 -= 1 - while var_11 + len ( var_0 ) >= 0 : - var_13 = int ( var_0 [ var_11 ] ) + var_6 - var_4.insert ( 0 , str ( var_13 % 10 ) ) - var_6 = var_13 / 10 - var_11 -= 1 - while var_11 + len ( var_1 ) >= 0 : - var_13 = int ( var_1 [ var_11 ] ) + var_6 - var_4.insert ( 0 , str ( var_13 % 10 ) ) - var_6 = var_13 / 10 - var_11 -= 1 - if var_6 != 0 : - var_4.insert ( 0 , str ( var_6 ) ) - return ''.join ( var_4 ) -",100None01,6 -96,344_Reverse_String_1.py,"def reverseString( s): - return s[::-1]","def sample_funcname ( var_0 ) : - return var_0 [ : : - 1 ] -",1,1 -97,929_Unique_Email_Addresses_1.py,"def numUniqueEmails( emails): - email_set = set() - for email in emails: - elements = email.split('@') - email_set.add(elements[0].split('+')[0].replace('.', '') + elements[1]) - return len(email_set)","def sample_funcname ( var_0 ) : - var_2 = set ( ) - for var_3 in var_0 : - var_6 = var_3.split ( '@' ) - var_2.add ( var_6 [ 0 ].split ( '+' ) [ 0 ].replace ( '.' , '' ) + var_6 [ 1 ] ) - return len ( var_2 ) -",@0+.1,6 -98,042_Trapping_Rain_Water_2.py,"def trap( height): - ls = len(height) - if ls == 0: - return 0 - height.append(0) - height.insert(0, 0) - left = [0] * ls - right = [0] * ls - cur_left, cur_right = 0, 0 - for i in range(1, ls + 1): - cur_left = max(cur_left, height[i - 1]) - - left[i - 1] = cur_left - for i in reversed(range(ls)): - cur_right = max(cur_right, height[i + 1]) - - right[i] = cur_right - res = 0 - for i in range(ls): - curr = min(left[i], right[i]) - if curr > height[i]: - res += curr - height[i] - return res","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - if var_2 == 0 : - return 0 - var_0.append ( 0 ) - var_0.insert ( 0 , 0 ) - var_6 = [ 0 ] * var_2 - var_7 = [ 0 ] * var_2 - var_8 , var_9 = 0 , 0 - for var_12 in range ( 1 , var_2 + 1 ) : - var_8 = max ( var_8 , var_0 [ var_12 - 1 ] ) - var_6 [ var_12 - 1 ] = var_8 - for var_12 in reversed ( range ( var_2 ) ) : - var_9 = max ( var_9 , var_0 [ var_12 + 1 ] ) - var_7 [ var_12 ] = var_9 - var_15 = 0 - for var_12 in range ( var_2 ) : - var_17 = min ( var_6 [ var_12 ] , var_7 [ var_12 ] ) - if var_17 > var_0 [ var_12 ] : - var_15 += var_17 - var_0 [ var_12 ] - return var_15 -",10,2 -99,006_ZigZag_Conversion_1.py,"def convert( s, numRows): - ls = len(s) - if ls <= 1 or numRows == 1: - return s - temp_s = [] - for i in range(numRows): - temp_s.append(['']*(ls / 2)) - inter = numRows - 1 - col, row = 0, 0 - for i, ch in enumerate(s): - flag = True - if (i / inter) % 2 == 1: - - flag = False - if flag: - temp_s[row][col] = ch - row += 1 - else: - temp_s[row][col] = ch - col += 1 - row -= 1 - result = '' - for i in range(numRows): - result += ''.join(temp_s[i]) - return result","def sample_funcname ( var_0 , var_1 ) : - var_3 = len ( var_0 ) - if var_3 <= 1 or var_1 == 1 : - return var_0 - var_5 = [ ] - for var_7 in range ( var_1 ) : - var_5.append ( [ '' ] * ( var_3 / 2 ) ) - var_11 = var_1 - 1 - var_13 , var_14 = 0 , 0 - for var_7 , var_16 in enumerate ( var_0 ) : - var_18 = True - if ( var_7 / var_11 ) % 2 == 1 : - var_18 = False - if var_18 : - var_5 [ var_14 ] [ var_13 ] = var_16 - var_14 += 1 - else : - var_5 [ var_14 ] [ var_13 ] = var_16 - var_13 += 1 - var_14 -= 1 - var_20 = '' - for var_7 in range ( var_1 ) : - var_20 += ''.join ( var_5 [ var_7 ] ) - return var_20 -",102,4 -100,367_Valid_Perfect_Square_1.py,"def isPerfectSquare( num): - i = 1 - while num > 0: - num -= i - i += 2 - return num == 0","def sample_funcname ( var_0 ) : - var_2 = 1 - while var_0 > 0 : - var_0 -= var_2 - var_2 += 2 - return var_0 == 0 -",102,3 -101,198_House_Robber_1.py,"def rob( nums): - ls = len(nums) - if ls == 0: - return 0 - dp = [0] * ls - dp[0] = nums[0] - for i in range(1, ls): - if i < 2: - dp[i] = max(nums[i], dp[i - 1]) - else: - dp[i] = max(dp[i - 2] + nums[i], dp[i - 1]) - return dp[ls - 1]","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - if var_2 == 0 : - return 0 - var_4 = [ 0 ] * var_2 - var_4 [ 0 ] = var_0 [ 0 ] - for var_7 in range ( 1 , var_2 ) : - if var_7 < 2 : - var_4 [ var_7 ] = max ( var_0 [ var_7 ] , var_4 [ var_7 - 1 ] ) - else : - var_4 [ var_7 ] = max ( var_4 [ var_7 - 2 ] + var_0 [ var_7 ] , var_4 [ var_7 - 1 ] ) - return var_4 [ var_2 - 1 ] -",102,3 -102,009_Palindrome_Number_3.py,"def isPalindrome( x): - if x < 0: - return False - div = 1 - while x / div >= 10: - div *= 10 - while x != 0: - left = x / div - right = x % 10 - if left != right: - return False - x = (x % div) / 10 - div /= 100 - return True","def sample_funcname ( var_0 ) : - if var_0 < 0 : - return False - var_4 = 1 - while var_0 / var_4 >= 10 : - var_4 *= 10 - while var_0 != 0 : - var_6 = var_0 / var_4 - var_7 = var_0 % 10 - if var_6 != var_7 : - return False - var_0 = ( var_0 % var_4 ) / 10 - var_4 /= 100 - return True -",1010010,4 -103,086_Partition_List_1.py,"def partition( head, x): - if head is None: - return None - less = lesshead = None - last = pos = head - while pos is not None: - if pos.val < x: - if lesshead is None: - lesshead = pos - else: - less.next = pos - less = pos - if head == pos: - last = head = pos.next - else: - last.next = pos.next - else: - last = pos - pos = pos.next - if lesshead is not None: - less.next = head - else: - lesshead = head - return lesshead","def sample_funcname ( var_0 , var_1 ) : - if var_0 is None : - return None - var_4 = var_3 = None - var_6 = var_5 = var_0 - while var_5 is not None : - if var_5.val < var_1 : - if var_3 is None : - var_3 = var_5 - else : - var_4.next = var_5 - var_4 = var_5 - if var_0 == var_5 : - var_6 = var_0 = var_5.next - else : - var_6.next = var_5.next - else : - var_6 = var_5 - var_5 = var_5.next - if var_3 is not None : - var_4.next = var_0 - else : - var_3 = var_0 - return var_3 -",None,1 -104,123_Best_Time_to_Buy_and_Sell_Stock_III_1.py,"def maxProfit( prices): - ls = len(prices) - if ls == 0: - return 0 - num_t, max_profit = 2, 0 - dp = [[0] * ls for _ in range(num_t + 1)] - for t in range(1, num_t + 1): - tempMax = dp[t - 1][0] - prices[0] - for i in range(1, ls): - dp[t][i] = max(dp[t][i - 1], prices[i] + tempMax) - tempMax = max(tempMax, dp[t - 1][i] - prices[i]) - max_profit = max(dp[t][i], max_profit) - return max_profit","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - if var_2 == 0 : - return 0 - var_5 , var_6 = 2 , 0 - var_10 = [ [ 0 ] * var_2 for var_7 in range ( var_5 + 1 ) ] - for var_11 in range ( 1 , var_5 + 1 ) : - var_12 = var_10 [ var_11 - 1 ] [ 0 ] - var_0 [ 0 ] - for var_13 in range ( 1 , var_2 ) : - var_10 [ var_11 ] [ var_13 ] = max ( var_10 [ var_11 ] [ var_13 - 1 ] , var_0 [ var_13 ] + var_12 ) - var_12 = max ( var_12 , var_10 [ var_11 - 1 ] [ var_13 ] - var_0 [ var_13 ] ) - var_6 = max ( var_10 [ var_11 ] [ var_13 ] , var_6 ) - return var_6 -",102,3 -105,294_Flip_Game_II_2.py,"def firstMissingNumber(lut): - ls = len(lut) - for i in range(ls): - if i not in lut: - return i - return ls","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - for var_4 in range ( var_2 ) : - if var_4 not in var_0 : - return var_4 - return var_2 -",,0 -106,904_Fruit_Into_Baskets_1.py,"def totalFruit( tree): - basket, res, start = 2, 0, 0 - queue_map = {} - for i, v in enumerate(tree): - queue_map[v] = queue_map.get(v, 0) + 1 - if len(queue_map) > 2: - queue_map[tree[start]] -= 1 - if queue_map[tree[start]] == 0: - del queue_map[tree[start]] - start += 1 - res = max(res, i - start + 1) - return res","def sample_funcname ( var_0 ) : - var_2 , var_4 , var_5 = 2 , 0 , 0 - var_6 = { } - for var_8 , var_9 in enumerate ( var_0 ) : - var_6 [ var_9 ] = var_6.get ( var_9 , 0 ) + 1 - if len ( var_6 ) > 2 : - var_6 [ var_0 [ var_5 ] ] -= 1 - if var_6 [ var_0 [ var_5 ] ] == 0 : - del var_6 [ var_0 [ var_5 ] ] - var_5 += 1 - var_4 = max ( var_4 , var_8 - var_5 + 1 ) - return var_4 -",102,3 -107,053_Maximum_Subarray_3.py,"def maxSubArray( nums): - maxEndingHere = maxSofFar = nums[0] - for i in range(1, len(nums)): - maxEndingHere = max(maxEndingHere + nums[i], nums[i]) - maxSofFar = max(maxEndingHere, maxSofFar) - return maxSofFar","def sample_funcname ( var_0 ) : - var_3 = var_1 = var_0 [ 0 ] - for var_7 in range ( 1 , len ( var_0 ) ) : - var_3 = max ( var_3 + var_0 [ var_7 ] , var_0 [ var_7 ] ) - var_1 = max ( var_3 , var_1 ) - return var_1 -",10,2 -108,751_IP_to_CIDR_1.py,"def ipToInt( ip): - ans = 0 - for x in ip.split('.'): - ans = 256 * ans + int(x) - return ans","def sample_funcname ( var_0 ) : - var_2 = 0 - for var_5 in var_0.split ( '.' ) : - var_2 = 256 * var_2 + int ( var_5 ) - return var_2 -",0.256,3 -109,032_Longest_Valid_Parentheses_2.py,"def longestValidParentheses( s): - ls = len(s) - stack = [] - data = [0] * ls - for i in range(ls): - curr = s[i] - if curr == '(': - stack.append(i) - else: - if len(stack) > 0: - data[i] = 1 - data[stack.pop(-1)] = 1 - tep, res = 0, 0 - for t in data: - if t == 1: - tep += 1 - else: - res = max(tep, res) - tep = 0 - return max(tep, res)","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_3 = [ ] - var_5 = [ 0 ] * var_2 - for var_7 in range ( var_2 ) : - var_8 = var_0 [ var_7 ] - if var_8 == '(' : - var_3.append ( var_7 ) - else : - if len ( var_3 ) > 0 : - var_5 [ var_7 ] = 1 - var_5 [ var_3.pop ( - 1 ) ] = 1 - var_13 , var_14 = 0 , 0 - for var_15 in var_5 : - if var_15 == 1 : - var_13 += 1 - else : - var_14 = max ( var_13 , var_14 ) - var_13 = 0 - return max ( var_13 , var_14 ) -",1(0,3 -110,695_Max_Area_of_Island_1.py,"def dfs( grid, i, j): - stack = [(i, j)] - area = 0 - while stack: - r, c = stack.pop(-1) - area += 1 - for nr, nc in ((r - 1, c), (r + 1, c), (r, c - 1), (r, c + 1)): - if (0 <= nr < len(grid) and - 0 <= nc < len(grid[0]) and grid[nr][nc]): - stack.append((nr, nc)) - grid[nr][nc] = 0 - return area","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_3 = [ ( var_1 , var_2 ) ] - var_5 = 0 - while var_3 : - var_7 , var_9 = var_3.pop ( - 1 ) - var_5 += 1 - for var_10 , var_11 in ( ( var_7 - 1 , var_9 ) , ( var_7 + 1 , var_9 ) , ( var_7 , var_9 - 1 ) , ( var_7 , var_9 + 1 ) ) : - if ( 0 <= var_10 < len ( var_0 ) and 0 <= var_11 < len ( var_0 [ 0 ] ) and var_0 [ var_10 ] [ var_11 ] ) : - var_3.append ( ( var_10 , var_11 ) ) - var_0 [ var_10 ] [ var_11 ] = 0 - return var_5 -",10,2 -111,1480_Running_Sum_of_1d_Array_1.py,"def runningSum( nums: List[int]) -> List[int]: - if nums is None or len(nums) == 0: - return nums - for i in range(1, len(nums)): - nums[i] += nums[i-1] - return nums","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - if var_0 is None or len ( var_0 ) == 0 : - return var_0 - for var_8 in range ( 1 , len ( var_0 ) ) : - var_0 [ var_8 ] += var_0 [ var_8 - 1 ] - return var_0 -",10None,3 -112,150_Evaluate_Reverse_Polish_Notation_1.py,"def evalRPN( tokens): - stack = [] - for t in tokens: - try: - temp = int(t) - stack.append(temp) - except: - b = stack.pop() - a = stack.pop() - if t == ""+"": - a += b - elif t == ""-"": - a -= b - elif t == ""*"": - a *= b - else: - a = int(a * 1.0 / b) - stack.append(a) - return stack[-1]","def sample_funcname ( var_0 ) : - var_1 = [ ] - for var_2 in var_0 : - try : - var_4 = int ( var_2 ) - var_1.append ( var_4 ) - except : - var_7 = var_1.pop ( ) - var_8 = var_1.pop ( ) - if var_2 == ""+"" : - var_8 += var_7 - elif var_2 == ""-"" : - var_8 -= var_7 - elif var_2 == ""*"" : - var_8 *= var_7 - else : - var_8 = int ( var_8 * 1.0 / var_7 ) - var_1.append ( var_8 ) - return var_1 [ - 1 ] -",+*1.01-,5 -113,1304_Find_N_Unique_Integers_Sum_up_to_Zero_2.py,"def sumZero( n: int) -> List[int]: - prefix = list(range(1, n)) - - return prefix + [-sum(prefix)]","def sample_funcname ( var_0 : int ) -> List [ int ] : - var_6 = list ( range ( 1 , var_0 ) ) - return var_6 + [ - sum ( var_6 ) ] -",1,1 -114,922_Sort_Array_By_Parity_II_1.py,"def sortArrayByParityII( A): - N = len(A) - ans = [None] * N - t = 0 - for i, x in enumerate(A): - if x % 2 == 0: - ans[t] = x - t += 2 - t = 1 - for i, x in enumerate(A): - if x % 2 == 1: - ans[t] = x - t += 2 - - - - return ans","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_4 = [ None ] * var_2 - var_6 = 0 - for var_8 , var_9 in enumerate ( var_0 ) : - if var_9 % 2 == 0 : - var_4 [ var_6 ] = var_9 - var_6 += 2 - var_6 = 1 - for var_8 , var_9 in enumerate ( var_0 ) : - if var_9 % 2 == 1 : - var_4 [ var_6 ] = var_9 - var_6 += 2 - return var_4 -",10None2,4 -115,784_Letter_Case_Permutation_1.py,"def letterCasePermutation( S): - ans = [[]]","def sample_funcname ( var_0 ) : - var_1 = [ [ ] ] -",,0 -116,022_Generate_Parentheses_1.py,"def generate(leftnum, rightnum, s, result): - if leftnum == 0 and rightnum == 0: - result.append(s) - if leftnum > 0: - generate(leftnum - 1, rightnum, s + '(', result) - if rightnum > 0 and leftnum < rightnum: - generate(leftnum, rightnum - 1, s + ')', result)","def sample_funcname ( var_1 , var_2 , var_3 , var_4 ) : - if var_1 == 0 and var_2 == 0 : - var_4.append ( var_3 ) - if var_1 > 0 : - var_0 ( var_1 - 1 , var_2 , var_3 + '(' , var_4 ) - if var_2 > 0 and var_1 < var_2 : - var_0 ( var_1 , var_2 - 1 , var_3 + ')' , var_4 ) -",1(0),4 -117,962_Maximum_Width_Ramp_1.py,"def maxWidthRamp( A): - if not A or len(A) == 0: - return 0 - for ans in range(len(A) - 1, 0, -1): - for i in range(len(A)): - if i + ans > len(A) - 1: - break - if (A[i + ans] >= A[i]): - return ans - return 0","def sample_funcname ( var_0 ) : - if not var_0 or len ( var_0 ) == 0 : - return 0 - for var_5 in range ( len ( var_0 ) - 1 , 0 , - 1 ) : - for var_6 in range ( len ( var_0 ) ) : - if var_6 + var_5 > len ( var_0 ) - 1 : - break - if ( var_0 [ var_6 + var_5 ] >= var_0 [ var_6 ] ) : - return var_5 - return 0 -",10,2 -119,143_Reorder_List_1.py,"def reorderList( head): - if not head: - return - dmap = [] - current = head - while current is not None: - dmap.append(current) - current = current.next - ls = len(dmap) - for i in range(ls / 2): - t = -1 * (i + 1) - dmap[t].next = dmap[i].next - dmap[i].next = dmap[t] - dmap[ls / 2].next = None","def sample_funcname ( var_0 ) : - if not var_0 : - return - var_1 = [ ] - var_2 = var_0 - while var_2 is not None : - var_1.append ( var_2 ) - var_2 = var_2.next - var_7 = len ( var_1 ) - for var_10 in range ( var_7 / 2 ) : - var_12 = - 1 * ( var_10 + 1 ) - var_1 [ var_12 ].next = var_1 [ var_10 ].next - var_1 [ var_10 ].next = var_1 [ var_12 ] - var_1 [ var_7 / 2 ].next = None -",1None2,3 -120,"050_Pow(x, n)_2.py","def myPow( x, n): - if n == 0: - return 1 - res ,curr = 1, abs(n) - while curr > 0: - if curr & 1 == 1: - res *= x - curr >>= 1 - x *= x - if n < 0: - return 1 / res - return res","def sample_funcname ( var_0 , var_1 ) : - if var_1 == 0 : - return 1 - var_4 , var_6 = 1 , abs ( var_1 ) - while var_6 > 0 : - if var_6 & 1 == 1 : - var_4 *= var_0 - var_6 >>= 1 - var_0 *= var_0 - if var_1 < 0 : - return 1 / var_4 - return var_4 -",10,2 -121,270_Closest_Binary_Search_Tree_Value_1.py,"def closestValue( root, target): - path = [] - while root: - path += root.val, - root = root.left if target < root.val else root.right - return min(path, key=lambda x: abs(target - x))","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - while var_0 : - var_2 += var_0.val , - var_0 = var_0.left if var_1 < var_0.val else var_0.right - return min ( var_2 , var_7 = lambda var_8 : abs ( var_1 - var_8 ) ) -",,0 -122,296_Best_Meeting_Point_1.py,"def minDistance1D( points, origin): - distance = 0 - for point in points: - distance += abs(point - origin) - return distance","def sample_funcname ( var_0 , var_1 ) : - var_3 = 0 - for var_4 in var_0 : - var_3 += abs ( var_4 - var_1 ) - return var_3 -",0,1 -123,141_Linked_List_Cycle_3.py,"def hasCycle( head): - try: - fast = head.next.next - slow = head.next - - while fast != slow: - fast = fast.next.next - slow = slow.next - - return True - except: - return False","def sample_funcname ( var_0 ) : - try : - var_2 = var_0.next.next - var_3 = var_0.next - while var_2 != var_3 : - var_2 = var_2.next.next - var_3 = var_3.next - return True - except : - return False -",,0 -124,063_Unique_Paths_II_2.py,"def uniquePathsWithObstacles( obstacleGrid): - m, n = len(obstacleGrid), len(obstacleGrid[0]) - if m == 0: - return 0 - dmap = [[0] * (n + 1) for _ in range(m + 1)] - dmap[m - 1][n] = 1 - for i in range(m - 1, -1, -1): - for j in range(n - 1, -1, -1): - if obstacleGrid[i][j] == 1: - dmap[i][j] = 0 - else: - dmap[i][j] = dmap[i][j + 1] + dmap[i + 1][j] - return dmap[0][0]","def sample_funcname ( var_0 ) : - var_2 , var_4 = len ( var_0 ) , len ( var_0 [ 0 ] ) - if var_2 == 0 : - return 0 - var_8 = [ [ 0 ] * ( var_4 + 1 ) for var_6 in range ( var_2 + 1 ) ] - var_8 [ var_2 - 1 ] [ var_4 ] = 1 - for var_9 in range ( var_2 - 1 , - 1 , - 1 ) : - for var_10 in range ( var_4 - 1 , - 1 , - 1 ) : - if var_0 [ var_9 ] [ var_10 ] == 1 : - var_8 [ var_9 ] [ var_10 ] = 0 - else : - var_8 [ var_9 ] [ var_10 ] = var_8 [ var_9 ] [ var_10 + 1 ] + var_8 [ var_9 + 1 ] [ var_10 ] - return var_8 [ 0 ] [ 0 ] -",10,2 -125,003_Longest_Substring_Without_Repeating_Characters_3.py,"def lengthOfLongestSubstring( s): - charMap = {} - for i in range(256): - charMap[i] = -1 - ls = len(s) - i = max_len = 0 - for j in range(ls): - if charMap[ord(s[j])] >= i: - i = charMap[ord(s[j])] + 1 - charMap[ord(s[j])] = j - max_len = max(max_len, j - i + 1) - return max_len","def sample_funcname ( var_0 ) : - var_1 = { } - for var_4 in range ( 256 ) : - var_1 [ var_4 ] = - 1 - var_7 = len ( var_0 ) - var_4 = var_8 = 0 - for var_10 in range ( var_7 ) : - if var_1 [ ord ( var_0 [ var_10 ] ) ] >= var_4 : - var_4 = var_1 [ ord ( var_0 [ var_10 ] ) ] + 1 - var_1 [ ord ( var_0 [ var_10 ] ) ] = var_10 - var_8 = max ( var_8 , var_10 - var_4 + 1 ) - return var_8 -",12560,3 -126,186_Reverse_Words_in_a_String_II_1.py,"def reverse( array_s, begin, end): - for i in range((end - begin) / 2): - array_s[begin + i], array_s[end - i - 1] = array_s[end - i - 1], array_s[begin + i]","def sample_funcname ( var_0 , var_1 , var_2 ) : - for var_5 in range ( ( var_2 - var_1 ) / 2 ) : - var_0 [ var_1 + var_5 ] , var_0 [ var_2 - var_5 - 1 ] = var_0 [ var_2 - var_5 - 1 ] , var_0 [ var_1 + var_5 ] -",12,2 -127,025_Reverse_Nodes_i_ k-Group_1.py,"def reverseList( head, end): - pos = head.next - last = end - next_start = pos - while pos != end: - head.next = pos - last_pos = pos - pos = pos.next - last_pos.next = last - last = last_pos - return next_start","def sample_funcname ( var_0 , var_1 ) : - var_3 = var_0.next - var_4 = var_1 - var_5 = var_3 - while var_3 != var_1 : - var_0.next = var_3 - var_6 = var_3 - var_3 = var_3.next - var_6.next = var_4 - var_4 = var_6 - return var_5 -",,0 -128,137_Single_Number_II_1.py,"def singleNumber( nums): - import ctypes - - - count = [0] * 32 - res = ctypes.c_int32(0) - for i in range(32): - for num in nums: - if (ctypes.c_int32(num).value >> i) & 1: - count[i] += 1 - res.value |= ((count[i] % 3) << i) - return res.value","def sample_funcname ( var_0 ) : - import var_1 - var_4 = [ 0 ] * 32 - var_6 = var_1.c_int32 ( 0 ) - for var_8 in range ( 32 ) : - for var_9 in var_0 : - if ( var_1.c_int32 ( var_9 ).value >> var_8 ) & 1 : - var_4 [ var_8 ] += 1 - var_6.value |= ( ( var_4 [ var_8 ] % 3 ) << var_8 ) - return var_6.value -",13032,4 -129,328_Odd_Even_Linked_List_2.py,"def oddEvenList( head): - if (head != None): - x = [] - else: - return [] - while (head.next != None): - x.append(head.val) - head = head.next - x.append(head.val) - return x[0::2] + x[1::2]","def sample_funcname ( var_0 ) : - if ( var_0 != None ) : - var_2 = [ ] - else : - return [ ] - while ( var_0.next != None ) : - var_2.append ( var_0.val ) - var_0 = var_0.next - var_2.append ( var_0.val ) - return var_2 [ 0 : : 2 ] + var_2 [ 1 : : 2 ] -",10None2,4 -130,072_Edit_Distance_1.py,"def minDistance( word1, word2): - ls_1, ls_2 = len(word1), len(word2) - dp = [[0] * (ls_2 + 1) for _ in range(ls_1 + 1)] - for i in range(1, ls_1 + 1): - dp[i][0] = i - for j in range(1, ls_2 + 1): - dp[0][j] = j - for i in range(1, ls_1 + 1): - for j in range(1, ls_2 + 1): - if word1[i - 1] == word2[j - 1]: - dp[i][j] = dp[i - 1][j - 1] - else: - dp[i][j] = min(dp[i - 1][j - 1] + 1, - dp[i][j - 1] + 1, - dp[i - 1][j] + 1) - return dp[ls_1][ls_2]","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = len ( var_0 ) , len ( var_1 ) - var_9 = [ [ 0 ] * ( var_4 + 1 ) for var_7 in range ( var_3 + 1 ) ] - for var_10 in range ( 1 , var_3 + 1 ) : - var_9 [ var_10 ] [ 0 ] = var_10 - for var_11 in range ( 1 , var_4 + 1 ) : - var_9 [ 0 ] [ var_11 ] = var_11 - for var_10 in range ( 1 , var_3 + 1 ) : - for var_11 in range ( 1 , var_4 + 1 ) : - if var_0 [ var_10 - 1 ] == var_1 [ var_11 - 1 ] : - var_9 [ var_10 ] [ var_11 ] = var_9 [ var_10 - 1 ] [ var_11 - 1 ] - else : - var_9 [ var_10 ] [ var_11 ] = min ( var_9 [ var_10 - 1 ] [ var_11 - 1 ] + 1 , var_9 [ var_10 ] [ var_11 - 1 ] + 1 , var_9 [ var_10 - 1 ] [ var_11 ] + 1 ) - return var_9 [ var_3 ] [ var_4 ] -",10,2 -131,001_Two_Sum_4.py,"def twoSum( nums, target): - nums_index = [(v, index) for index, v in enumerate(nums)] - nums_index.sort() - begin, end = 0, len(nums) - 1 - while begin < end: - curr = nums_index[begin][0] + nums_index[end][0] - if curr == target: - return [nums_index[begin][1], nums_index[end][1]] - elif curr < target: - begin += 1 - else: - end -= 1","def sample_funcname ( var_0 , var_1 ) : - var_5 = [ ( var_2 , var_3 ) for var_3 , var_2 in enumerate ( var_0 ) ] - var_5.sort ( ) - var_8 , var_11 = 0 , len ( var_0 ) - 1 - while var_8 < var_11 : - var_12 = var_5 [ var_8 ] [ 0 ] + var_5 [ var_11 ] [ 0 ] - if var_12 == var_1 : - return [ var_5 [ var_8 ] [ 1 ] , var_5 [ var_11 ] [ 1 ] ] - elif var_12 < var_1 : - var_8 += 1 - else : - var_11 -= 1 -",10,2 -132,223_Rectangle Area_1.py,"def computeArea( A, B, C, D, E, F, G, H): - result = (C - A) * (D - B) + (G - E) * (H - F) - if (C <= E or G <= A or H <= B or D <= F): - return result - dx = min(C, G) - max(A, E) - dy = min(D, H) - max(B, F) - return result - dx * dy","def sample_funcname ( var_0 , var_1 , var_2 , var_3 , var_4 , var_5 , var_6 , var_7 ) : - var_8 = ( var_2 - var_0 ) * ( var_3 - var_1 ) + ( var_6 - var_4 ) * ( var_7 - var_5 ) - if ( var_2 <= var_4 or var_6 <= var_0 or var_7 <= var_1 or var_3 <= var_5 ) : - return var_8 - var_11 = min ( var_2 , var_6 ) - max ( var_0 , var_4 ) - var_12 = min ( var_3 , var_7 ) - max ( var_1 , var_5 ) - return var_8 - var_11 * var_12 -",,0 -133,215_Kth_Largest_Element_in_an_Array_1.py,"def findKthLargest( nums, k): - return sorted(nums, reverse=True)[k - 1]","def sample_funcname ( var_0 , var_1 ) : - return sorted ( var_0 , var_3 = True ) [ var_1 - 1 ] -",1,1 -134,293_Flip_Game_1.py,"def generatePossibleNextMoves( s): - res = [] - if s is None or len(s) == 0: - return res - ls = len(s) - for i in range(ls - 1): - if s[i] == '+' and s[i + 1] == '+': - res.append(s[:i] + '--' + s[i + 2:]) - return res","def sample_funcname ( var_0 ) : - var_1 = [ ] - if var_0 is None or len ( var_0 ) == 0 : - return var_1 - var_5 = len ( var_0 ) - for var_8 in range ( var_5 - 1 ) : - if var_0 [ var_8 ] == '+' and var_0 [ var_8 + 1 ] == '+' : - var_1.append ( var_0 [ : var_8 ] + '--' + var_0 [ var_8 + 2 : ] ) - return var_1 -",0None+21--,6 -135,288_Unique_Word_Abbreviation_1.py,"def getAbb( word): - if len(word) <= 2: - return word - return word[0] + str(len(word) - 2) + word[-1]","def sample_funcname ( var_0 ) : - if len ( var_0 ) <= 2 : - return var_0 - return var_0 [ 0 ] + str ( len ( var_0 ) - 2 ) + var_0 [ - 1 ] -",102,3 -136,028_Implement_strStr()_3.py,"def makeNext( needle): - ls = len(needle) - next = [0] * ls - next[0], i, j = -1, 0, -1 - while i < ls - 1: - if j == -1 or needle[i] == needle[j]: - next[i + 1] = j + 1 - if needle[i + 1] == needle[j + 1]: - next[i + 1] = next[j + 1] - i += 1 - j += 1 - if needle[i] != needle[j]: - j = next[j] - return next","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_4 = [ 0 ] * var_2 - var_4 [ 0 ] , var_6 , var_7 = - 1 , 0 , - 1 - while var_6 < var_2 - 1 : - if var_7 == - 1 or var_0 [ var_6 ] == var_0 [ var_7 ] : - var_4 [ var_6 + 1 ] = var_7 + 1 - if var_0 [ var_6 + 1 ] == var_0 [ var_7 + 1 ] : - var_4 [ var_6 + 1 ] = var_4 [ var_7 + 1 ] - var_6 += 1 - var_7 += 1 - if var_0 [ var_6 ] != var_0 [ var_7 ] : - var_7 = var_4 [ var_7 ] - return var_4 -",10,2 -137,089_Gray_Code_2.py,"def count_one( num): - count = 0 - while num: - num &= (num - 1) - count += 1 - return count","def sample_funcname ( var_0 ) : - var_2 = 0 - while var_0 : - var_0 &= ( var_0 - 1 ) - var_2 += 1 - return var_2 -",10,2 -138,541_Reverse_String_II_2.py,"def reverseStr( s: str, k: int) -> str: - s = list(s) - for i in range(0, len(s), 2*k): - s[i:i+k] = reversed(s[i:i+k]) - return """".join(s)","def sample_funcname ( var_0 : str , var_2 : int ) -> str : - var_0 = list ( var_0 ) - for var_9 in range ( 0 , len ( var_0 ) , 2 * var_2 ) : - var_0 [ var_9 : var_9 + var_2 ] = reversed ( var_0 [ var_9 : var_9 + var_2 ] ) - return """".join ( var_0 ) -",02,3 -139,056_Merge_Intervals_1.py,"def merge( intervals): - if intervals is None: - return - ls = len(intervals) - if ls <= 1: - return intervals - intervals.sort(key=lambda x: x.start) - pos = 0 - while pos < len(intervals) - 1: - if intervals[pos].end >= intervals[pos + 1].start: - next = intervals.pop(pos + 1) - if next.end > intervals[pos].end: - intervals[pos].end = next.end - else: - pos += 1 - return intervals","def sample_funcname ( var_0 ) : - if var_0 is None : - return - var_3 = len ( var_0 ) - if var_3 <= 1 : - return var_0 - var_0.sort ( var_6 = lambda var_7 : var_7.start ) - var_10 = 0 - while var_10 < len ( var_0 ) - 1 : - if var_0 [ var_10 ].end >= var_0 [ var_10 + 1 ].start : - var_13 = var_0.pop ( var_10 + 1 ) - if var_13.end > var_0 [ var_10 ].end : - var_0 [ var_10 ].end = var_13.end - else : - var_10 += 1 - return var_0 -",1None0,3 -140,290_Word_Pattern_1.py,"def wordPattern( pattern, str): - if pattern is None or str is None: - return True - words_to_pattern = {} - pattern_to_words = {} - word_list = str.split(' ') - if len(word_list) != len(pattern): - return False - for index, word in enumerate(word_list): - curr_p = pattern[index] - if pattern_to_words.get(curr_p, word) != word or words_to_pattern.get(word, curr_p) != curr_p: - return False - pattern_to_words[curr_p] = pattern_to_words.get(curr_p, word) - words_to_pattern[word] = words_to_pattern.get(word, curr_p) - return True","def sample_funcname ( var_0 , var_1 ) : - if var_0 is None or var_1 is None : - return True - var_4 = { } - var_5 = { } - var_8 = var_1.split ( ' ' ) - if len ( var_8 ) != len ( var_0 ) : - return False - for var_12 , var_13 in enumerate ( var_8 ) : - var_14 = var_0 [ var_12 ] - if var_5.get ( var_14 , var_13 ) != var_13 or var_4.get ( var_13 , var_14 ) != var_14 : - return False - var_5 [ var_14 ] = var_5.get ( var_14 , var_13 ) - var_4 [ var_13 ] = var_4.get ( var_13 , var_14 ) - return True -", None,2 -141,717_1-bit_and_2-bit_Characters_1.py,"def isOneBitCharacter( bits: List[int]) -> bool: - pos = 0 - while pos < len(bits) - 1: - pos += bits[pos] + 1 - return pos == len(bits) - 1","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_5 = 0 - while var_5 < len ( var_0 ) - 1 : - var_5 += var_0 [ var_5 ] + 1 - return var_5 == len ( var_0 ) - 1 -",10,2 -142,026_Remove_Duplicates_from_Sorted_Array_2.py,"def removeDuplicates( nums): - if len(nums) == 0: - return 0 - left = 0 - for i in range(1, len(nums)): - if nums[left] == nums[i]: - continue - else: - left += 1 - nums[left] = nums[i] - return left + 1","def sample_funcname ( var_0 ) : - if len ( var_0 ) == 0 : - return 0 - var_3 = 0 - for var_6 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_3 ] == var_0 [ var_6 ] : - continue - else : - var_3 += 1 - var_0 [ var_3 ] = var_0 [ var_6 ] - return var_3 + 1 -",10,2 -143,153_Find_Minimum_in_Rotated_Sorted_Array_1.py,"def findMin( nums): - l, r = 0, len(nums) - 1 - while l < r and nums[l] >= nums[r]: - mid = (l + r) / 2 - if nums[mid] > nums[r]: - l = mid + 1 - else: - r = mid - return nums[l]","def sample_funcname ( var_0 ) : - var_2 , var_5 = 0 , len ( var_0 ) - 1 - while var_2 < var_5 and var_0 [ var_2 ] >= var_0 [ var_5 ] : - var_7 = ( var_2 + var_5 ) / 2 - if var_0 [ var_7 ] > var_0 [ var_5 ] : - var_2 = var_7 + 1 - else : - var_5 = var_7 - return var_0 [ var_2 ] -",102,3 -144,015_3Sum_1.py,"def threeSum( nums): - if len(nums) < 3: - return [] - nums.sort() - ls = len(nums) - result = [] - for i in range(0, ls - 2): - if nums[i] > 0: - break - if i > 0 and nums[i] == nums[i - 1]: - continue - j = i + 1 - k = ls - 1 - while(j < k): - temp = [nums[i], nums[j], nums[k]] - s = sum(temp) - jtemp = nums[j] - ktemp = nums[k] - if s <= 0: - j += 1 - while(j < k and jtemp == nums[j]): - j += 1 - if s == 0: - result.append(temp) - else: - k -= 1 - while(j < k and ktemp == nums[k]): - k -= 1 - return result","def sample_funcname ( var_0 ) : - if len ( var_0 ) < 3 : - return [ ] - var_0.sort ( ) - var_4 = len ( var_0 ) - var_5 = [ ] - for var_9 in range ( 0 , var_4 - 2 ) : - if var_0 [ var_9 ] > 0 : - break - if var_9 > 0 and var_0 [ var_9 ] == var_0 [ var_9 - 1 ] : - continue - var_11 = var_9 + 1 - var_12 = var_4 - 1 - while ( var_11 < var_12 ) : - var_13 = [ var_0 [ var_9 ] , var_0 [ var_11 ] , var_0 [ var_12 ] ] - var_15 = sum ( var_13 ) - var_16 = var_0 [ var_11 ] - var_17 = var_0 [ var_12 ] - if var_15 <= 0 : - var_11 += 1 - while ( var_11 < var_12 and var_16 == var_0 [ var_11 ] ) : - var_11 += 1 - if var_15 == 0 : - var_5.append ( var_13 ) - else : - var_12 -= 1 - while ( var_11 < var_12 and var_17 == var_0 [ var_12 ] ) : - var_12 -= 1 - return var_5 -",1302,4 -145,016_3Sum_Closest_1.py,"def threeSumClosest( nums, target): - ls = len(nums) - sort_nums = sorted(nums) - res = nums[0] + nums[1] + nums[2] - for i in range(ls - 2): - j, k = i + 1, ls - 1 - while j < k: - temp = sort_nums[i] + sort_nums[j] + sort_nums[k] - if abs(target - temp) < abs(target - res): - res = temp - if temp < target: - j += 1 - else: - k -= 1 - return res","def sample_funcname ( var_0 , var_1 ) : - var_3 = len ( var_0 ) - var_5 = sorted ( var_0 ) - var_9 = var_0 [ 0 ] + var_0 [ 1 ] + var_0 [ 2 ] - for var_11 in range ( var_3 - 2 ) : - var_12 , var_13 = var_11 + 1 , var_3 - 1 - while var_12 < var_13 : - var_14 = var_5 [ var_11 ] + var_5 [ var_12 ] + var_5 [ var_13 ] - if abs ( var_1 - var_14 ) < abs ( var_1 - var_9 ) : - var_9 = var_14 - if var_14 < var_1 : - var_12 += 1 - else : - var_13 -= 1 - return var_9 -",102,3 -146,034_Search_for_a_Range_1.py,"def searchRange( nums, target): - length = len(nums) - if length == 0: - return [-1, -1] - min = 0 - max = length - 1 - while min <= max: - pos = (min + max) / 2 - if nums[pos] > target: - max = pos - 1 - elif nums[pos] < target: - min = pos + 1 - else: - for i in range(min, max + 1): - if nums[i] == target: - if min < i and nums[min] != nums[i]: - min = i - max = i - return [min, max] - return [-1, -1]","def sample_funcname ( var_0 , var_1 ) : - var_3 = len ( var_0 ) - if var_3 == 0 : - return [ - 1 , - 1 ] - var_6 = 0 - var_7 = var_3 - 1 - while var_6 <= var_7 : - var_9 = ( var_6 + var_7 ) / 2 - if var_0 [ var_9 ] > var_1 : - var_7 = var_9 - 1 - elif var_0 [ var_9 ] < var_1 : - var_6 = var_9 + 1 - else : - for var_11 in range ( var_6 , var_7 + 1 ) : - if var_0 [ var_11 ] == var_1 : - if var_6 < var_11 and var_0 [ var_6 ] != var_0 [ var_11 ] : - var_6 = var_11 - var_7 = var_11 - return [ var_6 , var_7 ] - return [ - 1 , - 1 ] -",102,3 -147,434_Number_of_Segments_in_a_String_2.py,"def countSegments( s): - segment_count = 0","def sample_funcname ( var_0 ) : - var_2 = 0 -",0,1 -148,811_Subdomain_Visit_Count_1.py,"def subdomainVisits( cpdomains): - domain_count = {} - for cpdomain in cpdomains: - count, domain = cpdomain.split(' ') - sub_domain = domain.split('.') - for i in range(len(sub_domain)): - curr = '.'.join(sub_domain[i:]) - domain_count[curr] = domain_count.get(curr, 0) + int(count) - return [str(v) + ' ' + k for k, v in domain_count.items()]","def sample_funcname ( var_0 ) : - var_1 = { } - for var_2 in var_0 : - var_4 , var_6 = var_2.split ( ' ' ) - var_8 = var_6.split ( '.' ) - for var_11 in range ( len ( var_8 ) ) : - var_13 = '.'.join ( var_8 [ var_11 : ] ) - var_1 [ var_13 ] = var_1.get ( var_13 , 0 ) + int ( var_4 ) - return [ str ( var_18 ) + ' ' + var_19 for var_19 , var_18 in var_1.items ( ) ] -",0 .,3 -149,141_Linked_List_Cycle_2.py,"def hasCycle( head): - dic = {} - pos = head - while pos is not None: - try: - dic[pos] - return True - except KeyError: - dic[pos] = pos - pos = pos.next - return False","def sample_funcname ( var_0 ) : - var_1 = { } - var_2 = var_0 - while var_2 is not None : - try : - var_1 [ var_2 ] - return True - except KeyError : - var_1 [ var_2 ] = var_2 - var_2 = var_2.next - return False -",None,1 -150,003_Longest_Substring_Without_Repeating_Characters_2.py,"def lengthOfLongestSubstring( s): - sls = len(set(s)) - ls = len(s) - if ls >= 1: - max_l = 1 - else: - return 0 - for i in range(ls): - for j in reversed(range(i + max_l + 1, i + sls + 1)): - curr = s[i:j] - c_ls = len(curr) - if len(set(curr)) == c_ls: - if c_ls > max_l: - max_l = c_ls - if max_l == sls: - return sls - break - return max_l","def sample_funcname ( var_0 ) : - var_3 = len ( set ( var_0 ) ) - var_4 = len ( var_0 ) - if var_4 >= 1 : - var_6 = 1 - else : - return 0 - for var_9 in range ( var_4 ) : - for var_11 in reversed ( range ( var_9 + var_6 + 1 , var_9 + var_3 + 1 ) ) : - var_12 = var_0 [ var_9 : var_11 ] - var_13 = len ( var_12 ) - if len ( set ( var_12 ) ) == var_13 : - if var_13 > var_6 : - var_6 = var_13 - if var_6 == var_3 : - return var_3 - break - return var_6 -",10,2 -152,035_Search_Insert_Position_1.py,"def searchInsert( nums, target): - min, pos = 0, 0 - max = len(nums) - 1 - while min <= max: - - pos = (max + min) / 2 - if nums[pos] == target: - return pos - elif nums[pos] > target: - max = pos - 1 - else: - min = pos + 1 - if min > pos: - - - return pos + 1 - return pos","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = 0 , 0 - var_7 = len ( var_0 ) - 1 - while var_3 <= var_7 : - var_4 = ( var_7 + var_3 ) / 2 - if var_0 [ var_4 ] == var_1 : - return var_4 - elif var_0 [ var_4 ] > var_1 : - var_7 = var_4 - 1 - else : - var_3 = var_4 + 1 - if var_3 > var_4 : - return var_4 + 1 - return var_4 -",102,3 -153,007_Reverse_Integer_1.py,"def reverse( x): - max_int = 2147483647 - if x == 0: - return 0 - isPos = True - if x < 0: - x *= (-1) - isPos = False - ltemp = [] - while x != 0: - temp = x % 10 - ltemp.append(temp) - x /= 10 - result = 0 - - for t in ltemp: - result = result * 10 + t - if result > max_int: - result = 0 - if isPos: - return result - else: - return -1 * result","def sample_funcname ( var_0 ) : - var_2 = 2147483647 - if var_0 == 0 : - return 0 - var_5 = True - if var_0 < 0 : - var_0 *= ( - 1 ) - var_5 = False - var_8 = [ ] - while var_0 != 0 : - var_10 = var_0 % 10 - var_8.append ( var_10 ) - var_0 /= 10 - var_12 = 0 - for var_13 in var_8 : - var_12 = var_12 * 10 + var_13 - if var_12 > var_2 : - var_12 = 0 - if var_5 : - return var_12 - else : - return - 1 * var_12 -",21474836470101,4 -154,697_Degree_of_an_Array_1.py,"def smallestSubArray( nums, key, degree): - start = nums.index(key) - pos = start + 1 - degree -= 1 - while pos < len(nums) and degree != 0: - if nums[pos] == key: - degree -= 1 - pos += 1 - return pos - start","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_4 = var_0.index ( var_1 ) - var_6 = var_4 + 1 - var_2 -= 1 - while var_6 < len ( var_0 ) and var_2 != 0 : - if var_0 [ var_6 ] == var_1 : - var_2 -= 1 - var_6 += 1 - return var_6 - var_4 -",10,2 -155,243_Shortest_Word_Distance_1.py,"def shortestDistance( words, word1, word2): - indexes = [] - for index, word in enumerate(words): - if word1 == word: - indexes.append((index, 1)) - elif word2 == word: - indexes.append((index, 2)) - ls, min_range = len(indexes), len(words) - for i in range(ls - 1): - if indexes[i][1] == indexes[i + 1][1]: - continue - curr_range = abs(indexes[i][0] - indexes[i + 1][0]) - if curr_range < min_range: - min_range = curr_range - return min_range","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_3 = [ ] - for var_5 , var_6 in enumerate ( var_0 ) : - if var_1 == var_6 : - var_3.append ( ( var_5 , 1 ) ) - elif var_2 == var_6 : - var_3.append ( ( var_5 , 2 ) ) - var_11 , var_12 = len ( var_3 ) , len ( var_0 ) - for var_14 in range ( var_11 - 1 ) : - if var_3 [ var_14 ] [ 1 ] == var_3 [ var_14 + 1 ] [ 1 ] : - continue - var_17 = abs ( var_3 [ var_14 ] [ 0 ] - var_3 [ var_14 + 1 ] [ 0 ] ) - if var_17 < var_12 : - var_12 = var_17 - return var_12 -",102,3 -156,069_Sqrt(x)_1.py,"def mySqrt( x): - if x == 0: - return 0 - low = 0 - high = x - last = x - while high >= low: - mid = (low + high) / 2 - temp = mid * mid - if temp == x: - return mid - elif temp < x: - low = mid + 1 - last = mid - else: - high = mid - 1 - return last","def sample_funcname ( var_0 ) : - if var_0 == 0 : - return 0 - var_2 = 0 - var_3 = var_0 - var_4 = var_0 - while var_3 >= var_2 : - var_6 = ( var_2 + var_3 ) / 2 - var_7 = var_6 * var_6 - if var_7 == var_0 : - return var_6 - elif var_7 < var_0 : - var_2 = var_6 + 1 - var_4 = var_6 - else : - var_3 = var_6 - 1 - return var_4 -",102,3 -157,1310_XOR_Queries_of_a_Subarray_1.py,"def xorQueries( arr: List[int], queries: List[List[int]]) -> List[int]: - pref = [0] - for e in arr: - pref.append(e ^ pref[-1]) - ans = [] - for [l, r] in queries: - ans.append(pref[r+1] ^ pref[l]) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ List [ int ] ] ) -> List [ int ] : - var_5 = [ 0 ] - for var_6 in var_0 : - var_5.append ( var_6 ^ var_5 [ - 1 ] ) - var_9 = [ ] - for [ var_10 , var_11 ] in var_3 : - var_9.append ( var_5 [ var_11 + 1 ] ^ var_5 [ var_10 ] ) - return var_9 -",10,2 -158,836_Rectangle_Overlap_1.py,"def isRectangleOverlap( rec1, rec2): - return not (rec1[2] <= rec2[0] or - rec1[3] <= rec2[1] or - rec1[0] >= rec2[2] or - rec1[1] >= rec2[3])","def sample_funcname ( var_0 , var_1 ) : - return not ( var_0 [ 2 ] <= var_1 [ 0 ] or var_0 [ 3 ] <= var_1 [ 1 ] or var_0 [ 0 ] >= var_1 [ 2 ] or var_0 [ 1 ] >= var_1 [ 3 ] ) -",1302,4 -159,581_Shortest_Unsorted_Continuous_Subarray_1.py,"def findUnsortedSubarray( nums): - snums = nums[::] - snums.sort() - start = len(nums) - end = 0 - for i in range(len(nums)): - if snums[i] != nums[i]: - start = min(start, i) - end = max(end, i) - if end >= start: - return end - start + 1 - return 0","def sample_funcname ( var_0 ) : - var_1 = var_0 [ : : ] - var_1.sort ( ) - var_4 = len ( var_0 ) - var_6 = 0 - for var_8 in range ( len ( var_0 ) ) : - if var_1 [ var_8 ] != var_0 [ var_8 ] : - var_4 = min ( var_4 , var_8 ) - var_6 = max ( var_6 , var_8 ) - if var_6 >= var_4 : - return var_6 - var_4 + 1 - return 0 -",10,2 -160,168_Excel_Sheet_Column_Title_1.py,"def convertToTitle( n: int) -> str: - res = """" - while n > 0: - n -= 1 - res = chr(65 + n % 26) + res - n //= 26 - return res","def sample_funcname ( var_0 : int ) -> str : - var_4 = """" - while var_0 > 0 : - var_0 -= 1 - var_4 = chr ( 65 + var_0 % 26 ) + var_4 - var_0 //= 26 - return var_4 -",016526,5 -161,366_Find_Leaves_of_Binary_Tree_1.py,"def findLeaves( root): - res = [] - if root is None: - return [] - stack = [root] - check_set = set() - while len(stack) > 0: - curr = stack.pop() - check_set.add(curr) - if curr.left: - stack.append(curr.left) - if curr.right: - stack.append(curr.right) - while len(check_set) > 0: - curr = [] - for node in check_set: - if (node.left is None or node.left not in check_set) and\ - (node.right is None or node.right not in check_set): - curr.append(node) - res.append([node.val for node in curr]) - for node in curr: - check_set.remove(node) - return res","def sample_funcname ( var_0 ) : - var_1 = [ ] - if var_0 is None : - return [ ] - var_3 = [ var_0 ] - var_5 = set ( ) - while len ( var_3 ) > 0 : - var_9 = var_3.pop ( ) - var_5.add ( var_9 ) - if var_9.left : - var_3.append ( var_9.left ) - if var_9.right : - var_3.append ( var_9.right ) - while len ( var_5 ) > 0 : - var_9 = [ ] - for var_14 in var_5 : - if ( var_14.left is None or var_14.left not in var_5 ) and ( var_14.right is None or var_14.right not in var_5 ) : - var_9.append ( var_14 ) - var_1.append ( [ var_14.val for var_14 in var_9 ] ) - for var_14 in var_9 : - var_5.remove ( var_14 ) - return var_1 -",0None,2 -162,237_Delete_Node_in_a_Linked_List_1.py,"def deleteNode( node): - node.val = node.next.val - node.next = node.next.next","def sample_funcname ( var_0 ) : - var_0.val = var_0.next.val - var_0.next = var_0.next.next -",,0 -163,028_Implement_strStr()_2.py,"def strStr( haystack, needle): - lsh, lsn = len(haystack), len(needle) - if lsn == 0: - return 0 - pos, index = 0, 0 - while index <= lsh - lsn: - if haystack[index] == needle[0]: - - if haystack[index:index + lsn] == needle: - return index - index += 1 - return -1","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = len ( var_0 ) , len ( var_1 ) - if var_4 == 0 : - return 0 - var_6 , var_7 = 0 , 0 - while var_7 <= var_3 - var_4 : - if var_0 [ var_7 ] == var_1 [ 0 ] : - if var_0 [ var_7 : var_7 + var_4 ] == var_1 : - return var_7 - var_7 += 1 - return - 1 -",10,2 -164,191_Number_of_1_Bits_1.py,"def hammingWeight( n): - s_n = bin(n)[2:] - return s_n.count('1')","def sample_funcname ( var_0 ) : - var_3 = bin ( var_0 ) [ 2 : ] - return var_3.count ( '1' ) -",21,2 -165,067_Add_Binary_1.py,"def addBinary( a, b): - res = '' - lsa, lsb = len(a), len(b) - pos = -1 - plus = 0 - while (lsa + pos) >= 0 and (lsb + pos) >= 0: - curr = int(a[pos]) + int(b[pos]) + plus - if curr >= 2: - plus = 1 - curr %= 2 - else: - plus = 0 - res = str(curr) + res - pos -= 1 - if lsa + pos >= 0: - while (lsa + pos) >= 0: - curr = int(a[pos]) + plus - if curr >= 2: - plus = 1 - curr %= 2 - else: - plus = 0 - res = str(curr) + res - pos -= 1 - if lsb + pos >= 0: - while (lsb + pos) >= 0: - curr = int(b[pos]) + plus - if curr >= 2: - plus = 1 - curr %= 2 - else: - plus = 0 - res = str(curr) + res - pos -= 1 - if plus == 1: - res = '1' + res - return res","def sample_funcname ( var_0 , var_1 ) : - var_3 = '' - var_5 , var_6 = len ( var_0 ) , len ( var_1 ) - var_8 = - 1 - var_10 = 0 - while ( var_5 + var_8 ) >= 0 and ( var_6 + var_8 ) >= 0 : - var_12 = int ( var_0 [ var_8 ] ) + int ( var_1 [ var_8 ] ) + var_10 - if var_12 >= 2 : - var_10 = 1 - var_12 %= 2 - else : - var_10 = 0 - var_3 = str ( var_12 ) + var_3 - var_8 -= 1 - if var_5 + var_8 >= 0 : - while ( var_5 + var_8 ) >= 0 : - var_12 = int ( var_0 [ var_8 ] ) + var_10 - if var_12 >= 2 : - var_10 = 1 - var_12 %= 2 - else : - var_10 = 0 - var_3 = str ( var_12 ) + var_3 - var_8 -= 1 - if var_6 + var_8 >= 0 : - while ( var_6 + var_8 ) >= 0 : - var_12 = int ( var_1 [ var_8 ] ) + var_10 - if var_12 >= 2 : - var_10 = 1 - var_12 %= 2 - else : - var_10 = 0 - var_3 = str ( var_12 ) + var_3 - var_8 -= 1 - if var_10 == 1 : - var_3 = '1' + var_3 - return var_3 -",0211,5 -166,130_Surrounded_Regions_1.py,"def buildLeakWall( board): - leakWall, height, width = [], len(board), len(board[0]) - for i in range(height): - if board[i][0] == ""O"": - leakWall.append((i, 0)) - if board[i][width - 1] == ""O"": - leakWall.append((i, width - 1)) - for j in range(width): - if board[0][j] == ""O"": - leakWall.append((0, j)) - if board[height - 1][j] == ""O"": - leakWall.append((height - 1, j)) - return leakWall","def sample_funcname ( var_0 ) : - var_1 , var_3 , var_5 = [ ] , len ( var_0 ) , len ( var_0 [ 0 ] ) - for var_7 in range ( var_3 ) : - if var_0 [ var_7 ] [ 0 ] == ""O"" : - var_1.append ( ( var_7 , 0 ) ) - if var_0 [ var_7 ] [ var_5 - 1 ] == ""O"" : - var_1.append ( ( var_7 , var_5 - 1 ) ) - for var_11 in range ( var_5 ) : - if var_0 [ 0 ] [ var_11 ] == ""O"" : - var_1.append ( ( 0 , var_11 ) ) - if var_0 [ var_3 - 1 ] [ var_11 ] == ""O"" : - var_1.append ( ( var_3 - 1 , var_11 ) ) - return var_1 -",10O,3 -167,671_Second_Minimum_Node_In_a_Binary_Tree_1.py,"def findSecondMinimumValue( root): - if not root: - return -1 - ans = float('inf') - min_val = root.val - stack = [root] - while stack: - curr = stack.pop() - if not curr: - continue - if min_val < curr.val < ans: - ans = curr.val - elif curr.val == min_val: - stack.append(curr.left) - stack.append(curr.right) - return ans if ans < float('inf') else -1","def sample_funcname ( var_0 ) : - if not var_0 : - return - 1 - var_4 = float ( 'inf' ) - var_6 = var_0.val - var_7 = [ var_0 ] - while var_7 : - var_9 = var_7.pop ( ) - if not var_9 : - continue - if var_6 < var_9.val < var_4 : - var_4 = var_9.val - elif var_9.val == var_6 : - var_7.append ( var_9.left ) - var_7.append ( var_9.right ) - return var_4 if var_4 < float ( 'inf' ) else - 1 -",1inf,2 -168,229_Majority_Element_II_1.py,"def majorityElement( nums): - ls = len(nums) - res = [] - check_value = [] - for i in range(ls): - if nums[i] in check_value: - continue - count = 1 - for j in range(i + 1, ls): - if nums[i] == nums[j]: - count += 1 - if count > ls / 3: - res.append(nums[i]) - check_value.append(nums[i]) - return res","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_3 = [ ] - var_4 = [ ] - for var_6 in range ( var_2 ) : - if var_0 [ var_6 ] in var_4 : - continue - var_8 = 1 - for var_9 in range ( var_6 + 1 , var_2 ) : - if var_0 [ var_6 ] == var_0 [ var_9 ] : - var_8 += 1 - if var_8 > var_2 / 3 : - var_3.append ( var_0 [ var_6 ] ) - var_4.append ( var_0 [ var_6 ] ) - return var_3 -",31,2 -169,252_Meeting_Rooms_1.py,"def canAttendMeetings( intervals): - check = [] - for it in intervals: - check.append((it.start, True)) - check.append((it.end - 1, False)) - check.sort(key=lambda x : x[0]) - count = 0 - for t in check: - if t[1]: - count += 1 - if count > 1: - return False - else: - count -= 1 - return True","def sample_funcname ( var_0 ) : - var_1 = [ ] - for var_2 in var_0 : - var_1.append ( ( var_2.start , True ) ) - var_1.append ( ( var_2.end - 1 , False ) ) - var_1.sort ( var_10 = lambda var_11 : var_11 [ 0 ] ) - var_13 = 0 - for var_14 in var_1 : - if var_14 [ 1 ] : - var_13 += 1 - if var_13 > 1 : - return False - else : - var_13 -= 1 - return True -",10,2 -170,977_Squares_of_a_Sorted_Array_1.py,"def sortedSquares( A): - return sorted(x * x for x in A)","def sample_funcname ( var_0 ) : - return sorted ( var_2 * var_2 for var_2 in var_0 ) -",,0 -171,259_3Sum_Smaller_1.py,"def binarySearch( nums, start, target): - left, right = start, len(nums) - 1 - while left < right: - mid = (left + right + 1) / 2 - if nums[mid] < target: - - left = mid - else: - right = mid - 1 - return left","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_3 , var_6 = var_1 , len ( var_0 ) - 1 - while var_3 < var_6 : - var_8 = ( var_3 + var_6 + 1 ) / 2 - if var_0 [ var_8 ] < var_2 : - var_3 = var_8 - else : - var_6 = var_8 - 1 - return var_3 -",12,2 -172,268_Missing_Number_1.py,"def missingNumber( nums): - n = len(nums) - return (n ** 2 + n) / 2 - sum(nums)","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - return ( var_2 ** 2 + var_2 ) / 2 - sum ( var_0 ) -",2,1 -173,296_Best_Meeting_Point_4.py,"def collectCols( grid): - cols = [] - for j in range(len(grid[0])): - for i in range(len(grid)): - if grid[i][j] == 1: - cols.append(j) - return cols","def sample_funcname ( var_0 ) : - var_1 = [ ] - for var_5 in range ( len ( var_0 [ 0 ] ) ) : - for var_6 in range ( len ( var_0 ) ) : - if var_0 [ var_6 ] [ var_5 ] == 1 : - var_1.append ( var_5 ) - return var_1 -",10,2 -174,099_Recover_Binary_Search_Tree_1.py,"def recoverTree( root): - pre = first = second = None - while root is not None: - if root.left is not None: - temp = root.left - while temp.right is not None and temp.right != root: - temp = temp.right - if temp.right is not None: - if pre is not None and pre.val > root.val: - if first is None: - first = pre - second = root - pre = root - temp.right = None - root = root.right - else: - temp.right = root - root = root.left - else: - if pre is not None and pre.val > root.val: - if first is None: - first = pre - second = root - pre = root - root = root.right - - if first is not None and second is not None: - first.val, second.val = second.val, first.val","def sample_funcname ( var_0 ) : - var_4 = var_1 = var_2 = None - while var_0 is not None : - if var_0.left is not None : - var_6 = var_0.left - while var_6.right is not None and var_6.right != var_0 : - var_6 = var_6.right - if var_6.right is not None : - if var_4 is not None and var_4.val > var_0.val : - if var_1 is None : - var_1 = var_4 - var_2 = var_0 - var_4 = var_0 - var_6.right = None - var_0 = var_0.right - else : - var_6.right = var_0 - var_0 = var_0.left - else : - if var_4 is not None and var_4.val > var_0.val : - if var_1 is None : - var_1 = var_4 - var_2 = var_0 - var_4 = var_0 - var_0 = var_0.right - if var_1 is not None and var_2 is not None : - var_1.val , var_2.val = var_2.val , var_1.val -",None,1 -175,009_Palindrome_Number_2.py,"def isPalindrome( x): - if x < 0: - return False - ls = len(str(x)) - tmp = x - for i in range(int(ls/2)): - right = int(tmp % 10) - left = tmp / (10 ** (ls - 2 * i - 1)) - left = int(left % 10) - if left != right: - return False - tmp = tmp // 10 - return True","def sample_funcname ( var_0 ) : - if var_0 < 0 : - return False - var_5 = len ( str ( var_0 ) ) - var_6 = var_0 - for var_10 in range ( int ( var_5 / 2 ) ) : - var_12 = int ( var_6 % 10 ) - var_14 = var_6 / ( 10 ** ( var_5 - 2 * var_10 - 1 ) ) - var_14 = int ( var_14 % 10 ) - if var_14 != var_12 : - return False - var_6 = var_6 // 10 - return True -",10012,4 -176,156_Binary_Tree_Upside_Down_1.py,"def upsideDownBinaryTree( root): - node, parent, parentRight = root, None, None - while node is not None: - left = node.left - node.left = parentRight - parentRight = node.right - node.right = parent - parent = node - node = left - return parent","def sample_funcname ( var_0 ) : - var_1 , var_3 , var_4 = var_0 , None , None - while var_1 is not None : - left = var_1.left - var_1.left = var_4 - var_4 = var_1.right - var_1.right = var_3 - var_3 = var_1 - var_1 = left - return var_3 -",None,1 -177,078_Subsets_1.py,"def get_subsets( nums, magic): - res = [] - for i in range(len(nums)): - if (1 << i) & magic != 0: - res.append(nums[i]) - return res","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - for var_5 in range ( len ( var_0 ) ) : - if ( 1 << var_5 ) & var_1 != 0 : - var_2.append ( var_0 [ var_5 ] ) - return var_2 -",10,2 -178,142_Linked_List_Cycle_II_1.py,"def detectCycle( head): - try: - fast = head.next.next - slow = head.next - - while fast != slow: - fast = fast.next.next - slow = slow.next - except: - return None - slow = head - while fast != slow: - fast = fast.next - slow = slow.next - return fast","def sample_funcname ( var_0 ) : - try : - var_2 = var_0.next.next - var_3 = var_0.next - while var_2 != var_3 : - var_2 = var_2.next.next - var_3 = var_3.next - except : - return None - var_3 = var_0 - while var_2 != var_3 : - var_2 = var_2.next - var_3 = var_3.next - return var_2 -",None,1 -179,876_Middle_of_the_Linked_List_2.py,"def middleNode( head): - fast = slow = head - while fast and fast.next: - slow = slow.next - fast = fast.next.next - return slow","def sample_funcname ( var_0 ) : - var_2 = var_1 = var_0 - while var_2 and var_2.next : - var_1 = var_1.next - var_2 = var_2.next.next - return var_1 -",,0 -180,053_Maximum_Subarray_2.py,"def maxSubArray( nums): - ls = len(nums) - start, all = nums[-1], nums[-1] - for i in reversed(range(ls - 1)): - start = max(nums[i], nums[i] + start) - all = max(start, all) - return all","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_4 , var_5 = var_0 [ - 1 ] , var_0 [ - 1 ] - for var_8 in reversed ( range ( var_2 - 1 ) ) : - var_4 = max ( var_0 [ var_8 ] , var_0 [ var_8 ] + var_4 ) - var_5 = max ( var_4 , var_5 ) - return var_5 -",1,1 -181,001_Two_Sum_1.py,"def twoSum( nums, target): - ls = len(nums) - for i in range(ls): - for j in range(i + 1, ls): - if nums[i] + nums[j] == target: - return [i, j]","def sample_funcname ( var_0 , var_1 ) : - var_3 = len ( var_0 ) - for var_5 in range ( var_3 ) : - for var_7 in range ( var_5 + 1 , var_3 ) : - if var_0 [ var_5 ] + var_0 [ var_7 ] == var_1 : - return [ var_5 , var_7 ] -",1,1 -182,236_Lowest_Common_Ancestor_of_a_Binary_Tree_1.py,"def lowestCommonAncestor( root, p, q): - stack = [root] - parent = {root: None} - while p not in parent or q not in parent: - - node = stack.pop() - - if node.left: - parent[node.left] = node - stack.append(node.left) - if node.right: - parent[node.right] = node - stack.append(node.right) - - ancestors = set() - - while p: - ancestors.add(p) - p = parent[p] - - while q not in ancestors: - q = parent[q] - return q","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_3 = [ var_0 ] - var_5 = { var_0 : None } - while var_1 not in var_5 or var_2 not in var_5 : - var_7 = var_3.pop ( ) - if var_7.left : - var_5 [ var_7.left ] = var_7 - var_3.append ( var_7.left ) - if var_7.right : - var_5 [ var_7.right ] = var_7 - var_3.append ( var_7.right ) - var_12 = set ( ) - while var_1 : - var_12.add ( var_1 ) - var_1 = var_5 [ var_1 ] - while var_2 not in var_12 : - var_2 = var_5 [ var_2 ] - return var_2 -",None,1 -183,283_Move Zeroes_1.py,"def moveZeroes( nums): - ls = len(nums) - pos = 0 - while pos < ls: - if nums[pos] == 0: - curr = pos + 1 - while curr < ls: - if nums[curr] != 0: - temp = nums[curr] - nums[curr] = nums[pos] - nums[pos] = temp - break - curr += 1 - pos += 1","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_4 = 0 - while var_4 < var_2 : - if var_0 [ var_4 ] == 0 : - var_6 = var_4 + 1 - while var_6 < var_2 : - if var_0 [ var_6 ] != 0 : - var_7 = var_0 [ var_6 ] - var_0 [ var_6 ] = var_0 [ var_4 ] - var_0 [ var_4 ] = var_7 - break - var_6 += 1 - var_4 += 1 -",10,2 -184,340_Longest_Substring_with_At_Most_K_Distinct_Characters_1.py,"def lengthOfLongestSubstringKDistinct( s, k): - count = [0] * 256 - i, numDistinct, maxLen = 0, 0, 0 - for j in range(len(s)): - if count[ord(s[j])] == 0: - numDistinct += 1 - count[ord(s[j])] += 1 - while numDistinct > k: - count[ord(s[i])] -= 1 - if count[ord(s[i])] == 0: - numDistinct -= 1 - i += 1 - maxLen = max(j - i + 1, maxLen) - return maxLen","def sample_funcname ( var_0 , var_1 ) : - var_4 = [ 0 ] * 256 - var_5 , var_6 , var_7 = 0 , 0 , 0 - for var_10 in range ( len ( var_0 ) ) : - if var_4 [ ord ( var_0 [ var_10 ] ) ] == 0 : - var_6 += 1 - var_4 [ ord ( var_0 [ var_10 ] ) ] += 1 - while var_6 > var_1 : - var_4 [ ord ( var_0 [ var_5 ] ) ] -= 1 - if var_4 [ ord ( var_0 [ var_5 ] ) ] == 0 : - var_6 -= 1 - var_5 += 1 - var_7 = max ( var_10 - var_5 + 1 , var_7 ) - return var_7 -",10256,3 -185,485_Max_Consecutive_Ones_1.py,"def findMaxConsecutiveOnes( nums): - ans = 0 - curr = 0 - for n in nums: - if n == 1: - curr += 1 - if curr > ans: - ans = curr - else: - curr = 0 - return ans","def sample_funcname ( var_0 ) : - var_2 = 0 - var_3 = 0 - for var_4 in var_0 : - if var_4 == 1 : - var_3 += 1 - if var_3 > var_2 : - var_2 = var_3 - else : - var_3 = 0 - return var_2 -",10,2 -186,946_Validate_Stack_Sequences_1.py,"def validateStackSequences( pushed, popped): - in_stack = [] - pos = 0 - while pos != len(pushed): - curr = pushed[pos] - while len(in_stack) > 0 and len(popped) > 0 and in_stack[-1] == popped[0]: - in_stack.pop(-1) - popped.pop(0) - if len(popped) == 0: - break - if curr == popped[0]: - popped.pop(0) - else: - in_stack.append(curr) - pos += 1 - while len(in_stack) > 0 and len(popped) > 0 and in_stack[-1] == popped[0]: - in_stack.pop(-1) - popped.pop(0) - if len(in_stack) == 0: - return True - return False","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - var_4 = 0 - while var_4 != len ( var_0 ) : - var_6 = var_0 [ var_4 ] - while len ( var_2 ) > 0 and len ( var_1 ) > 0 and var_2 [ - 1 ] == var_1 [ 0 ] : - var_2.pop ( - 1 ) - var_1.pop ( 0 ) - if len ( var_1 ) == 0 : - break - if var_6 == var_1 [ 0 ] : - var_1.pop ( 0 ) - else : - var_2.append ( var_6 ) - var_4 += 1 - while len ( var_2 ) > 0 and len ( var_1 ) > 0 and var_2 [ - 1 ] == var_1 [ 0 ] : - var_2.pop ( - 1 ) - var_1.pop ( 0 ) - if len ( var_2 ) == 0 : - return True - return False -",10,2 -187,728_Self_Dividing_Numbers_1.py,"def selfDividingNumbers( left: int, right: int) -> List[int]: - return [x for x in range(left, right+1) if all([int(i) != 0 and x % int(i)==0 for i in str(x)])]","def sample_funcname ( var_0 : int , var_2 : int ) -> List [ int ] : - return [ var_4 for var_4 in range ( var_0 , var_2 + 1 ) if all ( [ int ( var_8 ) != 0 and var_4 % int ( var_8 ) == 0 for var_8 in str ( var_4 ) ] ) ] -",10,2 -188,080_Remove_Duplicates_from_Sorted_Array_II_1.py,"def removeDuplicates( nums): - if nums is None: - return 0 - length = len(nums) - result = 0 - i = j = 0 - while i < length: - j = i - while j < length: - if nums[j] != nums[i]: - break - j += 1 - if j-i > 2: - length -= j-i-2 - for k in range(j-i-2): - del nums[i] - result += 2 - j = i+2 - else: - result += (j-i) - i = j - return result","def sample_funcname ( var_0 ) : - if var_0 is None : - return 0 - var_4 = len ( var_0 ) - var_5 = 0 - var_7 = var_6 = 0 - while var_7 < var_4 : - var_6 = var_7 - while var_6 < var_4 : - if var_0 [ var_6 ] != var_0 [ var_7 ] : - break - var_6 += 1 - if var_6 - var_7 > 2 : - var_4 -= var_6 - var_7 - 2 - for var_11 in range ( var_6 - var_7 - 2 ) : - del var_0 [ var_7 ] - var_5 += 2 - var_6 = var_7 + 2 - else : - var_5 += ( var_6 - var_7 ) - var_7 = var_6 - return var_5 -",10None2,4 -189,131_Palindrome_Partitioning_1.py,"def isPalindrome( s, begin, end): - while begin < end: - if s[begin] != s[end]: - return False - begin += 1 - end -= 1 - return True","def sample_funcname ( var_0 , var_1 , var_2 ) : - while var_1 < var_2 : - if var_0 [ var_1 ] != var_0 [ var_2 ] : - return False - var_1 += 1 - var_2 -= 1 - return True -",1,1 -190,1108_Defanging_an_IP_Address_1.py,"def defangIPaddr( address: str) -> str: - return address.replace('.', '[.]')","def sample_funcname ( var_0 : str ) -> str : - return var_0.replace ( '.' , '[.]' ) -",[.].,2 -191,350_Intersection_of_Two_Arrays_II_1.py,"def intersect( nums1, nums2): - nums1.sort() - nums2.sort() - res = [] - pos1 = pos2 = 0 - while pos1 < len(nums1) and pos2 < len(nums2): - if nums1[pos1] == nums2[pos2]: - res.append(nums1[pos1]) - pos1 += 1 - pos2 += 1 - elif nums1[pos1] < nums2[pos2]: - pos1 += 1 - else: - pos2 += 1 - return res","def sample_funcname ( var_0 , var_1 ) : - var_0.sort ( ) - var_1.sort ( ) - var_3 = [ ] - var_6 = var_4 = 0 - while var_6 < len ( var_0 ) and var_4 < len ( var_1 ) : - if var_0 [ var_6 ] == var_1 [ var_4 ] : - var_3.append ( var_0 [ var_6 ] ) - var_6 += 1 - var_4 += 1 - elif var_0 [ var_6 ] < var_1 [ var_4 ] : - var_6 += 1 - else : - var_4 += 1 - return var_3 -",10,2 -192,141_Linked_List_Cycle_1.py,"def hasCycle( head): - if head is None: - return False - count = 0 - max = 100000 - pos = head - while pos is not None: - count += 1 - pos = pos.next - if count > max: - return True - return False","def sample_funcname ( var_0 ) : - if var_0 is None : - return False - var_4 = 0 - var_6 = 100000 - var_7 = var_0 - while var_7 is not None : - var_4 += 1 - var_7 = var_7.next - if var_4 > var_6 : - return True - return False -",10100000None,4 -194,003_Longest_Substring_Without_Repeating_Characters_1.py,"def lengthOfLongestSubstring( s): - sls = len(set(s)) - ls = len(s) - if ls >= 1: - max_l = 1 - else: - return 0 - for i in range(ls): - for j in range(i + max_l + 1, i + sls + 1): - curr = s[i:j] - c_ls = len(curr) - if len(set(curr)) != c_ls: - break - else: - if c_ls > max_l: - max_l = c_ls - if max_l == sls: - return sls - return max_l","def sample_funcname ( var_0 ) : - var_3 = len ( set ( var_0 ) ) - var_4 = len ( var_0 ) - if var_4 >= 1 : - var_6 = 1 - else : - return 0 - for var_9 in range ( var_4 ) : - for var_10 in range ( var_9 + var_6 + 1 , var_9 + var_3 + 1 ) : - var_11 = var_0 [ var_9 : var_10 ] - var_12 = len ( var_11 ) - if len ( set ( var_11 ) ) != var_12 : - break - else : - if var_12 > var_6 : - var_6 = var_12 - if var_6 == var_3 : - return var_3 - return var_6 -",10,2 -195,296_Best_Meeting_Point_3.py,"def collectRows( grid): - rows = [] - for i in range(len(grid)): - for j in range(len(grid[0])): - if grid[i][j] == 1: - rows.append(i) - return rows","def sample_funcname ( var_0 ) : - var_1 = [ ] - for var_4 in range ( len ( var_0 ) ) : - for var_6 in range ( len ( var_0 [ 0 ] ) ) : - if var_0 [ var_4 ] [ var_6 ] == 1 : - var_1.append ( var_4 ) - return var_1 -",10,2 -196,434_Number_of_Segments_in_a_String_1.py,"def countSegments( s): - return len(s.split())","def sample_funcname ( var_0 ) : - return len ( var_0.split ( ) ) -",,0 -197,015_3Sum_2.py,"def threeSum( nums): - res = [] - nums.sort() - ls = len(nums) - for i in range(ls - 2): - if i > 0 and nums[i] == nums[i - 1]: - continue - j = i + 1 - k = ls - 1 - while j < k: - curr = nums[i] + nums[j] + nums[k] - if curr == 0: - res.append([nums[i], nums[j], nums[k]]) - while j < k and nums[j] == nums[j + 1]: - j += 1 - while j < k and nums[k] == nums[k - 1]: - k -= 1 - j += 1 - k -= 1 - elif curr < 0: - j += 1 - else: - k -= 1 - return res","def sample_funcname ( var_0 ) : - var_1 = [ ] - var_0.sort ( ) - var_4 = len ( var_0 ) - for var_7 in range ( var_4 - 2 ) : - if var_7 > 0 and var_0 [ var_7 ] == var_0 [ var_7 - 1 ] : - continue - var_10 = var_7 + 1 - var_11 = var_4 - 1 - while var_10 < var_11 : - var_12 = var_0 [ var_7 ] + var_0 [ var_10 ] + var_0 [ var_11 ] - if var_12 == 0 : - var_1.append ( [ var_0 [ var_7 ] , var_0 [ var_10 ] , var_0 [ var_11 ] ] ) - while var_10 < var_11 and var_0 [ var_10 ] == var_0 [ var_10 + 1 ] : - var_10 += 1 - while var_10 < var_11 and var_0 [ var_11 ] == var_0 [ var_11 - 1 ] : - var_11 -= 1 - var_10 += 1 - var_11 -= 1 - elif var_12 < 0 : - var_10 += 1 - else : - var_11 -= 1 - return var_1 -",102,3 -198,132_Palindrome_Partitioning_II_1.py,"def minCut( s): - if len(s) <= 1: - return 0 - ls = len(s) - d = [0] * ls - pal = [[False] * ls for _ in range(ls)] - for i in range(ls - 1, -1, -1): - d[i] = ls - i - 1 - for j in range(i, ls): - if s[i] == s[j] and (j - i < 2 or pal[i + 1][j - 1]): - pal[i][j] = True - if j == ls - 1: - d[i] = 0 - elif d[j + 1] + 1 < d[i]: - d[i] = d[j + 1] + 1 - return d[0]","def sample_funcname ( var_0 ) : - if len ( var_0 ) <= 1 : - return 0 - var_4 = len ( var_0 ) - var_5 = [ 0 ] * var_4 - var_9 = [ [ False ] * var_4 for var_7 in range ( var_4 ) ] - for var_10 in range ( var_4 - 1 , - 1 , - 1 ) : - var_5 [ var_10 ] = var_4 - var_10 - 1 - for var_11 in range ( var_10 , var_4 ) : - if var_0 [ var_10 ] == var_0 [ var_11 ] and ( var_11 - var_10 < 2 or var_9 [ var_10 + 1 ] [ var_11 - 1 ] ) : - var_9 [ var_10 ] [ var_11 ] = True - if var_11 == var_4 - 1 : - var_5 [ var_10 ] = 0 - elif var_5 [ var_11 + 1 ] + 1 < var_5 [ var_10 ] : - var_5 [ var_10 ] = var_5 [ var_11 + 1 ] + 1 - return var_5 [ 0 ] -",102,3 -199,163_Missing_Ranges_1.py,"def findMissingRanges( nums, lower, upper): - ranges = [] - prev = lower - 1 - for i in range(len(nums) + 1): - if i == len(nums): - curr = upper + 1 - else: - curr = nums[i] - if curr - prev > 2: - ranges.append(""%d->%d"" % (prev + 1, curr - 1)) - elif curr - prev == 2: - ranges.append(""%d"" % (prev + 1)) - prev = curr - return ranges","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_3 = [ ] - var_5 = var_1 - 1 - for var_8 in range ( len ( var_0 ) + 1 ) : - if var_8 == len ( var_0 ) : - var_9 = var_2 + 1 - else : - var_9 = var_0 [ var_8 ] - if var_9 - var_5 > 2 : - var_3.append ( ""%d->%d"" % ( var_5 + 1 , var_9 - 1 ) ) - elif var_9 - var_5 == 2 : - var_3.append ( ""%d"" % ( var_5 + 1 ) ) - var_5 = var_9 - return var_3 -",1%d->%d2%d,4 -200,035_Search_Insert_Position_2.py,"def searchInsert( nums, target): - l, r = int(0), len(nums) - 1 - while l < r: - mid = int((l + r) / 2) - if nums[mid] < target: - l = mid + 1 - else: - r = mid - if nums[l] < target: - return l + 1 - return l","def sample_funcname ( var_0 , var_1 ) : - var_4 , var_7 = int ( 0 ) , len ( var_0 ) - 1 - while var_4 < var_7 : - var_9 = int ( ( var_4 + var_7 ) / 2 ) - if var_0 [ var_9 ] < var_1 : - var_4 = var_9 + 1 - else : - var_7 = var_9 - if var_0 [ var_4 ] < var_1 : - return var_4 + 1 - return var_4 -",102,3 -201,007_Reverse_Integer_2.py,"def reverse( x): - res, isPos = 0, 1 - if x < 0: - isPos = -1 - x = -1 * x - while x != 0: - res = res * 10 + x % 10 - if res > 2147483647: - return 0 - x /= 10 - return res * isPos","def sample_funcname ( var_0 ) : - var_2 , var_4 = 0 , 1 - if var_0 < 0 : - var_4 = - 1 - var_0 = - 1 * var_0 - while var_0 != 0 : - var_2 = var_2 * 10 + var_0 % 10 - if var_2 > 2147483647 : - return 0 - var_0 /= 10 - return var_2 * var_4 -",10102147483647,4 -202,409_Longest_Palindrome_1.py,"def longestPalindrome( s): - ans = 0 - char_map = {} - for c in s: - char_map[c] = char_map.get(c, 0) + 1 - for c in char_map.keys(): - if char_map[c] % 2 == 0: - ans += char_map.pop(c) - else: - ans += char_map[c] / 2 * 2 - if len(char_map) != 0: - ans += 1 - return ans","def sample_funcname ( var_0 ) : - var_2 = 0 - var_3 = { } - for var_4 in var_0 : - var_3 [ var_4 ] = var_3.get ( var_4 , 0 ) + 1 - for var_4 in var_3.keys ( ) : - if var_3 [ var_4 ] % 2 == 0 : - var_2 += var_3.pop ( var_4 ) - else : - var_2 += var_3 [ var_4 ] / 2 * 2 - if len ( var_3 ) != 0 : - var_2 += 1 - return var_2 -",102,3 -203,482_License_Key_Formatting_1.py,"def licenseKeyFormatting( S, K): - S = S.upper().replace('-', '') - ls = len(S) - if ls % K == 0: - pos = K - else: - pos = ls % K - res = S[:pos] - while pos < ls: - res += '-' + S[pos:pos + K] - pos += K - return res","def sample_funcname ( var_0 , var_1 ) : - var_0 = var_0.var_2 ( ).replace ( '-' , '' ) - var_7 = len ( var_0 ) - if var_7 % var_1 == 0 : - var_9 = var_1 - else : - var_9 = var_7 % var_1 - var_10 = var_0 [ : var_9 ] - while var_9 < var_7 : - var_10 += '-' + var_0 [ var_9 : var_9 + var_1 ] - var_9 += var_1 - return var_10 -",0-,3 -204,538_Convert_BST_to_Greater_Tree_1.py,"def convertBST( root): - total = 0 - - node = root - stack = [] - while stack or node is not None: - while node is not None: - stack.append(node) - node = node.right - - node = stack.pop() - total += node.val - node.val = total - - node = node.left - - return root","def sample_funcname ( var_0 ) : - var_2 = 0 - var_3 = var_0 - var_4 = [ ] - while var_4 or var_3 is not None : - while var_3 is not None : - var_4.append ( var_3 ) - var_3 = var_3.right - var_3 = var_4.pop ( ) - var_2 += var_3.val - var_3.val = var_2 - var_3 = var_3.left - return var_0 -",0None,2 -205,697_Degree_of_an_Array_2.py,"def findShortestSubArray( nums): - left, right, count = {}, {}, {} - for i, x in enumerate(nums): - if x not in left: left[x] = i - right[x] = i - count[x] = count.get(x, 0) + 1 - - ans = len(nums) - degree = max(count.values()) - for x in count: - if count[x] == degree: - ans = min(ans, right[x] - left[x] + 1) - - return ans","def sample_funcname ( var_0 ) : - var_1 , var_2 , var_3 = { } , { } , { } - for var_5 , var_6 in enumerate ( var_0 ) : - if var_6 not in var_1 : var_1 [ var_6 ] = var_5 - var_2 [ var_6 ] = var_5 - var_3 [ var_6 ] = var_3.get ( var_6 , 0 ) + 1 - var_11 = len ( var_0 ) - var_14 = max ( var_3.values ( ) ) - for var_6 in var_3 : - if var_3 [ var_6 ] == var_14 : - var_11 = min ( var_11 , var_2 [ var_6 ] - var_1 [ var_6 ] + 1 ) - return var_11 -",10,2 -206,243_Shortest_Word_Distance_2.py,"def shortestDistance( words, word1, word2): - index1 = index2 = -1 - res = len(words) - for index, word in enumerate(words): - if word1 == word: - index1 = index - elif word2 == word: - index2 = index - if index1 != -1 and index2 != -1: - res = min(res, abs(index1 - index2)) - return res","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_5 = var_3 = - 1 - var_7 = len ( var_0 ) - for var_9 , var_10 in enumerate ( var_0 ) : - if var_1 == var_10 : - var_5 = var_9 - elif var_2 == var_10 : - var_3 = var_9 - if var_5 != - 1 and var_3 != - 1 : - var_7 = min ( var_7 , abs ( var_5 - var_3 ) ) - return var_7 -",1,1 -207,581_Shortest_Unsorted_Continuous_Subarray_2.py,"def findUnsortedSubarray( nums): - stack = [] - l, r = len(nums), 0 - for i in range(len(nums)): - while len(stack) != 0 and nums[stack[-1]] > nums[i]: - l = min(l, stack.pop()) - stack.append(i) - stack = [] - for i in range(len(nums) - 1, -1, -1): - while len(stack) != 0 and nums[stack[-1]] < nums[i]: - r = max(r, stack.pop()) - stack.append(i) - if r > l: - return r - l + 1 - return 0","def sample_funcname ( var_0 ) : - var_1 = [ ] - var_3 , var_5 = len ( var_0 ) , 0 - for var_7 in range ( len ( var_0 ) ) : - while len ( var_1 ) != 0 and var_0 [ var_1 [ - 1 ] ] > var_0 [ var_7 ] : - var_3 = min ( var_3 , var_1.pop ( ) ) - var_1.append ( var_7 ) - var_1 = [ ] - for var_7 in range ( len ( var_0 ) - 1 , - 1 , - 1 ) : - while len ( var_1 ) != 0 and var_0 [ var_1 [ - 1 ] ] < var_0 [ var_7 ] : - var_5 = max ( var_5 , var_1.pop ( ) ) - var_1.append ( var_7 ) - if var_5 > var_3 : - return var_5 - var_3 + 1 - return 0 -",10,2 -208,122_Best_Time_to_Buy_and_Sell_Stock_II_1.py,"def maxProfit( prices): - return sum([y - x for x, y in zip(prices[0:-1], prices[1:]) if x < y])","def sample_funcname ( var_0 ) : - return sum ( [ var_2 - var_3 for var_3 , var_2 in zip ( var_0 [ 0 : - 1 ] , var_0 [ 1 : ] ) if var_3 < var_2 ] ) -",10,2 -209,1310_XOR_Queries_of_a_Subarray_2.py,"def xorQueries( arr: List[int], queries: List[List[int]]) -> List[int]: - for i in range(len(arr) - 1): - arr[i + 1] ^= arr[i] - return [arr[j] ^ arr[i - 1] if i else arr[j] for i, j in queries]","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ List [ int ] ] ) -> List [ int ] : - for var_7 in range ( len ( var_0 ) - 1 ) : - var_0 [ var_7 + 1 ] ^= var_0 [ var_7 ] - return [ var_0 [ var_8 ] ^ var_0 [ var_7 - 1 ] if var_7 else var_0 [ var_8 ] for var_7 , var_8 in var_3 ] -",1,1 -210,836_Rectangle_Overlap_2.py,"def intersect(p_left, p_right, q_left, q_right): - return min(p_right, q_right) > max(p_left, q_left)","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - return min ( var_1 , var_3 ) > max ( var_0 , var_2 ) -",,0 -211,191_Number_of_1_Bits_2.py,"def hammingWeight( n): - count = 0 - while n: - n &= n - 1 - count += 1 - return count","def sample_funcname ( var_0 ) : - var_2 = 0 - while var_0 : - var_0 &= var_0 - 1 - var_2 += 1 - return var_2 -",10,2 -212,028_Implement_strStr()_1.py,"def strStr( haystack, needle): - lsh, lsn = len(haystack), len(needle) - if lsn == 0: - return 0 - pos, index = 0, 0 - while index <= lsh - lsn: - if haystack[index] == needle[pos]: - backup = index - while index < lsh and pos < lsn and haystack[index] == needle[pos]: - pos += 1 - index += 1 - if pos == len(needle): - return index - pos - index = backup - index += 1 - pos = 0 - return -1","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = len ( var_0 ) , len ( var_1 ) - if var_4 == 0 : - return 0 - var_6 , var_7 = 0 , 0 - while var_7 <= var_3 - var_4 : - if var_0 [ var_7 ] == var_1 [ var_6 ] : - var_8 = var_7 - while var_7 < var_3 and var_6 < var_4 and var_0 [ var_7 ] == var_1 [ var_6 ] : - var_6 += 1 - var_7 += 1 - if var_6 == len ( var_1 ) : - return var_7 - var_6 - var_7 = var_8 - var_7 += 1 - var_6 = 0 - return - 1 -",10,2 -213,107_Binary_Tree_Level_Order_Traversal_II_1.py,"def levelOrderBottom( root): - if root is None: - return [] - stack = [[root]] - res = [] - while len(stack) > 0: - top = stack.pop() - res.insert(0, [t.val for t in top]) - temp = [] - for node in top: - if node.left is not None: - temp.append(node.left) - if node.right is not None: - temp.append(node.right) - if len(temp) > 0: - stack.append(temp) - return res","def sample_funcname ( var_0 ) : - if var_0 is None : - return [ ] - var_2 = [ [ var_0 ] ] - var_3 = [ ] - while len ( var_2 ) > 0 : - var_7 = var_2.pop ( ) - var_3.insert ( 0 , [ var_9.val for var_9 in var_7 ] ) - var_11 = [ ] - for var_12 in var_7 : - if var_12.left is not None : - var_11.append ( var_12.left ) - if var_12.right is not None : - var_11.append ( var_12.right ) - if len ( var_11 ) > 0 : - var_2.append ( var_11 ) - return var_3 -",0None,2 -214,229_Majority_Element_II_2.py,"def majorityElement( nums): - count_hash = {} - res = [] - for i in nums: - try: - count_hash[i] += 1 - except KeyError: - count_hash[i] = 1 - for k, v in count_hash.iteritems(): - if v > len(nums) / 3: - res.append(k) - return res","def sample_funcname ( var_0 ) : - var_1 = { } - var_2 = [ ] - for var_3 in var_0 : - try : - var_1 [ var_3 ] += 1 - except KeyError : - var_1 [ var_3 ] = 1 - for var_7 , var_8 in var_1.iteritems ( ) : - if var_8 > len ( var_0 ) / 3 : - var_2.append ( var_7 ) - return var_2 -",31,2 -215,475_Heaters_1.py,"def findRadius( houses, heaters): - heaters = sorted(heaters) + [float('inf')] - i = r = 0 - for x in sorted(houses): - while x >= sum(heaters[i:i + 2]) / 2.: - i += 1 - r = max(r, abs(heaters[i] - x)) - return r","def sample_funcname ( var_0 , var_1 ) : - var_1 = sorted ( var_1 ) + [ float ( 'inf' ) ] - var_7 = var_5 = 0 - for var_8 in sorted ( var_0 ) : - while var_8 >= sum ( var_1 [ var_7 : var_7 + 2 ] ) / 2.: - var_7 += 1 - var_5 = max ( var_5 , abs ( var_1 [ var_7 ] - var_8 ) ) - return var_5 -",02.2inf1,5 -216,130_Surrounded_Regions_2.py,"def solve( board): - if not any(board): return - - height, width = len(board), len(board[0]) - save = [ij for k in range(height + width) for ij in ((0, k), (height - 1, k), (k, 0), (k, width - 1))] - while save: - i, j = save.pop() - if 0 <= i < height and 0 <= j < width and board[i][j] == 'O': - board[i][j] = 'S' - save += (i, j - 1), (i, j + 1), (i - 1, j), (i + 1, j) - board[:] = [['XO'[c == 'S'] for c in row] for row in board]","def sample_funcname ( var_0 ) : - if not any ( var_0 ) : return - var_3 , var_5 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_10 = [ var_6 for var_7 in range ( var_3 + var_5 ) for var_6 in ( ( 0 , var_7 ) , ( var_3 - 1 , var_7 ) , ( var_7 , 0 ) , ( var_7 , var_5 - 1 ) ) ] - while var_10 : - var_12 , var_13 = var_10.pop ( ) - if 0 <= var_12 < var_3 and 0 <= var_13 < var_5 and var_0 [ var_12 ] [ var_13 ] == 'O' : - var_0 [ var_12 ] [ var_13 ] = 'S' - var_10 += ( var_12 , var_13 - 1 ) , ( var_12 , var_13 + 1 ) , ( var_12 - 1 , var_13 ) , ( var_12 + 1 , var_13 ) - var_0 [ : ] = [ [ 'XO' [ var_17 == 'S' ] for var_17 in var_18 ] for var_18 in var_0 ] -",0SXO1O,5 -217,067_Add_Binary_2.py,"def addBinary( a, b): - res = '' - lsa, lsb = len(a), len(b) - pos, plus, curr = -1, 0, 0 - while (lsa + pos) >= 0 or (lsb + pos) >= 0: - if (lsa + pos) >= 0: - curr += int(a[pos]) - if (lsb + pos) >= 0: - curr += int(b[pos]) - res = str(curr % 2) + res - curr //= 2 - pos -= 1 - if curr == 1: - res = '1' + res - return res","def sample_funcname ( var_0 , var_1 ) : - var_3 = '' - var_5 , var_6 = len ( var_0 ) , len ( var_1 ) - var_8 , var_10 , var_11 = - 1 , 0 , 0 - while ( var_5 + var_8 ) >= 0 or ( var_6 + var_8 ) >= 0 : - if ( var_5 + var_8 ) >= 0 : - var_11 += int ( var_0 [ var_8 ] ) - if ( var_6 + var_8 ) >= 0 : - var_11 += int ( var_1 [ var_8 ] ) - var_3 = str ( var_11 % 2 ) + var_3 - var_11 //= 2 - var_8 -= 1 - if var_11 == 1 : - var_3 = '1' + var_3 - return var_3 -",0211,5 -218,605_Can_Place_Flowers_1.py,"def canPlaceFlowers( flowerbed, n): - count = 0 - for i in range(len(flowerbed)): - curr = flowerbed[i] - if i - 1 >= 0: - curr += flowerbed[i - 1] - if i + 1 < len(flowerbed): - curr += flowerbed[i + 1] - if curr == 0: - count += 1 - flowerbed[i] = 1 - if count >= n: - return True - return False","def sample_funcname ( var_0 , var_1 ) : - var_3 = 0 - for var_6 in range ( len ( var_0 ) ) : - var_7 = var_0 [ var_6 ] - if var_6 - 1 >= 0 : - var_7 += var_0 [ var_6 - 1 ] - if var_6 + 1 < len ( var_0 ) : - var_7 += var_0 [ var_6 + 1 ] - if var_7 == 0 : - var_3 += 1 - var_0 [ var_6 ] = 1 - if var_3 >= var_1 : - return True - return False -",10,2 -219,103_Binary_Tree_Zigzag_Level_Order_Traversal_1.py,"def zigzagLevelOrder( root): - if root is None: - return [] - q = [[root]] - for level in q: - record = [] - for node in level: - if node.left: - record.append(node.left) - if node.right: - record.append(node.right) - if record: - q.append(record) - res = [] - for index, level in enumerate(q): - temp = [x.val for x in level] - if index % 2 == 0: - res.append(temp) - else: - res.append(temp[::-1]) - return res","def sample_funcname ( var_0 ) : - if var_0 is None : - return [ ] - var_2 = [ [ var_0 ] ] - for var_3 in var_2 : - var_4 = [ ] - for var_5 in var_3 : - if var_5.left : - var_4.append ( var_5.left ) - if var_5.right : - var_4.append ( var_5.right ) - if var_4 : - var_2.append ( var_4 ) - var_9 = [ ] - for var_11 , var_3 in enumerate ( var_2 ) : - var_14 = [ var_13.val for var_13 in var_3 ] - if var_11 % 2 == 0 : - var_9.append ( var_14 ) - else : - var_9.append ( var_14 [ : : - 1 ] ) - return var_9 -",10None2,4 -220,259_3Sum_Smaller_2.py,"def twoSumSmaller( nums, start, target): - res, left, right = 0, start, len(nums) - 1 - while left < right: - if nums[left] + nums[right] < target: - res += right - left - left += 1 - else: - right -= 1 - return res","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_4 , var_5 , var_8 = 0 , var_1 , len ( var_0 ) - 1 - while var_5 < var_8 : - if var_0 [ var_5 ] + var_0 [ var_8 ] < var_2 : - var_4 += var_8 - var_5 - var_5 += 1 - else : - var_8 -= 1 - return var_4 -",10,2 -221,252_Meeting_Rooms_2.py,"def canAttendMeetings( intervals): - intervals.sort(key=lambda x: x.start) - ls = len(intervals) - for i in range(ls - 1): - if intervals[i].end > intervals[i + 1].start: - return False - return True","def sample_funcname ( var_0 ) : - var_0.sort ( var_2 = lambda var_3 : var_3.start ) - var_6 = len ( var_0 ) - for var_9 in range ( var_6 - 1 ) : - if var_0 [ var_9 ].end > var_0 [ var_9 + 1 ].start : - return False - return True -",1,1 -222,977_Squares_of_a_Sorted_Array_2.py,"def sortedSquares( A): - pos = 0 - while pos < len(A) and A[pos] < 0: - pos += 1 - npos = pos - 1 - res = [] - while pos < len(A) and npos >= 0: - if A[npos] ** 2 < A[pos] ** 2: - res.append(A[npos] ** 2) - npos -= 1 - else: - res.append(A[pos] ** 2) - pos +=1 - while npos >= 0: - res.append(A[npos] ** 2) - npos -= 1 - while pos < len(A): - res.append(A[pos] ** 2) - pos += 1 - return res","def sample_funcname ( var_0 ) : - var_2 = 0 - while var_2 < len ( var_0 ) and var_0 [ var_2 ] < 0 : - var_2 += 1 - var_5 = var_2 - 1 - var_6 = [ ] - while var_2 < len ( var_0 ) and var_5 >= 0 : - if var_0 [ var_5 ] ** 2 < var_0 [ var_2 ] ** 2 : - var_6.append ( var_0 [ var_5 ] ** 2 ) - var_5 -= 1 - else : - var_6.append ( var_0 [ var_2 ] ** 2 ) - var_2 += 1 - while var_5 >= 0 : - var_6.append ( var_0 [ var_5 ] ** 2 ) - var_5 -= 1 - while var_2 < len ( var_0 ) : - var_6.append ( var_0 [ var_2 ] ** 2 ) - var_2 += 1 - return var_6 -",102,3 -223,144_Binary_Tree_Preorder_Traversal_1.py,"def preorderTraversal( root): - if root is None: - return [] - res = [] - stack = [root] - while len(stack) > 0: - curr = stack.pop() - res.append(curr.val) - if curr.right is not None: - stack.append(curr.right) - if curr.left is not None: - stack.append(curr.left) - return res","def sample_funcname ( var_0 ) : - if var_0 is None : - return [ ] - var_2 = [ ] - var_3 = [ var_0 ] - while len ( var_3 ) > 0 : - var_7 = var_3.pop ( ) - var_2.append ( var_7.val ) - if var_7.right is not None : - var_3.append ( var_7.right ) - if var_7.left is not None : - var_3.append ( var_7.left ) - return var_2 -",0None,2 -224,087_Scramble_String_1.py,"def isScramble( s1, s2): - if s1 == s2: - return True - if len(s1) != len(s2): - return False - ls = len(s1) - letters = [0] * 26 - for i in range(ls): - letters[ord(s1[i]) - ord('a')] += 1 - letters[ord(s2[i]) - ord('a')] -= 1 - for i in range(26): - if letters[i] != 0: - return False - dp = [[[False] * ls for i in range(ls)] for i in range(ls + 1)] - for i in range(ls): - for j in range(ls): - dp[1][i][j] = (s1[i] == s2[j]) - - for cur_len in range(2, ls + 1): - for i in range(ls - cur_len + 1): - for j in range(ls - cur_len + 1): - dp[cur_len][i][j] = False - for k in range(1, cur_len): - if dp[cur_len][i][j]: - break - dp[cur_len][i][j] = dp[cur_len][i][j] or (dp[k][i][j] and dp[cur_len - k][i + k][j + k]) - dp[cur_len][i][j] = dp[cur_len][i][j] or (dp[k][i + cur_len - k][j] and dp[cur_len - k][i][j + k]) - return dp[ls][0][0]","def sample_funcname ( var_0 , var_1 ) : - if var_0 == var_1 : - return True - if len ( var_0 ) != len ( var_1 ) : - return False - var_5 = len ( var_0 ) - var_8 = [ 0 ] * 26 - for var_10 in range ( var_5 ) : - var_8 [ ord ( var_0 [ var_10 ] ) - ord ( 'a' ) ] += 1 - var_8 [ ord ( var_1 [ var_10 ] ) - ord ( 'a' ) ] -= 1 - for var_10 in range ( 26 ) : - if var_8 [ var_10 ] != 0 : - return False - var_14 = [ [ [ False ] * var_5 for var_10 in range ( var_5 ) ] for var_10 in range ( var_5 + 1 ) ] - for var_10 in range ( var_5 ) : - for var_15 in range ( var_5 ) : - var_14 [ 1 ] [ var_10 ] [ var_15 ] = ( var_0 [ var_10 ] == var_1 [ var_15 ] ) - for var_17 in range ( 2 , var_5 + 1 ) : - for var_10 in range ( var_5 - var_17 + 1 ) : - for var_15 in range ( var_5 - var_17 + 1 ) : - var_14 [ var_17 ] [ var_10 ] [ var_15 ] = False - for var_18 in range ( 1 , var_17 ) : - if var_14 [ var_17 ] [ var_10 ] [ var_15 ] : - break - var_14 [ var_17 ] [ var_10 ] [ var_15 ] = var_14 [ var_17 ] [ var_10 ] [ var_15 ] or ( var_14 [ var_18 ] [ var_10 ] [ var_15 ] and var_14 [ var_17 - var_18 ] [ var_10 + var_18 ] [ var_15 + var_18 ] ) - var_14 [ var_17 ] [ var_10 ] [ var_15 ] = var_14 [ var_17 ] [ var_10 ] [ var_15 ] or ( var_14 [ var_18 ] [ var_10 + var_17 - var_18 ] [ var_15 ] and var_14 [ var_17 - var_18 ] [ var_10 ] [ var_15 + var_18 ] ) - return var_14 [ var_5 ] [ 0 ] [ 0 ] -",0a2126,5 -225,268_Missing_Number_2.py,"def missingNumber( nums): - res = len(nums) - for i, v in enumerate(nums): - res ^= i - res ^= v - return res","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - for var_4 , var_5 in enumerate ( var_0 ) : - var_2 ^= var_4 - var_2 ^= var_5 - return var_2 -",,0 -226,009_Palindrome_Number_1.py,"def isPalindrome( x: int) -> bool: - x = str(x) - if (x == x[::-1]): - return True - return False","def sample_funcname ( var_0 : int ) -> bool : - var_0 = str ( var_0 ) - if ( var_0 == var_0 [ : : - 1 ] ) : - return True - return False -",1,1 -227,198_House_Robber_3.py,"def rob( nums): - prevMax = currMax = 0 - for num in nums: - temp = currMax - currMax = max(prevMax + num, currMax) - prevMax = temp - return currMax","def sample_funcname ( var_0 ) : - var_3 = var_1 = 0 - for var_4 in var_0 : - var_5 = var_1 - var_1 = max ( var_3 + var_4 , var_1 ) - var_3 = var_5 - return var_1 -",0,1 -228,179_Largest_Number_1.py,"def __lt__(x, y): - return x + y > y + x","def sample_funcname ( var_0 , var_1 ) : - return var_0 + var_1 > var_1 + var_0 -",,0 -229,367_Valid_Perfect_Square_3.py,"def isPerfectSquare( num): - x = num - while x * x > num: - x = (x + num / x) / 2 - return x * x == num","def sample_funcname ( var_0 ) : - var_1 = var_0 - while var_1 * var_1 > var_0 : - var_1 = ( var_1 + var_0 / var_1 ) / 2 - return var_1 * var_1 == var_0 -",2,1 -230,876_Middle_of_the_Linked_List_1.py,"def middleNode( head): - res = [] - while head: - res.append(head) - head = head.next - return res[len(res) / 2]","def sample_funcname ( var_0 ) : - var_1 = [ ] - while var_0 : - var_1.append ( var_0 ) - var_0 = var_0.next - return var_1 [ len ( var_1 ) / 2 ] -",2,1 -231,078_Subsets_2.py,"def subsets( nums): - nums.sort() - res = [[]] - for index in range(len(nums)): - size = len(res) - for j in range(size): - curr = list(res[j]) - curr.append(nums[index]) - res.append(curr) - return res","def sample_funcname ( var_0 ) : - var_0.sort ( ) - var_2 = [ [ ] ] - for var_5 in range ( len ( var_0 ) ) : - var_6 = len ( var_2 ) - for var_7 in range ( var_6 ) : - var_9 = list ( var_2 [ var_7 ] ) - var_9.append ( var_0 [ var_5 ] ) - var_2.append ( var_9 ) - return var_2 -",,0 -232,048_Rotate_Image_1.py,"def rotate( matrix): - if matrix is None or len(matrix) == 1: - return - ls = len(matrix) - for i in range(ls / 2): - begin, end = i, ls - 1 - i - for k in range(ls - 2 * i - 1): - temp = matrix[end - k][begin] - matrix[end - k][begin] = matrix[end][end - k] - matrix[end][end - k] = matrix[begin + k][end] - matrix[begin + k][end] = matrix[begin][begin + k] - matrix[begin][begin + k] = temp - return","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 1 : - return - var_4 = len ( var_0 ) - for var_7 in range ( var_4 / 2 ) : - var_8 , var_9 = var_7 , var_4 - 1 - var_7 - for var_10 in range ( var_4 - 2 * var_7 - 1 ) : - var_11 = var_0 [ var_9 - var_10 ] [ var_8 ] - var_0 [ var_9 - var_10 ] [ var_8 ] = var_0 [ var_9 ] [ var_9 - var_10 ] - var_0 [ var_9 ] [ var_9 - var_10 ] = var_0 [ var_8 + var_10 ] [ var_9 ] - var_0 [ var_8 + var_10 ] [ var_9 ] = var_0 [ var_8 ] [ var_8 + var_10 ] - var_0 [ var_8 ] [ var_8 + var_10 ] = var_11 - return -",1None2,3 -233,037_Sudoku_Solver_1.py,"def is_safe( board, row, col, ch): - for k in range(9): - if board[k][col] == ch: - return False - if board[row][k] == ch: - return False - start_row, start_col = 3 * (row / 3), 3 * (col / 3) - for i in range(start_row, start_row + 3): - for j in range(start_col, start_col + 3): - if board[i][j] == ch: - return False - return True","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - for var_6 in range ( 9 ) : - if var_0 [ var_6 ] [ var_2 ] == var_3 : - return False - if var_0 [ var_1 ] [ var_6 ] == var_3 : - return False - var_9 , var_10 = 3 * ( var_1 / 3 ) , 3 * ( var_2 / 3 ) - for var_11 in range ( var_9 , var_9 + 3 ) : - for var_12 in range ( var_10 , var_10 + 3 ) : - if var_0 [ var_11 ] [ var_12 ] == var_3 : - return False - return True -",93,2 -234,029_Divide_Two_Integers_1.py,"def divide( dividend, divisor): - isPositive = (dividend < 0) == (divisor < 0) - dividend, divisor, result = abs(dividend), abs(divisor), 0 - while dividend >= divisor: - n, nb = 1, divisor - - while dividend >= nb: - dividend, result = dividend - nb, result + n - n, nb = n << 1, nb << 1 - if isPositive: - return min(result, 2147483647) - return max(-result, -2147483648)","def sample_funcname ( var_0 , var_1 ) : - var_3 = ( var_0 < 0 ) == ( var_1 < 0 ) - var_0 , var_1 , var_5 = abs ( var_0 ) , abs ( var_1 ) , 0 - while var_0 >= var_1 : - var_7 , var_8 = 1 , var_1 - while var_0 >= var_8 : - var_0 , var_5 = var_0 - var_8 , var_5 + var_7 - var_7 , var_8 = var_7 << 1 , var_8 << 1 - if var_3 : - return min ( var_5 , 2147483647 ) - return max ( - var_5 , - 2147483648 ) -",1021474836482147483647,4 -235,283_Move Zeroes_2.py,"def moveZeroes( nums): - ls = len(nums) - n_pos = 0 - for i in range(ls): - if nums[i] != 0: - temp = nums[n_pos] - nums[n_pos] = nums[i] - nums[i] = temp - n_pos += 1","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_4 = 0 - for var_6 in range ( var_2 ) : - if var_0 [ var_6 ] != 0 : - var_7 = var_0 [ var_4 ] - var_0 [ var_4 ] = var_0 [ var_6 ] - var_0 [ var_6 ] = var_7 - var_4 += 1 -",10,2 -236,954_Array_of_Doubled_Pairs_1.py,"def canReorderDoubled( A): - v_map = {} - A.sort(key=lambda x: abs(x)) - for n in A: - v_map[n] = v_map.get(n, 0) + 1 - for n in A: - if v_map[n] <= 0: - continue - if 2 * n in v_map and v_map[2 * n] > 0: - v_map[n] -= 1 - v_map[2 * n] -= 1 - else: - return False - return True","def sample_funcname ( var_0 ) : - var_1 = { } - var_0.sort ( var_3 = lambda var_4 : abs ( var_4 ) ) - for var_6 in var_0 : - var_1 [ var_6 ] = var_1.get ( var_6 , 0 ) + 1 - for var_6 in var_0 : - if var_1 [ var_6 ] <= 0 : - continue - if 2 * var_6 in var_1 and var_1 [ 2 * var_6 ] > 0 : - var_1 [ var_6 ] -= 1 - var_1 [ 2 * var_6 ] -= 1 - else : - return False - return True -",102,3 -237,038_Count_and_Say_1.py,"def count( x): - m = list(x) - res = [] - m.append(None) - i , j = 0 , 0 - while i < len(m) - 1: - j += 1 - if m[j] != m[i]: - res += [j - i, m[i]] - i = j - return ''.join(str(s) for s in res)","def sample_funcname ( var_0 ) : - var_2 = list ( var_0 ) - var_3 = [ ] - var_2.append ( None ) - var_7 , var_8 = 0 , 0 - while var_7 < len ( var_2 ) - 1 : - var_8 += 1 - if var_2 [ var_8 ] != var_2 [ var_7 ] : - var_3 += [ var_8 - var_7 , var_2 [ var_7 ] ] - var_7 = var_8 - return ''.join ( str ( var_14 ) for var_14 in var_3 ) -",10None,4 -238,001_Two_Sum_2.py,"def twoSum( nums, target): - hash_nums = {} - for index, num in enumerate(nums): - try: - hash_nums[num].append(index) - except KeyError: - hash_nums[num] = [index] - for index, num in enumerate(nums): - another = target - num - try: - candicate = hash_nums[another] - if another == num: - if len(candicate) > 1: - return candicate - else: - continue - else: - return [index, candicate[0]] - except KeyError: - pass","def sample_funcname ( var_0 , var_1 ) : - var_2 = { } - for var_4 , var_5 in enumerate ( var_0 ) : - try : - var_2 [ var_5 ].append ( var_4 ) - except KeyError : - var_2 [ var_5 ] = [ var_4 ] - for var_4 , var_5 in enumerate ( var_0 ) : - var_8 = var_1 - var_5 - try : - var_9 = var_2 [ var_8 ] - if var_8 == var_5 : - if len ( var_9 ) > 1 : - return var_9 - else : - continue - else : - return [ var_4 , var_9 [ 0 ] ] - except KeyError : - pass -",10,2 -239,114_Flatten_Binary_Tree_to_Linked_List_1.py,"def appendNode( stack, node): - if node: - stack.append(node)","def sample_funcname ( var_0 , var_1 ) : - if var_1 : - var_0.append ( var_1 ) -",,0 -240,059_Spiral_Matrix_II_1.py,"def generateMatrix( n): - res = [[0] * n for _ in range(n)] - pos = [0, 0] - move = (0, 1) - for index in range(1, n * n + 1): - res[pos[0]][pos[1]] = index - if res[(pos[0] + move[0]) % n][(pos[1] + move[1]) % n] > 0: - move = (move[1], -1 * move[0]) - pos[0] = pos[0] + move[0] - pos[1] = pos[1] + move[1] - return res","def sample_funcname ( var_0 ) : - var_4 = [ [ 0 ] * var_0 for var_2 in range ( var_0 ) ] - var_5 = [ 0 , 0 ] - var_7 = ( 0 , 1 ) - for var_8 in range ( 1 , var_0 * var_0 + 1 ) : - var_4 [ var_5 [ 0 ] ] [ var_5 [ 1 ] ] = var_8 - if var_4 [ ( var_5 [ 0 ] + var_7 [ 0 ] ) % var_0 ] [ ( var_5 [ 1 ] + var_7 [ 1 ] ) % var_0 ] > 0 : - var_7 = ( var_7 [ 1 ] , - 1 * var_7 [ 0 ] ) - var_5 [ 0 ] = var_5 [ 0 ] + var_7 [ 0 ] - var_5 [ 1 ] = var_5 [ 1 ] + var_7 [ 1 ] - return var_4 -",10,2 -241,700_Search_in_a_Binary_Search_Tree_1.py,"def searchBST( root, val): - while root: - if root.val == val: - return root - elif root.val > val: - root = root.left - else: - root = root.right - return root","def sample_funcname ( var_0 , val ) : - while var_0 : - if var_0.val == val : - return var_0 - elif var_0.val > val : - var_0 = var_0.left - else : - var_0 = var_0.right - return var_0 -",,0 -242,053_Maximum_Subarray_1.py,"def maxSubArray( nums): - ls = len(nums) - start = [0] * ls - all = [0] * ls - start[-1], all[-1] = nums[-1], nums[-1] - for i in reversed(range(ls - 1)): - start[i] = max(nums[i], nums[i] + start[i + 1]) - all[i] = max(start[i], all[i + 1]) - return all[0]","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_4 = [ 0 ] * var_2 - var_5 = [ 0 ] * var_2 - var_4 [ - 1 ] , var_5 [ - 1 ] = var_0 [ - 1 ] , var_0 [ - 1 ] - for var_9 in reversed ( range ( var_2 - 1 ) ) : - var_4 [ var_9 ] = max ( var_0 [ var_9 ] , var_0 [ var_9 ] + var_4 [ var_9 + 1 ] ) - var_5 [ var_9 ] = max ( var_4 [ var_9 ] , var_5 [ var_9 + 1 ] ) - return var_5 [ 0 ] -",10,2 -243,231_Power_of_Two_1.py,"def isPowerOfTwo( n): - if n < 0: - return False - bin_str = bin(n) - return sum(map(lambda x: int(x), list(bin_str[2:]))) == 1","def sample_funcname ( var_0 ) : - if var_0 < 0 : - return False - var_4 = bin ( var_0 ) - return sum ( map ( lambda var_7 : int ( var_7 ) , list ( var_4 [ 2 : ] ) ) ) == 1 -",102,3 -244,064_Minimum_Path_Sum_1.py,"def minPathSum( grid): - height = len(grid) - if height == 0: - return 0 - width = len(grid[0]) - pathmap = [] - for i in range(height): - pathmap.append([100000000000] * width) - pathmap[0][0] = grid[0][0] - for i in range(height): - for j in range(width): - compare = [pathmap[i][j]] - if i - 1 >= 0: - compare.append(pathmap[i - 1][j] + grid[i][j]) - if j - 1 >= 0: - compare.append(pathmap[i][j - 1] + grid[i][j]) - pathmap[i][j] = min(compare) - return pathmap[-1][-1]","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - if var_2 == 0 : - return 0 - var_4 = len ( var_0 [ 0 ] ) - var_5 = [ ] - for var_7 in range ( var_2 ) : - var_5.append ( [ 100000000000 ] * var_4 ) - var_5 [ 0 ] [ 0 ] = var_0 [ 0 ] [ 0 ] - for var_7 in range ( var_2 ) : - for var_10 in range ( var_4 ) : - var_11 = [ var_5 [ var_7 ] [ var_10 ] ] - if var_7 - 1 >= 0 : - var_11.append ( var_5 [ var_7 - 1 ] [ var_10 ] + var_0 [ var_7 ] [ var_10 ] ) - if var_10 - 1 >= 0 : - var_11.append ( var_5 [ var_7 ] [ var_10 - 1 ] + var_0 [ var_7 ] [ var_10 ] ) - var_5 [ var_7 ] [ var_10 ] = min ( var_11 ) - return var_5 [ - 1 ] [ - 1 ] -",10100000000000,3 -245,096_Unique_Binary_Search_Trees_1.py,"def numTrees( n): - dp = [0] * (n + 1) - dp[0] = 1 - dp[1] = 1 - for level in range(2, n + 1): - for root in range(1, level + 1): - dp[level] += dp[level - root] * dp[root - 1] - return dp[n]","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * ( var_0 + 1 ) - var_3 [ 0 ] = 1 - var_3 [ 1 ] = 1 - for var_6 in range ( 2 , var_0 + 1 ) : - for var_7 in range ( 1 , var_6 + 1 ) : - var_3 [ var_6 ] += var_3 [ var_6 - var_7 ] * var_3 [ var_7 - 1 ] - return var_3 [ var_0 ] -",102,3 -247,116_Populating_Next_Right_Pointers_in_Each_Node_1.py,"def connect( root): - if root is None: - return - nodes = [root] - while len(nodes) != 0: - next_step = [] - last = None - for node in nodes: - if last is not None: - last.next = node - if node.left is not None: - next_step.append(node.left) - if node.right is not None: - next_step.append(node.right) - last = node - nodes = next_step","def sample_funcname ( var_0 ) : - if var_0 is None : - return - var_2 = [ var_0 ] - while len ( var_2 ) != 0 : - var_5 = [ ] - var_6 = None - for var_7 in var_2 : - if var_6 is not None : - var_6.next = var_7 - if var_7.left is not None : - var_5.append ( var_7.left ) - if var_7.right is not None : - var_5.append ( var_7.right ) - var_6 = var_7 - var_2 = var_5 -",0None,2 -248,728_Self_Dividing_Numbers_2.py,"def selfDividingNumbers( left: int, right: int) -> List[int]: - return [x for x in range(left, right+1) if all((i and (x % i==0) for i in map(int, str(x))))]","def sample_funcname ( var_0 : int , var_2 : int ) -> List [ int ] : - return [ var_4 for var_4 in range ( var_0 , var_2 + 1 ) if all ( ( var_8 and ( var_4 % var_8 == 0 ) for var_8 in map ( int , str ( var_4 ) ) ) ) ] -",10,2 -249,057_Insert_Interval_1.py,"def check_overlap( curr_int, new_int): - if curr_int.start <= new_int.start: - if curr_int.end > new_int.start: - return True - else: - if curr_int.start <= new_int.end: - return True - return False","def sample_funcname ( var_0 , var_1 ) : - if var_0.start <= var_1.start : - if var_0.end > var_1.start : - return True - else : - if var_0.start <= var_1.end : - return True - return False -",,0 -250,1108_Defanging_an_IP_Address_2.py,"def defangIPaddr( address: str) -> str: - return '[.]'.join(address.split('.'))","def sample_funcname ( var_0 : str ) -> str : - return '[.]'.join ( var_0.split ( '.' ) ) -",[.].,2 -251,041_First_Missing_Positive_1.py,"def firstMissingPositive( nums): - ls = len(nums) - index = 0 - while index < ls: - if nums[index] <= 0 or nums[index] > ls or nums[nums[index] - 1] == nums[index]: - index += 1 - else: - pos = nums[index] - 1 - nums[index], nums[pos] = nums[pos], nums[index] - res = 0 - while res < ls and nums[res] == res + 1: - res += 1 - return res + 1","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_4 = 0 - while var_4 < var_2 : - if var_0 [ var_4 ] <= 0 or var_0 [ var_4 ] > var_2 or var_0 [ var_0 [ var_4 ] - 1 ] == var_0 [ var_4 ] : - var_4 += 1 - else : - var_6 = var_0 [ var_4 ] - 1 - var_0 [ var_4 ] , var_0 [ var_6 ] = var_0 [ var_6 ] , var_0 [ var_4 ] - var_7 = 0 - while var_7 < var_2 and var_0 [ var_7 ] == var_7 + 1 : - var_7 += 1 - return var_7 + 1 -",10,2 -252,042_Trapping_Rain_Water_1.py,"def rain_water( height, start, end): - if end - start <= 1: - return 0 - min_m = min(height[start], height[end]) - res = min_m * (end - start - 1) - step = 0 - for index in range(start + 1, end): - if height[index] > 0: - step += height[index] - return res - step","def sample_funcname ( var_0 , var_1 , var_2 ) : - if var_2 - var_1 <= 1 : - return 0 - var_6 = min ( var_0 [ var_1 ] , var_0 [ var_2 ] ) - var_7 = var_6 * ( var_2 - var_1 - 1 ) - var_8 = 0 - for var_10 in range ( var_1 + 1 , var_2 ) : - if var_0 [ var_10 ] > 0 : - var_8 += var_0 [ var_10 ] - return var_7 - var_8 -",10,2 -253,1337_The_K_Weakest_Rows_in_a_Matrix_1.py,"def kWeakestRows( mat, k): - res = [] - num_row = len(mat) - num_col = len(mat[0]) - col = 0 - flag = 1 - while col < num_col and flag: - for i in range(num_row): - if i in res: - continue - if mat[i][col] == 0: - res.append(i) - if len(res) == k: - flag = 0 - break - col += 1 - if len(res) == k: - return res - for i in range(num_row): - if i in res: - continue - res.append(i) - if len(res) == k: - break - return res","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - var_4 = len ( var_0 ) - var_6 = len ( var_0 [ 0 ] ) - var_7 = 0 - var_9 = 1 - while var_7 < var_6 and var_9 : - for var_11 in range ( var_4 ) : - if var_11 in var_2 : - continue - if var_0 [ var_11 ] [ var_7 ] == 0 : - var_2.append ( var_11 ) - if len ( var_2 ) == var_1 : - var_9 = 0 - break - var_7 += 1 - if len ( var_2 ) == var_1 : - return var_2 - for var_11 in range ( var_4 ) : - if var_11 in var_2 : - continue - var_2.append ( var_11 ) - if len ( var_2 ) == var_1 : - break - return var_2 -",10,2 -254,135_Candy_1.py,"def candy( ratings): - if ratings is None or len(ratings) == 0: - return 0 - ls = len(ratings) - num = [1] * ls - for i in range(1, ls): - if ratings[i] > ratings[i - 1]: - num[i] = num[i - 1] + 1 - for i in range(ls - 1, 0, -1): - if ratings[i - 1] > ratings[i]: - num[i - 1] = max(num[i] + 1, num[i - 1]) - return sum(num)","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return 0 - var_4 = len ( var_0 ) - var_6 = [ 1 ] * var_4 - for var_8 in range ( 1 , var_4 ) : - if var_0 [ var_8 ] > var_0 [ var_8 - 1 ] : - var_6 [ var_8 ] = var_6 [ var_8 - 1 ] + 1 - for var_8 in range ( var_4 - 1 , 0 , - 1 ) : - if var_0 [ var_8 - 1 ] > var_0 [ var_8 ] : - var_6 [ var_8 - 1 ] = max ( var_6 [ var_8 ] + 1 , var_6 [ var_8 - 1 ] ) - return sum ( var_6 ) -",10None,3 -255,371_Sum_of_Two_Integers_1.py,"def getSum( a, b): - import ctypes - sum = 0 - carry = ctypes.c_int32(b) - while carry.value != 0: - sum = a ^ carry.value - carry = ctypes.c_int32(a & carry.value) - carry.value <<= 1 - a = sum - return sum","def sample_funcname ( var_0 , var_1 ) : - import var_2 - var_4 = 0 - var_6 = var_2.c_int32 ( var_1 ) - while var_6.value != 0 : - var_4 = var_0 ^ var_6.value - var_6 = var_2.c_int32 ( var_0 & var_6.value ) - var_6.value <<= 1 - var_0 = var_4 - return var_4 -",10,2 -256,268_Missing_Number_3.py,"def missingNumber( nums): - nums.sort() - left, right = 0, len(nums) - 1 - while left <= right: - mid = (left + right) / 2 - if nums[mid] <= mid: - left = mid + 1 - else: - right = mid - 1 - return left","def sample_funcname ( var_0 ) : - var_0.sort ( ) - var_3 , var_6 = 0 , len ( var_0 ) - 1 - while var_3 <= var_6 : - var_8 = ( var_3 + var_6 ) / 2 - if var_0 [ var_8 ] <= var_8 : - var_3 = var_8 + 1 - else : - var_6 = var_8 - 1 - return var_3 -",102,3 -257,091_Decode_Ways_1.py,"def numDecodings( s): - ls = len(s) - if ls == 0: - return 0 - dp = [0] * ls - for index in range(ls): - if index >= 1 and int(s[index - 1:index + 1]) < 27 and int(s[index - 1:index + 1]) >= 10: - if index == 1: - dp[index] = 1 - else: - dp[index] += dp[index - 2] - if int(s[index]) != 0: - if index == 0: - dp[index] = 1 - else: - dp[index] += dp[index - 1] - return dp[ls - 1]","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - if var_2 == 0 : - return 0 - var_4 = [ 0 ] * var_2 - for var_6 in range ( var_2 ) : - if var_6 >= 1 and int ( var_0 [ var_6 - 1 : var_6 + 1 ] ) < 27 and int ( var_0 [ var_6 - 1 : var_6 + 1 ] ) >= 10 : - if var_6 == 1 : - var_4 [ var_6 ] = 1 - else : - var_4 [ var_6 ] += var_4 [ var_6 - 2 ] - if int ( var_0 [ var_6 ] ) != 0 : - if var_6 == 0 : - var_4 [ var_6 ] = 1 - else : - var_4 [ var_6 ] += var_4 [ var_6 - 1 ] - return var_4 [ var_2 - 1 ] -",1002721,5 -258,198_House_Robber_2.py,"def rob( nums): - if nums is None or len(nums) == 0: - return 0 - if len(nums) == 1: - return nums[0] - nums[1] = max(nums[0], nums[1]) - for i in range(2, len(nums)): - nums[i] = max(nums[i] + nums[i - 2], nums[i - 1]) - return nums[-1]","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return 0 - if len ( var_0 ) == 1 : - return var_0 [ 0 ] - var_0 [ 1 ] = max ( var_0 [ 0 ] , var_0 [ 1 ] ) - for var_8 in range ( 2 , len ( var_0 ) ) : - var_0 [ var_8 ] = max ( var_0 [ var_8 ] + var_0 [ var_8 - 2 ] , var_0 [ var_8 - 1 ] ) - return var_0 [ - 1 ] -",10None2,4 -259,367_Valid_Perfect_Square_2.py,"def isPerfectSquare( num): - low, high = 1, num - while low <= high: - mid = (low + high) / 2 - mid_square = mid * mid - if mid_square == num: - return True - elif mid_square < num: - low = mid + 1 - else: - high = mid - 1 - return False","def sample_funcname ( var_0 ) : - var_2 , var_3 = 1 , var_0 - while var_2 <= var_3 : - var_5 = ( var_2 + var_3 ) / 2 - var_6 = var_5 * var_5 - if var_6 == var_0 : - return True - elif var_6 < var_0 : - var_2 = var_5 + 1 - else : - var_3 = var_5 - 1 - return False -",12,2 -260,294_Flip_Game_II_1.py,"def canWin( s): - memo = {}","def sample_funcname ( var_0 ) : - var_1 = { } -",,0 -261,032_Longest_Valid_Parentheses_1.py,"def longestValidParentheses( s): - ls = len(s) - start = [0] * (ls + 1) - all = [0] * (ls + 1) - for i in reversed(range(ls - 1)): - if s[i] == '(': - if s[i + 1] == ')': - start[i] = 2 - if start[i + 1] + i + 1 < ls and s[start[i + 1] + i + 1] == ')': - start[i] = 2 + start[i + 1] - if start[start[i] + i] > 0: - start[i] += start[start[i] + i] - all[i] = max(start[i], all[i + 1]) - return all[0]","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_5 = [ 0 ] * ( var_2 + 1 ) - var_6 = [ 0 ] * ( var_2 + 1 ) - for var_9 in reversed ( range ( var_2 - 1 ) ) : - if var_0 [ var_9 ] == '(' : - if var_0 [ var_9 + 1 ] == ')' : - var_5 [ var_9 ] = 2 - if var_5 [ var_9 + 1 ] + var_9 + 1 < var_2 and var_0 [ var_5 [ var_9 + 1 ] + var_9 + 1 ] == ')' : - var_5 [ var_9 ] = 2 + var_5 [ var_9 + 1 ] - if var_5 [ var_5 [ var_9 ] + var_9 ] > 0 : - var_5 [ var_9 ] += var_5 [ var_5 [ var_9 ] + var_9 ] - var_6 [ var_9 ] = max ( var_5 [ var_9 ] , var_6 [ var_9 + 1 ] ) - return var_6 [ 0 ] -",021(),5 -262,751_IP_to_CIDR_2.py,"def intToIP( x): - return ""."".join(str((x >> i) % 256) - for i in (24, 16, 8, 0))","def sample_funcname ( var_0 ) : - return ""."".join ( str ( ( var_0 >> var_4 ) % 256 ) for var_4 in ( 24 , 16 , 8 , 0 ) ) -",242560816.,6 -263,001_Two_Sum_3.py,"def twoSum( nums, target): - hash_nums = {} - for index, num in enumerate(nums): - another = target - num - try: - hash_nums[another] - return [hash_nums[another], index] - except KeyError: - hash_nums[num] = index","def sample_funcname ( var_0 , var_1 ) : - var_2 = { } - for var_4 , var_5 in enumerate ( var_0 ) : - var_6 = var_1 - var_5 - try : - var_2 [ var_6 ] - return [ var_2 [ var_6 ] , var_4 ] - except KeyError : - var_2 [ var_5 ] = var_4 -",,0 -264,118_Pascal's_Triangle_1.py,"def generate( numRows): - result = [] - for i in range(numRows): - result.append([0] * (i + 1)) - for i in range(numRows): - for j in range(i + 1): - if j == 0 or j == i: - result[i][j] = 1 - else: - result[i][j] = result[i - 1][j - 1] + result[i - 1][j] - return result","def sample_funcname ( var_0 ) : - var_1 = [ ] - for var_3 in range ( var_0 ) : - var_1.append ( [ 0 ] * ( var_3 + 1 ) ) - for var_3 in range ( var_0 ) : - for var_7 in range ( var_3 + 1 ) : - if var_7 == 0 or var_7 == var_3 : - var_1 [ var_3 ] [ var_7 ] = 1 - else : - var_1 [ var_3 ] [ var_7 ] = var_1 [ var_3 - 1 ] [ var_7 - 1 ] + var_1 [ var_3 - 1 ] [ var_7 ] - return var_1 -",10,2 -265,322_Coin_Change_1.py,"def coinChange( coins, amount): - if amount == 0: - return 0 - if coins is None or len(coins) == 0: - return -1 - coins.sort() - dp = [1000000000] * (amount + 1) - for i in range(1, amount + 1): - for coin in coins: - if i == coin: - dp[i] = 1 - break - elif i > coin: - dp[i] = min(dp[i], dp[i - coin] + 1) - if dp[amount] == 1000000000: - return -1 - return dp[amount]","def sample_funcname ( var_0 , var_1 ) : - if var_1 == 0 : - return 0 - if var_0 is None or len ( var_0 ) == 0 : - return - 1 - var_0.sort ( ) - var_8 = [ 1000000000 ] * ( var_1 + 1 ) - for var_10 in range ( 1 , var_1 + 1 ) : - for var_11 in var_0 : - if var_10 == var_11 : - var_8 [ var_10 ] = 1 - break - elif var_10 > var_11 : - var_8 [ var_10 ] = min ( var_8 [ var_10 ] , var_8 [ var_10 - var_11 ] + 1 ) - if var_8 [ var_1 ] == 1000000000 : - return - 1 - return var_8 [ var_1 ] -",110000000000None,4 -266,139_Word_Break_1.py,"def wordBreak( s, wordDict): - queue = [0] - ls = len(s) - lenList = [l for l in set(map(len, wordDict))] - visited = [0 for _ in range(0, ls + 1)] - while queue: - start = queue.pop(0) - for l in lenList: - if s[start:start + l] in wordDict: - if start + l == ls: - return True - if visited[start + l] == 0: - queue.append(start + l) - visited[start + l] = 1 - return False","def sample_funcname ( var_0 , var_1 ) : - var_3 = [ 0 ] - var_5 = len ( var_0 ) - var_9 = [ var_6 for var_6 in set ( map ( len , var_1 ) ) ] - var_13 = [ 0 for var_10 in range ( 0 , var_5 + 1 ) ] - while var_3 : - var_15 = var_3.pop ( 0 ) - for var_6 in var_9 : - if var_0 [ var_15 : var_15 + var_6 ] in var_1 : - if var_15 + var_6 == var_5 : - return True - if var_13 [ var_15 + var_6 ] == 0 : - var_3.append ( var_15 + var_6 ) - var_13 [ var_15 + var_6 ] = 1 - return False -",10,2 -267,004_Median_of_Two_Sorted_Arrays_1.py,"def findMedianSortedArrays( nums1, nums2): - p1 = p2 = 0 - ls1 = len(nums1) - ls2 = len(nums2) - all_nums = [] - median = 0.0 - while p1 < ls1 and p2 < ls2: - if nums1[p1] < nums2[p2]: - all_nums.append(nums1[p1]) - p1 += 1 - else: - all_nums.append(nums2[p2]) - p2 += 1 - if p1 < ls1: - while p1 < ls1: - all_nums.append(nums1[p1]) - p1 += 1 - if p2 < ls2: - while p2 < ls2: - all_nums.append(nums2[p2]) - p2 += 1 - - if (ls1 + ls2) % 2 == 1: - median = all_nums[(ls1 + ls2) / 2] - else: - median = 1.0 * (all_nums[(ls1 + ls2) / 2] + all_nums[(ls1 + ls2) / 2 - 1]) / 2 - return median","def sample_funcname ( var_0 , var_1 ) : - var_4 = var_2 = 0 - var_6 = len ( var_0 ) - var_7 = len ( var_1 ) - var_8 = [ ] - var_10 = 0.0 - while var_4 < var_6 and var_2 < var_7 : - if var_0 [ var_4 ] < var_1 [ var_2 ] : - var_8.append ( var_0 [ var_4 ] ) - var_4 += 1 - else : - var_8.append ( var_1 [ var_2 ] ) - var_2 += 1 - if var_4 < var_6 : - while var_4 < var_6 : - var_8.append ( var_0 [ var_4 ] ) - var_4 += 1 - if var_2 < var_7 : - while var_2 < var_7 : - var_8.append ( var_1 [ var_2 ] ) - var_2 += 1 - if ( var_6 + var_7 ) % 2 == 1 : - var_10 = var_8 [ ( var_6 + var_7 ) / 2 ] - else : - var_10 = 1.0 * ( var_8 [ ( var_6 + var_7 ) / 2 ] + var_8 [ ( var_6 + var_7 ) / 2 - 1 ] ) / 2 - return var_10 -",020.011.0,5 -268,695_Max_Area_of_Island_2.py,"def bfs( grid, x, y): - queue = [(x, y)] - area = 0 - - while queue: - i, j = queue.pop(0) - area += 1 - if i - 1 >= 0 and grid[i - 1][j] == 1: - grid[i - 1][j] = 0 - queue.append((i - 1, j)) - if i + 1 < len(grid) and grid[i + 1][j] == 1: - grid[i + 1][j] = 0 - queue.append((i + 1, j)) - if j - 1 >= 0 and grid[i][j - 1] == 1: - grid[i][j - 1] = 0 - queue.append((i, j - 1)) - if j + 1 < len(grid[0]) and grid[i][j + 1] == 1: - grid[i][j + 1] = 0 - queue.append((i, j + 1)) - return area","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_3 = [ ( var_1 , var_2 ) ] - var_5 = 0 - while var_3 : - var_7 , var_8 = var_3.pop ( 0 ) - var_5 += 1 - if var_7 - 1 >= 0 and var_0 [ var_7 - 1 ] [ var_8 ] == 1 : - var_0 [ var_7 - 1 ] [ var_8 ] = 0 - var_3.append ( ( var_7 - 1 , var_8 ) ) - if var_7 + 1 < len ( var_0 ) and var_0 [ var_7 + 1 ] [ var_8 ] == 1 : - var_0 [ var_7 + 1 ] [ var_8 ] = 0 - var_3.append ( ( var_7 + 1 , var_8 ) ) - if var_8 - 1 >= 0 and var_0 [ var_7 ] [ var_8 - 1 ] == 1 : - var_0 [ var_7 ] [ var_8 - 1 ] = 0 - var_3.append ( ( var_7 , var_8 - 1 ) ) - if var_8 + 1 < len ( var_0 [ 0 ] ) and var_0 [ var_7 ] [ var_8 + 1 ] == 1 : - var_0 [ var_7 ] [ var_8 + 1 ] = 0 - var_3.append ( ( var_7 , var_8 + 1 ) ) - return var_5 -",10,2 -269,1304_Find_N_Unique_Integers_Sum_up_to_Zero_1.py,"def sumZero( n: int) -> List[int]: - prefix_sum = 0 - res = [] - for i in range(1, n): - res.append(i) - prefix_sum = prefix_sum + i - res.append(-prefix_sum) - return res","def sample_funcname ( var_0 : int ) -> List [ int ] : - var_4 = 0 - var_5 = [ ] - for var_8 in range ( 1 , var_0 ) : - var_5.append ( var_8 ) - var_4 = var_4 + var_8 - var_5.append ( - var_4 ) - return var_5 -",10,2 -270,162_Find_Peak_Element_1.py,"def findPeakElement( nums): - start, end = 0, len(nums) - 1 - while start < end: - mid = (start + end) / 2 - if nums[mid] < nums[mid+1]: - start= mid + 1 - else: - end = mid - return start","def sample_funcname ( var_0 ) : - var_2 , var_5 = 0 , len ( var_0 ) - 1 - while var_2 < var_5 : - var_7 = ( var_2 + var_5 ) / 2 - if var_0 [ var_7 ] < var_0 [ var_7 + 1 ] : - var_2 = var_7 + 1 - else : - var_5 = var_7 - return var_2 -",102,3 -271,458_Poor_Pigs_1.py,"def poorPigs( buckets, minutesToDie, minutesToTest): - pigs = 0 - while (minutesToTest / minutesToDie + 1) ** pigs < buckets: - pigs += 1 - return pigs","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_4 = 0 - while ( var_2 / var_1 + 1 ) ** var_4 < var_0 : - var_4 += 1 - return var_4 -",10,2 -272,125_Valid_Palindrome_1.py,"def isPalindrome( s): - alnum_s = [t.lower() for t in s if t.isalnum()] - ls = len(alnum_s) - if ls <= 1: - return True - mid = ls / 2 - for i in range(mid): - if alnum_s[i] != alnum_s[ls - 1 - i]: - return False - return True","def sample_funcname ( var_0 ) : - var_4 = [ var_1.lower ( ) for var_1 in var_0 if var_1.isalnum ( ) ] - var_6 = len ( var_4 ) - if var_6 <= 1 : - return True - var_10 = var_6 / 2 - for var_12 in range ( var_10 ) : - if var_4 [ var_12 ] != var_4 [ var_6 - 1 - var_12 ] : - return False - return True -",12,2 -273,945_Minimum_Increment_to_Make_Array_Unique_1.py,"def minIncrementForUnique( A): - if A is None or len(A) == 0: - return 0 - res = 0 - num_set = set() - duplicate = [] - A.sort() - left, right = A[0], A[-1] - holes = right - left + 1 - for v in A: - if v in num_set: - duplicate.append(v) - else: - num_set.add(v) - holes = holes - len(num_set) - for hole in range(left + 1, right): - if holes == 0 or len(duplicate) == 0: - break - if hole not in num_set and hole > duplicate[0]: - res += hole - duplicate.pop(0) - holes -= 1 - while len(duplicate) != 0: - right += 1 - res += right - duplicate.pop(0) - return res","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return 0 - var_4 = 0 - var_6 = set ( ) - var_7 = [ ] - var_0.sort ( ) - var_9 , var_11 = var_0 [ 0 ] , var_0 [ - 1 ] - var_12 = var_11 - var_9 + 1 - for var_13 in var_0 : - if var_13 in var_6 : - var_7.append ( var_13 ) - else : - var_6.add ( var_13 ) - var_12 = var_12 - len ( var_6 ) - for var_17 in range ( var_9 + 1 , var_11 ) : - if var_12 == 0 or len ( var_7 ) == 0 : - break - if var_17 not in var_6 and var_17 > var_7 [ 0 ] : - var_4 += var_17 - var_7.pop ( 0 ) - var_12 -= 1 - while len ( var_7 ) != 0 : - var_11 += 1 - var_4 += var_11 - var_7.pop ( 0 ) - return var_4 -",10None,3 -274,760_Find_Anagram_Mappings_1.py,"def anagramMappings( A, B): - val_index = {} - ans = [] - for i, n in enumerate(B): - val_index[n] = i - for n in A: - ans.append(val_index[n]) - return ans","def sample_funcname ( var_0 , var_1 ) : - var_2 = { } - var_3 = [ ] - for var_5 , var_6 in enumerate ( var_1 ) : - var_2 [ var_6 ] = var_5 - for var_6 in var_0 : - var_3.append ( var_2 [ var_6 ] ) - return var_3 -",,0 -275,097_Interleaving_String_1.py,"def isInterleave( s1, s2, s3): - if len(s1) + len(s2) != len(s3): - return False - queue = [(0, 0), (-1, -1)] - visited = set() - isSuccess = False - index = 0 - while len(queue) != 1 or queue[0][0] != -1: - p = queue.pop(0) - if p[0] == len(s1) and p[1] == len(s2): - return True - if p[0] == -1: - queue.append(p) - index += 1 - continue - if p in visited: - continue - visited.add(p) - if p[0] < len(s1): - if s1[p[0]] == s3[index]: - queue.append((p[0] + 1, p[1])) - if p[1] < len(s2): - if s2[p[1]] == s3[index]: - queue.append((p[0], p[1] + 1)) - return False","def sample_funcname ( var_0 , var_1 , var_2 ) : - if len ( var_0 ) + len ( var_1 ) != len ( var_2 ) : - return False - var_7 = [ ( 0 , 0 ) , ( - 1 , - 1 ) ] - var_9 = set ( ) - var_10 = False - var_11 = 0 - while len ( var_7 ) != 1 or var_7 [ 0 ] [ 0 ] != - 1 : - var_13 = var_7.pop ( 0 ) - if var_13 [ 0 ] == len ( var_0 ) and var_13 [ 1 ] == len ( var_1 ) : - return True - if var_13 [ 0 ] == - 1 : - var_7.append ( var_13 ) - var_11 += 1 - continue - if var_13 in var_9 : - continue - var_9.add ( var_13 ) - if var_13 [ 0 ] < len ( var_0 ) : - if var_0 [ var_13 [ 0 ] ] == var_2 [ var_11 ] : - var_7.append ( ( var_13 [ 0 ] + 1 , var_13 [ 1 ] ) ) - if var_13 [ 1 ] < len ( var_1 ) : - if var_1 [ var_13 [ 1 ] ] == var_2 [ var_11 ] : - var_7.append ( ( var_13 [ 0 ] , var_13 [ 1 ] + 1 ) ) - return False -",10,2 -276,143_Reorder_List_2.py,"def reorderList( head): - if head is None or head.next is None: - return - p1, p2 = head, head.next - while p2 and p2.next: - p1 = p1.next - p2 = p2.next.next - head2 = p1.next - p1.next = None - p2 = head2.next - head2.next = None - while p2: - temp = p2.next - p2.next = head2 - head2 = p2 - p2 = temp - p1, p2 = head, head2 - while p1: - temp = p1.next - p1.next = p2 - p1 = p1.next - p2 = temp","def sample_funcname ( var_0 ) : - if var_0 is None or var_0.next is None : - return - var_3 , var_4 = var_0 , var_0.next - while var_4 and var_4.next : - var_3 = var_3.next - var_4 = var_4.next.next - var_5 = var_3.next - var_3.next = None - var_4 = var_5.next - var_5.next = None - while var_4 : - var_6 = var_4.next - var_4.next = var_5 - var_5 = var_4 - var_4 = var_6 - var_3 , var_4 = var_0 , var_5 - while var_3 : - var_6 = var_3.next - var_3.next = var_4 - var_3 = var_3.next - var_4 = var_6 -",None,1 -277,1108_Defanging_an_IP_Address_3.py,"def defangIPaddr( address: str) -> str: - return ''.join('[.]' if c == '.' else c for c in address)","def sample_funcname ( var_0 : str ) -> str : - return ''.join ( '[.]' if var_5 == '.' else var_5 for var_5 in var_0 ) -",[.].,3 -278,011_Container_With_Most_Water_1.py,"def maxArea( height: List[int]) -> int: - left, right = 0, len(height) - 1 - result = 0 - while left < right: - result = max(min(height[left], height[right]) * (right - left), result) - if height[left] > height[right]: - right -= 1 - else: - left += 1 - return result","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_7 = 0 , len ( var_0 ) - 1 - var_8 = 0 - while var_4 < var_7 : - var_8 = max ( min ( var_0 [ var_4 ] , var_0 [ var_7 ] ) * ( var_7 - var_4 ) , var_8 ) - if var_0 [ var_4 ] > var_0 [ var_7 ] : - var_7 -= 1 - else : - var_4 += 1 - return var_8 -",10,2 -280,039_Combination_Sum_1.py,"def combinationSum( candidates, target): - candidates.sort() - dp = [[] for _ in range(target + 1)] - dp[0].append([]) - for i in range(1, target + 1): - for j in range(len(candidates)): - if candidates[j] > i: - break - for k in range(len(dp[i - candidates[j]])): - temp = dp[i - candidates[j]][k][:] - if len(temp) > 0 and temp[-1] > candidates[j]: - continue - temp.append(candidates[j]) - dp[i].append(temp) - return dp[target]","def sample_funcname ( var_0 , var_1 ) : - var_0.sort ( ) - var_6 = [ [ ] for var_3 in range ( var_1 + 1 ) ] - var_6 [ 0 ].append ( [ ] ) - for var_9 in range ( 1 , var_1 + 1 ) : - for var_11 in range ( len ( var_0 ) ) : - if var_0 [ var_11 ] > var_9 : - break - for var_12 in range ( len ( var_6 [ var_9 - var_0 [ var_11 ] ] ) ) : - var_13 = var_6 [ var_9 - var_0 [ var_11 ] ] [ var_12 ] [ : ] - if len ( var_13 ) > 0 and var_13 [ - 1 ] > var_0 [ var_11 ] : - continue - var_13.append ( var_0 [ var_11 ] ) - var_6 [ var_9 ].append ( var_13 ) - return var_6 [ var_1 ] -",10,2 -281,962_Maximum_Width_Ramp_2.py,"def maxWidthRamp( A): - ans = 0 - m = float('inf') - for i in sorted(range(len(A)), key=A.__getitem__): - ans = max(ans, i - m) - m = min(m, i) - return ans","def sample_funcname ( var_0 ) : - var_2 = 0 - var_5 = float ( 'inf' ) - for var_11 in sorted ( range ( len ( var_0 ) ) , var_9 = var_0.__getitem__ ) : - var_2 = max ( var_2 , var_11 - var_5 ) - var_5 = min ( var_5 , var_11 ) - return var_2 -",0inf,2 -282,063_Unique_Paths_II_1.py,"def uniquePathsWithObstacles( obstacleGrid): - m, n = len(obstacleGrid), len(obstacleGrid[0]) - dmap = [[0] * n for _ in range(m)] - for i in range(m): - if obstacleGrid[i][0] != 1: - dmap[i][0] = 1 - else: - break - for j in range(n): - if obstacleGrid[0][j] != 1: - dmap[0][j] = 1 - else: - break - for i in range(1, m): - for j in range(1, n): - if obstacleGrid[i][j] == 1: - continue - l = u = 0 - if i - 1 >= 0: - u = dmap[i - 1][j] - if j - 1 >= 0: - l = dmap[i][j - 1] - dmap[i][j] = l + u - return dmap[m - 1][n - 1]","def sample_funcname ( var_0 ) : - var_2 , var_4 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_7 = [ [ 0 ] * var_4 for var_5 in range ( var_2 ) ] - for var_8 in range ( var_2 ) : - if var_0 [ var_8 ] [ 0 ] != 1 : - var_7 [ var_8 ] [ 0 ] = 1 - else : - break - for var_10 in range ( var_4 ) : - if var_0 [ 0 ] [ var_10 ] != 1 : - var_7 [ 0 ] [ var_10 ] = 1 - else : - break - for var_8 in range ( 1 , var_2 ) : - for var_10 in range ( 1 , var_4 ) : - if var_0 [ var_8 ] [ var_10 ] == 1 : - continue - var_12 = var_11 = 0 - if var_8 - 1 >= 0 : - var_11 = var_7 [ var_8 - 1 ] [ var_10 ] - if var_10 - 1 >= 0 : - var_12 = var_7 [ var_8 ] [ var_10 - 1 ] - var_7 [ var_8 ] [ var_10 ] = var_12 + var_11 - return var_7 [ var_2 - 1 ] [ var_4 - 1 ] -",10,2 -283,009_Palindrome_Number_4.py,"def isPalindrome( x): - if x < 0: - return False - rev_x = 0 - temp = x - while temp != 0: - curr = temp % 10 - rev_x = rev_x * 10 + curr - temp = temp // 10 - if rev_x == x: - return True - else: - return False","def sample_funcname ( var_0 ) : - if var_0 < 0 : - return False - var_3 = 0 - var_4 = var_0 - while var_4 != 0 : - var_6 = var_4 % 10 - var_3 = var_3 * 10 + var_6 - var_4 = var_4 // 10 - if var_3 == var_0 : - return True - else : - return False -",100,2 -284,296_Best_Meeting_Point_2.py,"def minDistance1D( points): - distance = 0 - i, j = 0, len(points) - 1 - while i < j: - distance += points[j] - points[i] - i += 1 - j -= 1 - return distance","def sample_funcname ( var_0 ) : - var_2 = 0 - var_3 , var_6 = 0 , len ( var_0 ) - 1 - while var_3 < var_6 : - var_2 += var_0 [ var_6 ] - var_0 [ var_3 ] - var_3 += 1 - var_6 -= 1 - return var_2 -",10,2 -285,"050_Pow(x, n)_1.py","def myPow( x, n): - if n == 0: - return 1 - temp = pow(x, n / 2) - if n % 2 == 0: - return temp * temp - else: - return temp * temp * x","def sample_funcname ( var_0 , var_1 ) : - if var_1 == 0 : - return 1 - var_6 = pow ( var_0 , var_1 / 2 ) - if var_1 % 2 == 0 : - return var_6 * var_6 - else : - return var_6 * var_6 * var_0 -",102,3 -286,010_Regular_Expression_Matching_1.py,"def isMatch( s, p): - if s == p: - return True - m, n = len(s), len(p) - dp = [[False] * (n + 1) for _ in range(m + 1)] - dp[0][0] = True - for j in range(1, n): - if p[j] == '*' and dp[0][j - 1]: - dp[0][j + 1] = True - for i in range(m): - for j in range(n): - if p[j] == '.' or p[j] == s[i]: - dp[i + 1][j + 1] = dp[i][j] - elif p[j] == '*': - if p[j - 1] != s[i] and p[j - 1] != '.': - dp[i + 1][j + 1] = dp[i + 1][j - 1] - else: - dp[i + 1][j + 1] = dp[i + 1][j] or dp[i][j + 1] or dp[i + 1][j - 1] - return dp[m][n]","def sample_funcname ( var_0 , var_1 ) : - if var_0 == var_1 : - return True - var_4 , var_5 = len ( var_0 ) , len ( var_1 ) - var_10 = [ [ False ] * ( var_5 + 1 ) for var_8 in range ( var_4 + 1 ) ] - var_10 [ 0 ] [ 0 ] = True - for var_12 in range ( 1 , var_5 ) : - if var_1 [ var_12 ] == '*' and var_10 [ 0 ] [ var_12 - 1 ] : - var_10 [ 0 ] [ var_12 + 1 ] = True - for var_14 in range ( var_4 ) : - for var_12 in range ( var_5 ) : - if var_1 [ var_12 ] == '.' or var_1 [ var_12 ] == var_0 [ var_14 ] : - var_10 [ var_14 + 1 ] [ var_12 + 1 ] = var_10 [ var_14 ] [ var_12 ] - elif var_1 [ var_12 ] == '*' : - if var_1 [ var_12 - 1 ] != var_0 [ var_14 ] and var_1 [ var_12 - 1 ] != '.' : - var_10 [ var_14 + 1 ] [ var_12 + 1 ] = var_10 [ var_14 + 1 ] [ var_12 - 1 ] - else : - var_10 [ var_14 + 1 ] [ var_12 + 1 ] = var_10 [ var_14 + 1 ] [ var_12 ] or var_10 [ var_14 ] [ var_12 + 1 ] or var_10 [ var_14 + 1 ] [ var_12 - 1 ] - return var_10 [ var_4 ] [ var_5 ] -",10.*,4 -287,072_Edit_Distance_2.py,"def minDistance( word1, word2): - ls_1, ls_2 = len(word1), len(word2) - dp = list(range(ls_1 + 1)) - for j in range(1, ls_2 + 1): - pre = dp[0] - dp[0] = j - for i in range(1, ls_1 + 1): - temp = dp[i] - if word1[i - 1] == word2[j - 1]: - dp[i] = pre - else: - dp[i] = min(pre + 1, dp[i] + 1, dp[i - 1] + 1) - pre = temp - return dp[ls_1]","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = len ( var_0 ) , len ( var_1 ) - var_8 = list ( range ( var_3 + 1 ) ) - for var_9 in range ( 1 , var_4 + 1 ) : - var_11 = var_8 [ 0 ] - var_8 [ 0 ] = var_9 - for var_12 in range ( 1 , var_3 + 1 ) : - var_13 = var_8 [ var_12 ] - if var_0 [ var_12 - 1 ] == var_1 [ var_9 - 1 ] : - var_8 [ var_12 ] = var_11 - else : - var_8 [ var_12 ] = min ( var_11 + 1 , var_8 [ var_12 ] + 1 , var_8 [ var_12 - 1 ] + 1 ) - var_11 = var_13 - return var_8 [ var_3 ] -",10,2 -288,453_Minimum_Moves_to_Equal_Array_Elements_1.py,"def minMoves( nums): - if nums is None or len(nums) == 0: - return 0 - min_num = min(nums) - return sum([i - min_num for i in nums])","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return 0 - var_5 = min ( var_0 ) - return sum ( [ var_7 - var_5 for var_7 in var_0 ] ) -",0None,2 -289,328_Odd_Even_Linked_List_1.py,"def oddEvenList( head): - odd = head - if head is None: - return None - if head.next is None: - return head - even_head = even = head.next - while odd.next is not None and even.next is not None: - odd.next = even.next - odd = odd.next - even.next = odd.next - even = even.next - odd.next = even_head - return head","def sample_funcname ( var_0 ) : - var_1 = var_0 - if var_0 is None : - return None - if var_0.next is None : - return var_0 - var_5 = var_4 = var_0.next - while var_1.next is not None and var_4.next is not None : - var_1.next = var_4.next - var_1 = var_1.next - var_4.next = var_1.next - var_4 = var_4.next - var_1.next = var_5 - return var_0 -",None,1 -290,137_Single_Number_II_2.py,"def singleNumber( nums): - ones, twos, threes = 0, 0, 0 - for num in nums: - twos |= ones & num - ones ^= num - threes = ones & twos - ones &= ~threes - twos &= ~threes - return ones","def sample_funcname ( var_0 ) : - var_2 , var_3 , var_4 = 0 , 0 , 0 - for var_5 in var_0 : - var_3 |= var_2 & var_5 - var_2 ^= var_5 - var_4 = var_2 & var_3 - var_2 &= ~ var_4 - var_3 &= ~ var_4 - return var_2 -",0,1 -291,058_Length_of_Last_Word_1.py,"def lengthOfLastWord( s): - if len(s) == 0: - return 0 - temp = s.split(' ') - temp = [t for t in temp if len(t) > 0] - if len(temp) == 0: - return 0 - else: - return len(temp[-1])","def sample_funcname ( var_0 ) : - if len ( var_0 ) == 0 : - return 0 - var_5 = var_0.split ( ' ' ) - var_5 = [ var_6 for var_6 in var_5 if len ( var_6 ) > 0 ] - if len ( var_5 ) == 0 : - return 0 - else : - return len ( var_5 [ - 1 ] ) -",10 ,3 -292,349_Intersection_of_Two_Arrays_1.py,"def intersection( nums1, nums2): - return list(set(nums1) & set(nums2))","def sample_funcname ( var_0 , var_1 ) : - return list ( set ( var_0 ) & set ( var_1 ) ) -",,0 -293,771_Jewels_and_Stones_1.py,"def numJewelsInStones( J, S): - if len(J) == 0 or len(S) == 0: - return 0 - j_set = set(J) - ans = 0 - for c in S: - if c in j_set: - ans += 1 - return ans","def sample_funcname ( var_0 , var_1 ) : - if len ( var_0 ) == 0 or len ( var_1 ) == 0 : - return 0 - var_5 = set ( var_0 ) - var_6 = 0 - for var_7 in var_1 : - if var_7 in var_5 : - var_6 += 1 - return var_6 -",10,2 -294,045_Jump_Game_II_1.py,"def jump( nums): - if len(nums) <= 1: - return 0 - end = 0 + nums[0] - start = 0 - step = 1 - maxDis = 0 + nums[0] - while end < len(nums) - 1: - for i in range(start + 1, end + 1): - maxDis = max(maxDis, nums[i] + i) - start = end - end = maxDis - step += 1 - return step","def sample_funcname ( var_0 ) : - if len ( var_0 ) <= 1 : - return 0 - var_4 = 0 + var_0 [ 0 ] - var_5 = 0 - var_6 = 1 - var_7 = 0 + var_0 [ 0 ] - while var_4 < len ( var_0 ) - 1 : - for var_9 in range ( var_5 + 1 , var_4 + 1 ) : - var_7 = max ( var_7 , var_0 [ var_9 ] + var_9 ) - var_5 = var_4 - var_4 = var_7 - var_6 += 1 - return var_6 -",10,2 -295,581_Shortest_Unsorted_Continuous_Subarray_3.py,"def findUnsortedSubarray( nums): - smin = 2 ** 31 -1 - smax = -2 ** 31 - flag = False - for i in range(1, len(nums)): - if nums[i] < nums[i-1]: - flag = True - if flag: - smin = min(smin, nums[i]) - flag = False - for i in range(len(nums)-2, -1, -1): - if nums[i] > nums[i+1]: - flag = True - if flag: - smax = max(smax, nums[i]) - for l in range(len(nums)): - if smin < nums[l]: - break - for r in range(len(nums)-1, -1, -1): - if smax > nums[r]: - break - if r > l: - return r - l + 1 - return 0","def sample_funcname ( var_0 ) : - var_4 = 2 ** 31 - 1 - var_5 = - 2 ** 31 - var_7 = False - for var_10 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_10 ] < var_0 [ var_10 - 1 ] : - var_7 = True - if var_7 : - var_4 = min ( var_4 , var_0 [ var_10 ] ) - var_7 = False - for var_10 in range ( len ( var_0 ) - 2 , - 1 , - 1 ) : - if var_0 [ var_10 ] > var_0 [ var_10 + 1 ] : - var_7 = True - if var_7 : - var_5 = max ( var_5 , var_0 [ var_10 ] ) - for var_14 in range ( len ( var_0 ) ) : - if var_4 < var_0 [ var_14 ] : - break - for var_15 in range ( len ( var_0 ) - 1 , - 1 , - 1 ) : - if var_5 > var_0 [ var_15 ] : - break - if var_15 > var_14 : - return var_15 - var_14 + 1 - return 0 -",01312,4 -296,404_Sum_of_Left_Leaves_1.py,"def sumOfLeftLeaves( root): - stack = [root] - res = 0 - while len(stack) > 0: - curr = stack.pop(0) - if curr is not None: - if curr.left is not None: - if curr.left.left is None and curr.left.right is None: - res += curr.left.val - stack.insert(0, curr.right) - stack.insert(0, curr.left) - return res","def sample_funcname ( var_0 ) : - var_1 = [ var_0 ] - var_3 = 0 - while len ( var_1 ) > 0 : - var_6 = var_1.pop ( 0 ) - if var_6 is not None : - if var_6.left is not None : - if var_6.left.left is None and var_6.left.right is None : - var_3 += var_6.left.val - var_1.insert ( 0 , var_6.right ) - var_1.insert ( 0 , var_6.left ) - return var_3 -",0None,2 -297,089_Gray_Code_1.py,"def grayCode( n): - res = [0] - for i in range(n): - for j in reversed(range(len(res))): - res.append(res[j] + (1 << i)) - return res","def sample_funcname ( var_0 ) : - var_2 = [ 0 ] - for var_4 in range ( var_0 ) : - for var_7 in reversed ( range ( len ( var_2 ) ) ) : - var_2.append ( var_2 [ var_7 ] + ( 1 << var_4 ) ) - return var_2 -",10,2 -298,030_Substring_with_Concatenation_of_All_Words_1.py,"def findSubstring( s, words): - ls = len(s) - word_ls = len(words[0]) - target_dict = {} - for word in words: - try: - target_dict[word] += 1 - except KeyError: - target_dict[word] = 1 - res = [] - for start in range(ls - word_ls * len(words) + 1): - curr_dict = target_dict.copy() - for pos in range(start, start + word_ls * len(words), word_ls): - curr = s[pos:pos + word_ls] - try: - curr_dict[curr] -= 1 - if curr_dict[curr] < 0: - break - except KeyError: - break - else: - res.append(start) - return res","def sample_funcname ( var_0 , var_1 ) : - var_3 = len ( var_0 ) - var_5 = len ( var_1 [ 0 ] ) - var_6 = { } - for var_7 in var_1 : - try : - var_6 [ var_7 ] += 1 - except KeyError : - var_6 [ var_7 ] = 1 - var_10 = [ ] - for var_12 in range ( var_3 - var_5 * len ( var_1 ) + 1 ) : - var_14 = var_6.copy ( ) - for var_15 in range ( var_12 , var_12 + var_5 * len ( var_1 ) , var_5 ) : - curr = var_0 [ var_15 : var_15 + var_5 ] - try : - var_14 [ curr ] -= 1 - if var_14 [ curr ] < 0 : - break - except KeyError : - break - else : - var_10.append ( var_12 ) - return var_10 -",10,2 -299,085_Maximal_Rectangle_1.py,"def maximalRectangle( matrix): - if matrix is None or len(matrix) == 0: - return 0 - ls_row, ls_col = len(matrix), len(matrix[0]) - left, right, height = [0] * ls_col, [ls_col] * ls_col, [0] * ls_col - maxA = 0 - for i in range(ls_row): - curr_left, curr_right = 0, ls_col - for j in range(ls_col): - if matrix[i][j] == '1': - height[j] += 1 - else: - height[j] = 0 - for j in range(ls_col): - if matrix[i][j] == '1': - left[j] = max(left[j], curr_left) - else: - left[j], curr_left = 0, j + 1 - for j in range(ls_col - 1, -1, -1): - if matrix[i][j] == '1': - right[j] = min(right[j], curr_right) - else: - right[j], curr_right = ls_col, j - for j in range(ls_col): - maxA = max(maxA, (right[j] - left[j]) * height[j]) - return maxA","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return 0 - var_4 , var_5 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_6 , var_7 , var_8 = [ 0 ] * var_5 , [ var_5 ] * var_5 , [ 0 ] * var_5 - var_9 = 0 - for var_11 in range ( var_4 ) : - var_12 , var_13 = 0 , var_5 - for var_14 in range ( var_5 ) : - if var_0 [ var_11 ] [ var_14 ] == '1' : - var_8 [ var_14 ] += 1 - else : - var_8 [ var_14 ] = 0 - for var_14 in range ( var_5 ) : - if var_0 [ var_11 ] [ var_14 ] == '1' : - var_6 [ var_14 ] = max ( var_6 [ var_14 ] , var_12 ) - else : - var_6 [ var_14 ] , var_12 = 0 , var_14 + 1 - for var_14 in range ( var_5 - 1 , - 1 , - 1 ) : - if var_0 [ var_11 ] [ var_14 ] == '1' : - var_7 [ var_14 ] = min ( var_7 [ var_14 ] , var_13 ) - else : - var_7 [ var_14 ] , var_13 = var_5 , var_14 - for var_14 in range ( var_5 ) : - var_9 = max ( var_9 , ( var_7 [ var_14 ] - var_6 [ var_14 ] ) * var_8 [ var_14 ] ) - return var_9 -",10None1,4 -300,229_Majority_Element_II_3.py,"def majorityElement( nums): - tmp = {} - res = [] - for n in list(set(nums)): - tmp[n] = nums.count(n) - for k, v in tmp.iteritems(): - if v > len(nums) / 3: - res.append(k) - return res","def sample_funcname ( var_0 ) : - var_1 = { } - var_2 = [ ] - for var_5 in list ( set ( var_0 ) ) : - var_1 [ var_5 ] = var_0.count ( var_5 ) - for var_8 , var_9 in var_1.iteritems ( ) : - if var_9 > len ( var_0 ) / 3 : - var_2.append ( var_8 ) - return var_2 -",3,1 -301,717_1-bit_and_2-bit_Characters_2.py,"def isOneBitCharacter( bits): - pos = len(bits) - 2 - - while pos >= 0 and bits[pos] > 0: - pos -= 1 - - return (len(bits) - pos) % 2 == 0","def sample_funcname ( var_0 ) : - var_3 = len ( var_0 ) - 2 - while var_3 >= 0 and var_0 [ var_3 ] > 0 : - var_3 -= 1 - return ( len ( var_0 ) - var_3 ) % 2 == 0 -",102,3 -302,541_Reverse_String_II_1.py,"def reverseStr( s: str, k: int) -> str: - N = len(s) - ans = """" - position = 0 - while position < N: - nx = s[position : position + k] - ans = ans + nx[::-1] + s[position + k : position + 2 * k] - position += 2 * k - return ans","def sample_funcname ( var_0 : str , var_2 : int ) -> str : - var_5 = len ( var_0 ) - var_7 = """" - var_9 = 0 - while var_9 < var_5 : - var_10 = var_0 [ var_9 : var_9 + var_2 ] - var_7 = var_7 + var_10 [ : : - 1 ] + var_0 [ var_9 + var_2 : var_9 + 2 * var_2 ] - var_9 += 2 * var_2 - return var_7 -",102,4 -303,026_Remove_Duplicates_from_Sorted_Array_1.py,"def removeDuplicates( nums): - ls = len(nums) - if ls <= 1: - return ls - last = nums[0] - pos = 1 - for t in nums[1:]: - if t == last: - continue - else: - nums[pos] = t - pos += 1 - last = t - return pos","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - if var_2 <= 1 : - return var_2 - var_5 = var_0 [ 0 ] - var_6 = 1 - for var_7 in var_0 [ 1 : ] : - if var_7 == var_5 : - continue - else : - var_0 [ var_6 ] = var_7 - var_6 += 1 - var_5 = var_7 - return var_6 -",10,2 -304,221_Maximal_Square_1.py,"def maximalSquare( matrix): - if matrix is None or len(matrix) == 0: - return 0 - rows, cols = len(matrix), len(matrix[0]) - res = 0 - for i in range(rows): - for j in range(cols): - if matrix[i][j] == '1': - sqlen, flag = 1, True - while sqlen + i < rows and sqlen + j < cols and flag: - for k in range(j, sqlen + j + 1): - if matrix[i + sqlen][k] == '0': - flag = False - break - for k in range(i, sqlen + i + 1): - if matrix[k][j + sqlen] == '0': - flag = False - break - if flag: - sqlen += 1 - if res < sqlen: - res = sqlen - return res * res","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return 0 - var_4 , var_5 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_6 = 0 - for var_8 in range ( var_4 ) : - for var_9 in range ( var_5 ) : - if var_0 [ var_8 ] [ var_9 ] == '1' : - var_12 , var_14 = 1 , True - while var_12 + var_8 < var_4 and var_12 + var_9 < var_5 and var_14 : - for var_15 in range ( var_9 , var_12 + var_9 + 1 ) : - if var_0 [ var_8 + var_12 ] [ var_15 ] == '0' : - var_14 = False - break - for var_15 in range ( var_8 , var_12 + var_8 + 1 ) : - if var_0 [ var_15 ] [ var_9 + var_12 ] == '0' : - var_14 = False - break - if var_14 : - var_12 += 1 - if var_6 < var_12 : - var_6 = var_12 - return var_6 * var_6 -",0None011,5 -305,416_Partition_Equal_Subset_Sum_1.py,"def canPartition( nums): - if nums is None or len(nums) == 0: - return True - volumn = 0 - for num in nums: - volumn += num - - if volumn % 2 != 0: - return False - - volumn /= 2 - dp = [False] * (volumn + 1) - dp[0] = True - for i in range(1, len(nums) + 1): - for j in range(volumn, nums[i - 1] - 1, -1): - dp[j] = dp[j] or dp[j - nums[i - 1]] - return dp[volumn]","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return True - var_5 = 0 - for var_6 in var_0 : - var_5 += var_6 - if var_5 % 2 != 0 : - return False - var_5 /= 2 - var_10 = [ False ] * ( var_5 + 1 ) - var_10 [ 0 ] = True - for var_12 in range ( 1 , len ( var_0 ) + 1 ) : - for var_13 in range ( var_5 , var_0 [ var_12 - 1 ] - 1 , - 1 ) : - var_10 [ var_13 ] = var_10 [ var_13 ] or var_10 [ var_13 - var_0 [ var_12 - 1 ] ] - return var_10 [ var_5 ] -",10None2,4 -306,217_Contains_Duplicate_2.py,"def containsDuplicate( nums): - nums.sort() - for i in range(len(nums) - 1): - if nums[i] == nums[i + 1]: - return True - return False","def sample_funcname ( var_0 ) : - var_0.sort ( ) - for var_5 in range ( len ( var_0 ) - 1 ) : - if var_0 [ var_5 ] == var_0 [ var_5 + 1 ] : - return True - return False -",1,1 -307,238_Product_of_Array_Except_Self_1.py,"def productExceptSelf( nums): - ans = [1] * len(nums) - for i in range(1, len(nums)): - ans[i] = ans[i - 1] * nums[i - 1] - right = 1 - for i in range(len(nums) - 1, -1, -1): - ans[i] *= right - right *= nums[i] - return ans","def sample_funcname ( var_0 ) : - var_3 = [ 1 ] * len ( var_0 ) - for var_5 in range ( 1 , len ( var_0 ) ) : - var_3 [ var_5 ] = var_3 [ var_5 - 1 ] * var_0 [ var_5 - 1 ] - var_6 = 1 - for var_5 in range ( len ( var_0 ) - 1 , - 1 , - 1 ) : - var_3 [ var_5 ] *= var_6 - var_6 *= var_0 [ var_5 ] - return var_3 -",1,1 -308,152_Maximum_Product_Subarray_1.py,"def maxProduct( nums): - if nums is None or len(nums) == 0: - return 0 - max_here = min_here = max_so_far = nums[0] - for i in range(1, len(nums)): - mx, mn = max_here, min_here - max_here = max(max(mx * nums[i], nums[i]), mn * nums[i]) - min_here = min(min(mx * nums[i], nums[i]), mn * nums[i]) - max_so_far = max(max_here, max_so_far) - return max_so_far","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return 0 - var_6 = var_4 = var_5 = var_0 [ 0 ] - for var_9 in range ( 1 , len ( var_0 ) ) : - var_10 , var_11 = var_6 , var_4 - var_6 = max ( max ( var_10 * var_0 [ var_9 ] , var_0 [ var_9 ] ) , var_11 * var_0 [ var_9 ] ) - var_4 = min ( min ( var_10 * var_0 [ var_9 ] , var_0 [ var_9 ] ) , var_11 * var_0 [ var_9 ] ) - var_5 = max ( var_6 , var_5 ) - return var_5 -",10None,3 -309,973_K_Closest_Points_to_Origin_1.py,"def kClosest( points, K): - return sorted(points, key=lambda x: x[0] ** 2 + x[1] ** 2)[:K]","def sample_funcname ( var_0 , var_1 ) : - return sorted ( var_0 , var_3 = lambda var_4 : var_4 [ 0 ] ** 2 + var_4 [ 1 ] ** 2 ) [ : var_1 ] -",102,3 -310,044_Wildcard_Matching_1.py,"def isMatch( s, p): - m, n = len(s), len(p) - dp = [[False] * (n + 1) for _ in range(m + 1)] - dp[0][0] = True - for j in range(1, n): - dp[0][j + 1] = dp[0][j] and p[j] == '*' - for i in range(m): - for j in range(n): - if p[j] == '?' or p[j] == s[i]: - dp[i + 1][j + 1] = dp[i][j] - elif p[j] == '*': - dp[i + 1][j + 1] = dp[i + 1][j] or dp[i][j + 1] - return dp[m][n]","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = len ( var_0 ) , len ( var_1 ) - var_9 = [ [ False ] * ( var_4 + 1 ) for var_7 in range ( var_3 + 1 ) ] - var_9 [ 0 ] [ 0 ] = True - for var_12 in range ( 1 , var_4 ) : - var_9 [ 0 ] [ var_12 + 1 ] = var_9 [ 0 ] [ var_12 ] and var_1 [ var_12 ] == '*' - for var_14 in range ( var_3 ) : - for var_12 in range ( var_4 ) : - if var_1 [ var_12 ] == '?' or var_1 [ var_12 ] == var_0 [ var_14 ] : - var_9 [ var_14 + 1 ] [ var_12 + 1 ] = var_9 [ var_14 ] [ var_12 ] - elif var_1 [ var_12 ] == '*' : - var_9 [ var_14 + 1 ] [ var_12 + 1 ] = var_9 [ var_14 + 1 ] [ var_12 ] or var_9 [ var_14 ] [ var_12 + 1 ] - return var_9 [ var_3 ] [ var_4 ] -",10?*,4 -311,036_Valid Sudoku_1.py,"def isValidSudoku( board): - vset = [0] * 9 - hset = [0] * 9 - bset = [0] * 9 - for i in range(9): - for j in range(9): - curr = board[i][j] - if curr != '.': - index = 1 << (ord(curr) - ord('0')) - if (hset[i] & index) > 0 or\ - (vset[j] & index) > 0 or\ - (bset[(i / 3) * 3 + j / 3] & index) > 0: - return False - hset[i] |= index - vset[j] |= index - bset[(i / 3) * 3 + j / 3] |= index - return True","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * 9 - var_4 = [ 0 ] * 9 - var_5 = [ 0 ] * 9 - for var_7 in range ( 9 ) : - for var_8 in range ( 9 ) : - var_9 = var_0 [ var_7 ] [ var_8 ] - if var_9 != '.' : - var_14 = 1 << ( ord ( var_9 ) - ord ( '0' ) ) - if ( var_4 [ var_7 ] & var_14 ) > 0 or ( var_3 [ var_8 ] & var_14 ) > 0 or ( var_5 [ ( var_7 / 3 ) * 3 + var_8 / 3 ] & var_14 ) > 0 : - return False - var_4 [ var_7 ] |= var_14 - var_3 [ var_8 ] |= var_14 - var_5 [ ( var_7 / 3 ) * 3 + var_8 / 3 ] |= var_14 - return True -",00.193,6 -312,617_Merge_Two_Binary_Trees_1.py,"def mergeTrees( t1, t2): - if t1 is None: - return t2 - stack = [(t1, t2)] - while len(stack) != 0: - n1, n2 = stack.pop() - if n1 is None or n2 is None: - continue - n1.val += n2.val - if n1.left is None: - n1.left = n2.left - else: - stack.insert(0, (n1.left, n2.left)) - if n1.right is None: - n1.right = n2.right - else: - stack.insert(0, (n1.right, n2.right)) - return t1","def sample_funcname ( var_0 , var_1 ) : - if var_0 is None : - return var_1 - var_3 = [ ( var_0 , var_1 ) ] - while len ( var_3 ) != 0 : - var_7 , var_8 = var_3.pop ( ) - if var_7 is None or var_8 is None : - continue - var_7.val += var_8.val - if var_7.left is None : - var_7.left = var_8.left - else : - var_3.insert ( 0 , ( var_7.left , var_8.left ) ) - if var_7.right is None : - var_7.right = var_8.right - else : - var_3.insert ( 0 , ( var_7.right , var_8.right ) ) - return var_0 -",0None,2 -313,071_Simplify_Path_1.py,"def simplifyPath( path): - result = [] - plist = path.split('/') - for pos in plist: - if pos: - if pos == '..': - try: - result.pop() - except: - result = [] - elif pos != '.': - result.append(pos) - return '/'+'/'.join(result)","def sample_funcname ( var_0 ) : - var_1 = [ ] - var_4 = var_0.split ( '/' ) - for var_5 in var_4 : - if var_5 : - if var_5 == '..' : - try : - var_1.pop ( ) - except : - var_1 = [ ] - elif var_5 != '.' : - var_1.append ( var_5 ) - return '/' + '/'.join ( var_1 ) -",../.,3 -314,068_Text_Justification_1.py,"def fullJustify( words, maxWidth): - res = [] - res_list = [] - curr = [] - count, pos = 0, 0 - while pos < len(words): - word = words[pos] - if len(word) > maxWidth: - pos += 1 - if len(word) + count + len(curr)<= maxWidth: - count += len(word) - curr.append(word) - pos += 1 - else: - res_list.append(curr) - curr = [] - count = 0 - if len(curr) > 0: - res_list.append(curr) - for index, curr in enumerate(res_list): - text = '' - remain = sum([len(t) for t in curr]) - if len(curr) == 1: - text = curr[0] + ' ' * (maxWidth - remain) - elif index == len(res_list) - 1: - text = ' '.join(curr) - text += ' ' * (maxWidth - remain - len(curr) + 1) - else: - step = (maxWidth - remain) / (len(curr) - 1 ) - extra = (maxWidth - remain) % (len(curr) - 1 ) - for index in range(len(curr) - 1): - text += curr[index] + ' ' * step - if extra > 0: - text += ' ' - extra -= 1 - text += curr[-1] - res.append(text) - return res","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - var_3 = [ ] - var_4 = [ ] - var_6 , var_7 = 0 , 0 - while var_7 < len ( var_0 ) : - var_9 = var_0 [ var_7 ] - if len ( var_9 ) > var_1 : - var_7 += 1 - if len ( var_9 ) + var_6 + len ( var_4 ) <= var_1 : - var_6 += len ( var_9 ) - var_4.append ( var_9 ) - var_7 += 1 - else : - var_3.append ( var_4 ) - var_4 = [ ] - var_6 = 0 - if len ( var_4 ) > 0 : - var_3.append ( var_4 ) - for var_13 , var_4 in enumerate ( var_3 ) : - var_15 = '' - var_18 = sum ( [ len ( var_16 ) for var_16 in var_4 ] ) - if len ( var_4 ) == 1 : - var_15 = var_4 [ 0 ] + ' ' * ( var_1 - var_18 ) - elif var_13 == len ( var_3 ) - 1 : - var_15 = ' '.join ( var_4 ) - var_15 += ' ' * ( var_1 - var_18 - len ( var_4 ) + 1 ) - else : - var_21 = ( var_1 - var_18 ) / ( len ( var_4 ) - 1 ) - var_22 = ( var_1 - var_18 ) % ( len ( var_4 ) - 1 ) - for var_13 in range ( len ( var_4 ) - 1 ) : - var_15 += var_4 [ var_13 ] + ' ' * var_21 - if var_22 > 0 : - var_15 += ' ' - var_22 -= 1 - var_15 += var_4 [ - 1 ] - var_2.append ( var_15 ) - return var_2 -",10 ,4 -315,628_Maximum_Product_of_Three_Numbers_1.py,"def maximumProduct( nums): - min1 = min2 = float('inf') - max1 = max2 = max3 = float('-inf') - for num in nums: - if num <= min1: - min2 = min1 - min1 = num - elif num <= min2: - min2 = num - if num >= max1: - max3 = max2 - max2 = max1 - max1 = num - elif num >= max2: - max3 = max2 - max2 = num - elif num >= max3: - max3 = num - return max(min1 * min2 * max1, max1 * max2 * max3)","def sample_funcname ( var_0 ) : - var_4 = var_1 = float ( 'inf' ) - var_8 = var_5 = var_6 = float ( '-inf' ) - for var_9 in var_0 : - if var_9 <= var_4 : - var_1 = var_4 - var_4 = var_9 - elif var_9 <= var_1 : - var_1 = var_9 - if var_9 >= var_8 : - var_6 = var_5 - var_5 = var_8 - var_8 = var_9 - elif var_9 >= var_5 : - var_6 = var_5 - var_5 = var_9 - elif var_9 >= var_6 : - var_6 = var_9 - return max ( var_4 * var_1 * var_8 , var_8 * var_5 * var_6 ) -",-infinf,2 -316,720_Longest_Word_in_Dictionary_1.py,"def longestWord( words): - words.sort() - words_set, longest_word = set(['']), '' - for word in words: - if word[:-1] in words_set: - words_set.add(word) - if len(word) > len(longest_word): - longest_word = word - return longest_word","def sample_funcname ( var_0 ) : - var_0.sort ( ) - var_4 , var_5 = set ( [ '' ] ) , '' - for var_6 in var_0 : - if var_6 [ : - 1 ] in var_4 : - var_4.add ( var_6 ) - if len ( var_6 ) > len ( var_5 ) : - var_5 = var_6 - return var_5 -",1,2 -317,136_Single_Number_1.py,"def singleNumber( nums): - dic = {} - for num in nums: - try: - dic[num] += 1 - except KeyError: - dic[num] = 1 - for num in nums: - if dic[num] == 1: - return num","def sample_funcname ( var_0 ) : - var_1 = { } - for var_2 in var_0 : - try : - var_1 [ var_2 ] += 1 - except KeyError : - var_1 [ var_2 ] = 1 - for var_2 in var_0 : - if var_1 [ var_2 ] == 1 : - return var_2 -",1,1 -318,326_Power_of_Three_1.py,"def isPowerOfThree( n): - import math - if n <= 0: - return False - - log_res = round(math.log(n, 3), 10) - if log_res - int(log_res) > 0: - return False - return True","def sample_funcname ( var_0 ) : - import var_1 - if var_0 <= 0 : - return False - var_8 = round ( var_1.log ( var_0 , 3 ) , 10 ) - if var_8 - int ( var_8 ) > 0 : - return False - return True -",1030,3 -319,1374_Generate_a_String_With_Characters_That_Have_Odd_Counts_Solution_1.py,"def generateTheString( n: int) -> str: - if n%2==0: - return ""a"" * (n-1) + ""b"" - else: - return ""a"" * n","def sample_funcname ( var_0 : int ) -> str : - if var_0 % 2 == 0 : - return ""a"" * ( var_0 - 1 ) + ""b"" - else : - return ""a"" * var_0 -",02a1b,5 -320,219_Contains_Duplicate_II_2.py,"def containsNearbyDuplicate( nums, k): - check = set() - for i in range(len(nums)): - if i > k: - check.remove(nums[i - k - 1]) - if nums[i] in check: - return True - else: - check.add(nums[i]) - return False","def sample_funcname ( var_0 , var_1 ) : - var_3 = set ( ) - for var_6 in range ( len ( var_0 ) ) : - if var_6 > var_1 : - var_3.remove ( var_0 [ var_6 - var_1 - 1 ] ) - if var_0 [ var_6 ] in var_3 : - return True - else : - var_3.add ( var_0 [ var_6 ] ) - return False -",1,1 -321,102_Binary_Tree_Level_Order_Traversal_1.py,"def levelOrder( root): - if root is None: - return [] - q = [[root]] - for level in q: - record = [] - for node in level: - if node.left: - record.append(node.left) - if node.right: - record.append(node.right) - if record: - q.append(record) - return [[x.val for x in level] for level in q]","def sample_funcname ( var_0 ) : - if var_0 is None : - return [ ] - var_2 = [ [ var_0 ] ] - for var_3 in var_2 : - var_4 = [ ] - for var_5 in var_3 : - if var_5.left : - var_4.append ( var_5.left ) - if var_5.right : - var_4.append ( var_5.right ) - if var_4 : - var_2.append ( var_4 ) - return [ [ var_9.val for var_9 in var_3 ] for var_3 in var_2 ] -",None,1 -322,126_Word_Ladder_II_1.py,"def add_path(tree, word, neigh, is_forw): - if is_forw: - tree[word] = tree.get(word, []) + [neigh] - else: - tree[neigh] = tree.get(neigh, []) + [word]","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - if var_3 : - var_0 [ var_1 ] = var_0.get ( var_1 , [ ] ) + [ var_2 ] - else : - var_0 [ var_2 ] = var_0.get ( var_2 , [ ] ) + [ var_1 ] -",,0 -323,709_To_Lower_Case_2.py,"def toLowerCase( str): - return str.lower()","def sample_funcname ( var_0 ) : - return var_0.lower ( ) -",,0 -325,228_Summary_Ranges_2.py,"def summaryRanges( nums): - res = [] - start, ls = 0, len(nums) - for i in range(ls): - if i + 1 < ls and nums[i + 1] == nums[i] + 1: - continue - if i == start: - res.append(str(nums[start])) - else: - res.append(""%d->%d"" % (nums[start], nums[i])) - start = i + 1 - return res","def sample_funcname ( var_0 ) : - var_1 = [ ] - var_3 , var_5 = 0 , len ( var_0 ) - for var_7 in range ( var_5 ) : - if var_7 + 1 < var_5 and var_0 [ var_7 + 1 ] == var_0 [ var_7 ] + 1 : - continue - if var_7 == var_3 : - var_1.append ( str ( var_0 [ var_3 ] ) ) - else : - var_1.append ( ""%d->%d"" % ( var_0 [ var_3 ] , var_0 [ var_7 ] ) ) - var_3 = var_7 + 1 - return var_1 -",10%d->%d,3 -326,205_Isomorphic_Strings_2.py,"def isIsomorphic( s, t): - if len(s) != len(t): - return False - ls = len(s) - mapStoT = [0] * 127 - mapTtoS = [0] * 127 - for i in range(ls): - s_num, t_num = ord(s[i]), ord(t[i]) - if mapStoT[s_num] == 0 and mapTtoS[t_num] == 0: - mapStoT[s_num] = t_num - mapTtoS[t_num] = s_num - elif mapTtoS[t_num] != s_num or mapStoT[s_num] != t_num: - return False - return True","def sample_funcname ( var_0 , var_1 ) : - if len ( var_0 ) != len ( var_1 ) : - return False - var_4 = len ( var_0 ) - var_7 = [ 0 ] * 127 - var_8 = [ 0 ] * 127 - for var_10 in range ( var_4 ) : - var_12 , var_13 = ord ( var_0 [ var_10 ] ) , ord ( var_1 [ var_10 ] ) - if var_7 [ var_12 ] == 0 and var_8 [ var_13 ] == 0 : - var_7 [ var_12 ] = var_13 - var_8 [ var_13 ] = var_12 - elif var_8 [ var_13 ] != var_12 or var_7 [ var_12 ] != var_13 : - return False - return True -",0127,2 -327,246_Strobogrammatic_Number_2.py,"def isStrobogrammatic( num): - return all(num[i] + num[~i] in '696 00 11 88' for i in range(len(num)/2+1))","def sample_funcname ( var_0 ) : - return all ( var_0 [ var_2 ] + var_0 [ ~ var_2 ] in '696 00 11 88' for var_2 in range ( len ( var_0 ) / 2 + 1 ) ) -",696 00 11 8812,3 -328,867_Transpose_Matrix_1.py,"def transpose( A): - res = [] - for i in range(len(A[0])): - temp = [] - for j in range(len(A)): - temp.append(A[j][i]) - res.append(temp) - return res","def sample_funcname ( var_0 ) : - var_1 = [ ] - for var_5 in range ( len ( var_0 [ 0 ] ) ) : - var_6 = [ ] - for var_7 in range ( len ( var_0 ) ) : - var_6.append ( var_0 [ var_7 ] [ var_5 ] ) - var_1.append ( var_6 ) - return var_1 -",0,1 -329,213_House_Robber_II_1.py,"def rob( nums): - if nums is None or len(nums) == 0: - return 0 - ls = len(nums) - dp = [0] * ls - - dp[0] = nums[0] - for i in range(1, ls - 1): - if i < 2: - dp[i] = max(nums[i], dp[i - 1]) - else: - dp[i] = max(dp[i - 2] + nums[i], dp[i - 1]) - res = dp[ls - 2] - - dp[0] = 0 - for i in range(1, ls): - if i < 2: - dp[i] = max(nums[i], dp[i - 1]) - else: - dp[i] = max(dp[i - 2] + nums[i], dp[i - 1]) - return max(res, dp[ls - 1])","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return 0 - var_4 = len ( var_0 ) - var_5 = [ 0 ] * var_4 - var_5 [ 0 ] = var_0 [ 0 ] - for var_8 in range ( 1 , var_4 - 1 ) : - if var_8 < 2 : - var_5 [ var_8 ] = max ( var_0 [ var_8 ] , var_5 [ var_8 - 1 ] ) - else : - var_5 [ var_8 ] = max ( var_5 [ var_8 - 2 ] + var_0 [ var_8 ] , var_5 [ var_8 - 1 ] ) - var_11 = var_5 [ var_4 - 2 ] - var_5 [ 0 ] = 0 - for var_8 in range ( 1 , var_4 ) : - if var_8 < 2 : - var_5 [ var_8 ] = max ( var_0 [ var_8 ] , var_5 [ var_8 - 1 ] ) - else : - var_5 [ var_8 ] = max ( var_5 [ var_8 - 2 ] + var_0 [ var_8 ] , var_5 [ var_8 - 1 ] ) - return max ( var_11 , var_5 [ var_4 - 1 ] ) -",10None2,4 -330,286_Walls_and_Gates_1.py,"def wallsAndGates( rooms): - direction = [(0, 1), (1, 0), (0, -1), (-1, 0)] - m = len(rooms) - if m == 0: - return - n = len(rooms[0]) - q = [] - for row in range(m): - for col in range(n): - if rooms[row][col] == 0: - q.append((row, col)) - - while len(q) > 0: - point = q.pop(0) - row, col = point[0], point[1] - for d in direction: - r = row + d[0] - c = col + d[1] - if r < 0 or c < 0 or r >= m or c >= n or rooms[r][c] != 2147483647: - continue - rooms[r][c] = rooms[row][col] + 1 - q.append((r, c))","def sample_funcname ( var_0 ) : - var_3 = [ ( 0 , 1 ) , ( 1 , 0 ) , ( 0 , - 1 ) , ( - 1 , 0 ) ] - var_5 = len ( var_0 ) - if var_5 == 0 : - return - var_6 = len ( var_0 [ 0 ] ) - var_7 = [ ] - for var_9 in range ( var_5 ) : - for var_10 in range ( var_6 ) : - if var_0 [ var_9 ] [ var_10 ] == 0 : - var_7.append ( ( var_9 , var_10 ) ) - while len ( var_7 ) > 0 : - var_13 = var_7.pop ( 0 ) - var_9 , var_10 = var_13 [ 0 ] , var_13 [ 1 ] - for var_14 in var_3 : - var_15 = var_9 + var_14 [ 0 ] - var_16 = var_10 + var_14 [ 1 ] - if var_15 < 0 or var_16 < 0 or var_15 >= var_5 or var_16 >= var_6 or var_0 [ var_15 ] [ var_16 ] != 2147483647 : - continue - var_0 [ var_15 ] [ var_16 ] = var_0 [ var_9 ] [ var_10 ] + 1 - var_7.append ( ( var_15 , var_16 ) ) -",102147483647,3 -331,368_Largest_Divisible_Subset_1.py,"def largestDivisibleSubset( nums): - S = {-1: set()} - for x in sorted(nums): - - S[x] = max((S[d] for d in S if x % d == 0), key=len) | {x} - return list(max(S.values(), key=len))","def sample_funcname ( var_0 ) : - var_3 = { - 1 : set ( ) } - for var_5 in sorted ( var_0 ) : - var_3 [ var_5 ] = max ( ( var_3 [ var_8 ] for var_8 in var_3 if var_5 % var_8 == 0 ) , var_6 = len ) | { var_5 } - return list ( max ( var_3.values ( ) , var_6 = len ) ) -",10,2 -332,274_H-Index_1.py,"def hIndex( citations): - citations.sort() - ls = len(citations) - h = ls - while h > 0 and citations[ls - h] < h: - h -= 1 - return h","def sample_funcname ( var_0 ) : - var_0.sort ( ) - var_3 = len ( var_0 ) - var_4 = var_3 - while var_4 > 0 and var_0 [ var_3 - var_4 ] < var_4 : - var_4 -= 1 - return var_4 -",10,2 -333,905_Sort_Array_By_Parity_1.py,"def sortArrayByParity( A): - A.sort(key=lambda x: x % 2) - return A","def sample_funcname ( var_0 ) : - var_0.sort ( var_2 = lambda var_3 : var_3 % 2 ) - return var_0 -",2,1 -334,111_Minimum_Depth_of_Binary_Tree_1.py,"def minDepth( root): - if root is None: - return 0 - queue = [root] - depth, rightMost = 1, root - while len(queue) > 0: - node = queue.pop(0) - if node.left is None and node.right is None: - break - if node.left is not None: - queue.append(node.left) - if node.right is not None: - queue.append(node.right) - if node == rightMost: - depth += 1 - if node.right is not None: - rightMost = node.right - else: - rightMost = node.left - return depth","def sample_funcname ( var_0 ) : - if var_0 is None : - return 0 - var_3 = [ var_0 ] - var_5 , var_6 = 1 , var_0 - while len ( var_3 ) > 0 : - var_9 = var_3.pop ( 0 ) - if var_9.left is None and var_9.right is None : - break - if var_9.left is not None : - var_3.append ( var_9.left ) - if var_9.right is not None : - var_3.append ( var_9.right ) - if var_9 == var_6 : - var_5 += 1 - if var_9.right is not None : - var_6 = var_9.right - else : - var_6 = var_9.left - return var_5 -",10None,3 -335,093_Restore_IP_Addresses_2.py,"def isValid( add): - if len(add) == 1: - return True - if add[0] == '0': - return False - if int(add) <= 255: - return True - return False","def sample_funcname ( var_0 ) : - if len ( var_0 ) == 1 : - return True - if var_0 [ 0 ] == '0' : - return False - if int ( var_0 ) <= 255 : - return True - return False -",255100,4 -336,276_Paint_Fence_2.py,"def numWays( n, k): - if n == 0: - return 0 - elif n == 1: - return k - dp = [0] * 2 - dp[0] = k - dp[1] = k * k - for i in range(2, n): - temp = dp[1] - dp[1] = sum(dp) * (k - 1) - dp[0] = temp - return dp[1]","def sample_funcname ( var_0 , var_1 ) : - if var_0 == 0 : - return 0 - elif var_0 == 1 : - return var_1 - var_5 = [ 0 ] * 2 - var_5 [ 0 ] = var_1 - var_5 [ 1 ] = var_1 * var_1 - for var_7 in range ( 2 , var_0 ) : - var_8 = var_5 [ 1 ] - var_5 [ 1 ] = sum ( var_5 ) * ( var_1 - 1 ) - var_5 [ 0 ] = var_8 - return var_5 [ 1 ] -",102,3 -337,242_Valid_Anagram_1.py,"def isAnagram( s, t): - return sorted(s) == sorted(t)","def sample_funcname ( var_0 , var_1 ) : - return sorted ( var_0 ) == sorted ( var_1 ) -",,0 -338,412_Fizz_Buzz_4.py,"def fizzBuzz( n): - return ['Fizz' * (not i % 3) + 'Buzz' * (not i % 5) or str(i) for i in range(1, n+1)]","def sample_funcname ( var_0 ) : - return [ 'Fizz' * ( not var_2 % 3 ) + 'Buzz' * ( not var_2 % 5 ) or str ( var_2 ) for var_2 in range ( 1 , var_0 + 1 ) ] -",5Buzz31Fizz,5 -339,134_Gas_Station_1.py,"def canCompleteCircuit( gas, cost): - ls = len(gas) - begin, end = 0, ls - 1 - curr = gas[end] - cost[end] - while begin < end: - if curr >= 0: - curr += gas[begin] - cost[begin] - begin += 1 - else: - end -= 1 - curr += gas[end] - cost[end] - if curr >= 0: - return end - else: - return -1","def sample_funcname ( var_0 , var_1 ) : - var_3 = len ( var_0 ) - var_5 , var_7 = 0 , var_3 - 1 - var_8 = var_0 [ var_7 ] - var_1 [ var_7 ] - while var_5 < var_7 : - if var_8 >= 0 : - var_8 += var_0 [ var_5 ] - var_1 [ var_5 ] - var_5 += 1 - else : - var_7 -= 1 - var_8 += var_0 [ var_7 ] - var_1 [ var_7 ] - if var_8 >= 0 : - return var_7 - else : - return - 1 -",10,2 -340,441_Arranging_Coins_1.py,"def arrangeCoins( n): - level = 0 - while n > level: - level += 1 - n -= level - return level","def sample_funcname ( var_0 ) : - var_2 = 0 - while var_0 > var_2 : - var_2 += 1 - var_0 -= var_2 - return var_2 -",10,2 -341,733_Flood_Fill_1.py,"def floodFill( image, sr, sc, newColor): - r_ls, c_ls = len(image), len(image[0]) - color = image[sr][sc] - if color == newColor: - return image","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - var_5 , var_7 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_8 = var_0 [ var_1 ] [ var_2 ] - if var_8 == var_3 : - return var_0 -",0,1 -342,094_Binary_Tree_Inorder_Traversal_1.py,"def inorderTraversal( root): - res = [] - if root is None: - return res - queue = [root] - while len(queue) > 0: - curr = queue.pop(0) - if curr.left is None and curr.right is None: - res.append(curr.val) - else: - if curr.right is not None: - queue.insert(0, curr.right) - curr.right = None - queue.insert(0, curr) - if curr.left is not None: - queue.insert(0, curr.left) - curr.left = None - return res","def sample_funcname ( var_0 ) : - var_1 = [ ] - if var_0 is None : - return var_1 - var_3 = [ var_0 ] - while len ( var_3 ) > 0 : - var_7 = var_3.pop ( 0 ) - if var_7.left is None and var_7.right is None : - var_1.append ( var_7.val ) - else : - if var_7.right is not None : - var_3.insert ( 0 , var_7.right ) - var_7.right = None - var_3.insert ( 0 , var_7 ) - if var_7.left is not None : - var_3.insert ( 0 , var_7.left ) - var_7.left = None - return var_1 -",0None,2 -343,665_Non-decreasing_Array_2.py,"def checkPossibility( nums): - broken_num = 0 - for i in range(len(nums) - 1): - if (nums[i] > nums[i + 1]): - broken_num += 1 - if broken_num >= 2: - return False - if (i - 1 < 0 or nums[i - 1] <= nums[i + 1]): - nums[i] = nums[i + 1] - else: - nums[i + 1] = nums[i] - return True","def sample_funcname ( var_0 ) : - var_2 = 0 - for var_6 in range ( len ( var_0 ) - 1 ) : - if ( var_0 [ var_6 ] > var_0 [ var_6 + 1 ] ) : - var_2 += 1 - if var_2 >= 2 : - return False - if ( var_6 - 1 < 0 or var_0 [ var_6 - 1 ] <= var_0 [ var_6 + 1 ] ) : - var_0 [ var_6 ] = var_0 [ var_6 + 1 ] - else : - var_0 [ var_6 + 1 ] = var_0 [ var_6 ] - return True -",102,3 -344,031_Next_Permutation_1.py,"def swap( nums, index1, index2): - if index1 == index2: - return - nums[index1], nums[index2] = nums[index2], nums[index1]","def sample_funcname ( var_0 , var_1 , var_2 ) : - if var_1 == var_2 : - return - var_0 [ var_1 ] , var_0 [ var_2 ] = var_0 [ var_2 ] , var_0 [ var_1 ] -",,0 -345,258_Add_Digits_1.py,"def addDigits( num): - if num < 10: - return num - return num - ((num - 1) / 9) * 9","def sample_funcname ( var_0 ) : - if var_0 < 10 : - return var_0 - return var_0 - ( ( var_0 - 1 ) / 9 ) * 9 -",1019,3 -346,438_Find_All_Anagrams_in_a_String_2.py,"def findAnagrams( s, p): - if len(s) < len(p): - return [] - res = [] - p_len = len(p) - bit_map = [] - for _ in range(26): - bit_map.append(0) - for c in p: - bit_map[ord(c) - ord('a')] += 1 - s_p = str(bit_map) - for i in range(26): - bit_map[i] = 0 - for i in range(p_len - 1): - bit_map[ord(s[i]) - ord('a')] += 1 - for i in range(p_len - 1, len(s)): - bit_map[ord(s[i]) - ord('a')] += 1 - if i - p_len >= 0: - bit_map[ord(s[i - p_len]) - ord('a')] -= 1 - if str(bit_map) == s_p: - res.append(i - p_len + 1) - return res","def sample_funcname ( var_0 , var_1 ) : - if len ( var_0 ) < len ( var_1 ) : - return [ ] - var_3 = [ ] - var_4 = len ( var_1 ) - var_5 = [ ] - for var_8 in range ( 26 ) : - var_5.append ( 0 ) - for var_11 in var_1 : - var_5 [ ord ( var_11 ) - ord ( 'a' ) ] += 1 - var_16 = str ( var_5 ) - for var_17 in range ( 26 ) : - var_5 [ var_17 ] = 0 - for var_17 in range ( var_4 - 1 ) : - var_5 [ ord ( var_0 [ var_17 ] ) - ord ( 'a' ) ] += 1 - for var_17 in range ( var_4 - 1 , len ( var_0 ) ) : - var_5 [ ord ( var_0 [ var_17 ] ) - ord ( 'a' ) ] += 1 - if var_17 - var_4 >= 0 : - var_5 [ ord ( var_0 [ var_17 - var_4 ] ) - ord ( 'a' ) ] -= 1 - if str ( var_5 ) == var_16 : - var_3.append ( var_17 - var_4 + 1 ) - return var_3 -",a0126,4 -347,120_Triangle_1.py,"def minimumTotal( triangle): - if triangle is None or len(triangle) == 0: - return 0 - ls = len(triangle) - dp = [0] * ls - dp[0] = triangle[0][0] - for i in range(1, ls): - dp[i] = dp[i - 1] + triangle[i][i] - for j in reversed(range(1, i)): - dp[j] = min(dp[j - 1] + triangle[i][j], dp[j] + triangle[i][j]) - dp[0] = dp[0] + triangle[i][0] - return min(dp)","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return 0 - var_4 = len ( var_0 ) - var_5 = [ 0 ] * var_4 - var_5 [ 0 ] = var_0 [ 0 ] [ 0 ] - for var_8 in range ( 1 , var_4 ) : - var_5 [ var_8 ] = var_5 [ var_8 - 1 ] + var_0 [ var_8 ] [ var_8 ] - for var_10 in reversed ( range ( 1 , var_8 ) ) : - var_5 [ var_10 ] = min ( var_5 [ var_10 - 1 ] + var_0 [ var_8 ] [ var_10 ] , var_5 [ var_10 ] + var_0 [ var_8 ] [ var_10 ] ) - var_5 [ 0 ] = var_5 [ 0 ] + var_0 [ var_8 ] [ 0 ] - return min ( var_5 ) -",10None,3 -348,457_Circular_Array_Loop_1.py,"def index( nums, index): - length = len(nums) - return (index + nums[index] + length) % length","def sample_funcname ( var_1 , var_0 ) : - var_3 = len ( var_1 ) - return ( var_0 + var_1 [ var_0 ] + var_3 ) % var_3 -",,0 -349,338_Counting_Bits_1.py,"def countBits( num): - res = [0] * (num + 1) - for i in range(1, num + 1): - res[i] = res[i >> 1] + (i & 1) - return res","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * ( var_0 + 1 ) - for var_5 in range ( 1 , var_0 + 1 ) : - var_3 [ var_5 ] = var_3 [ var_5 >> 1 ] + ( var_5 & 1 ) - return var_3 -",10,2 -350,055_Jump_Game_1.py,"def canJump( nums): - length = len(nums) - begin = length - 1 - for i in reversed(range(length - 1)): - if i + nums[i] >= begin: - begin = i - return not begin","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_4 = var_2 - 1 - for var_7 in reversed ( range ( var_2 - 1 ) ) : - if var_7 + var_0 [ var_7 ] >= var_4 : - var_4 = var_7 - return not var_4 -",1,1 -351,154_Find_Minimum_in_Rotated_Sorted_Array_II_1.py,"def findMin( nums): - start, end = 0, len(nums) - 1 - while start < end: - mid = (start + end) / 2 - if nums[mid] > nums[end]: - start = mid + 1 - elif nums[mid] < nums[end]: - end = mid - else: - end -= 1 - return nums[start]","def sample_funcname ( var_0 ) : - var_2 , var_5 = 0 , len ( var_0 ) - 1 - while var_2 < var_5 : - var_7 = ( var_2 + var_5 ) / 2 - if var_0 [ var_7 ] > var_0 [ var_5 ] : - var_2 = var_7 + 1 - elif var_0 [ var_7 ] < var_0 [ var_5 ] : - var_5 = var_7 - else : - var_5 -= 1 - return var_0 [ var_2 ] -",102,3 -352,280_Wiggle_Sort_3.py,"def wiggleSort( nums): - less = True - for i in range(len(nums) - 1): - if less: - if nums[i] > nums[i + 1]: - nums[i], nums[i + 1] = nums[i + 1], nums[i] - else: - if nums[i] < nums[i + 1]: - nums[i], nums[i + 1] = nums[i + 1], nums[i] - less = not less","def sample_funcname ( var_0 ) : - var_2 = True - for var_6 in range ( len ( var_0 ) - 1 ) : - if var_2 : - if var_0 [ var_6 ] > var_0 [ var_6 + 1 ] : - var_0 [ var_6 ] , var_0 [ var_6 + 1 ] = var_0 [ var_6 + 1 ] , var_0 [ var_6 ] - else : - if var_0 [ var_6 ] < var_0 [ var_6 + 1 ] : - var_0 [ var_6 ] , var_0 [ var_6 + 1 ] = var_0 [ var_6 + 1 ] , var_0 [ var_6 ] - var_2 = not var_2 -",1,1 -353,547_Friend_Circles_1.py,"def findCircleNum( M): - visited = [0] * len(M) - count = 0 - queue = [] - for i in range(len(M)): - if visited[i] == 0: - queue.append(i) - while queue: - curr = queue.pop(0) - visited[curr] = 1 - for j in range(len(M)): - if M[curr][j] == 1 and visited[j] == 0: - queue.append(j) - count += 1 - return count","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * len ( var_0 ) - var_4 = 0 - var_5 = [ ] - for var_7 in range ( len ( var_0 ) ) : - if var_3 [ var_7 ] == 0 : - var_5.append ( var_7 ) - while var_5 : - var_10 = var_5.pop ( 0 ) - var_3 [ var_10 ] = 1 - for var_12 in range ( len ( var_0 ) ) : - if var_0 [ var_10 ] [ var_12 ] == 1 and var_3 [ var_12 ] == 0 : - var_5.append ( var_12 ) - var_4 += 1 - return var_4 -",10,2 -354,415_Add_Strings_2.py,"def addStrings( num1, num2): - res = [] - pos1 = len(num1) - 1 - pos2 = len(num2) - 1 - carry = 0 - while pos1 >= 0 or pos2 >= 0 or carry == 1: - digit1 = digit2 = 0 - if pos1 >= 0: - digit1 = ord(num1[pos1]) - ord('0') - if pos2 >= 0: - digit2 = ord(num2[pos2]) - ord('0') - res.append(str((digit1 + digit2 + carry) % 10)) - carry = (digit1 + digit2 + carry) / 10 - pos1 -= 1 - pos2 -= 1 - return ''.join(res[::-1])","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - var_5 = len ( var_0 ) - 1 - var_6 = len ( var_1 ) - 1 - var_8 = 0 - while var_5 >= 0 or var_6 >= 0 or var_8 == 1 : - var_10 = var_9 = 0 - if var_5 >= 0 : - var_10 = ord ( var_0 [ var_5 ] ) - ord ( '0' ) - if var_6 >= 0 : - var_9 = ord ( var_1 [ var_6 ] ) - ord ( '0' ) - var_2.append ( str ( ( var_10 + var_9 + var_8 ) % 10 ) ) - var_8 = ( var_10 + var_9 + var_8 ) / 10 - var_5 -= 1 - var_6 -= 1 - return ''.join ( var_2 [ : : - 1 ] ) -",10001,5 -355,868_Binary_Gap_1.py,"def binaryGap( n: int) -> int: - current = 1 - last1 = -1 - out = 0 - while n > 0: - if n % 2 == 1: - if last1 >= 1: - out = max(out, current - last1) - last1 = current - current += 1 - n = n // 2 - return out","def sample_funcname ( var_0 : int ) -> int : - var_3 = 1 - var_4 = - 1 - var_6 = 0 - while var_0 > 0 : - if var_0 % 2 == 1 : - if var_4 >= 1 : - var_6 = max ( var_6 , var_3 - var_4 ) - var_4 = var_3 - var_3 += 1 - var_0 = var_0 // 2 - return var_6 -",102,3 -356,1064_Fixed_Point_1.py,"def fixedPoint( A): - for index, value in enumerate(A): - - if index == value: - return index - elif index < value: - return -1","def sample_funcname ( var_0 ) : - for var_2 , var_3 in enumerate ( var_0 ) : - if var_2 == var_3 : - return var_2 - elif var_2 < var_3 : - return - 1 -",1,1 -357,066_Plus_One_2.py,"def plusOne( digits): - ls = len(digits) - for index in reversed(range(ls)): - if digits[index] < 9: - digits[index] += 1 - return digits - else: - digits[index] = 0 - digits.insert(0, 1) - return digits","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - for var_5 in reversed ( range ( var_2 ) ) : - if var_0 [ var_5 ] < 9 : - var_0 [ var_5 ] += 1 - return var_0 - else : - var_0 [ var_5 ] = 0 - var_0.insert ( 0 , 1 ) - return var_0 -",910,3 -358,401_Binary_Watch_1.py,"def readBinaryWatch( num): - return ['%d:%02d' % (h, m) - for h in range(12) for m in range(60) - if (bin(h) + bin(m)).count('1') == num]","def sample_funcname ( var_0 ) : - return [ '%d:%02d' % ( var_2 , var_3 ) for var_2 in range ( 12 ) for var_3 in range ( 60 ) if ( bin ( var_2 ) + bin ( var_3 ) ).count ( '1' ) == var_0 ] -",%d:%02d60121,4 -359,253_Meeting_Rooms_II_1.py,"def minMeetingRooms( intervals): - timeline = [] - for interval in intervals: - timeline.append((interval.start, 1)) - timeline.append((interval.end, -1)) - timeline.sort() - ans = curr = 0 - for _, v in timeline: - curr += v - ans = max(ans, curr) - return ans","def sample_funcname ( var_0 ) : - var_1 = [ ] - for var_2 in var_0 : - var_1.append ( ( var_2.start , 1 ) ) - var_1.append ( ( var_2.end , - 1 ) ) - var_1.sort ( ) - var_10 = var_8 = 0 - for var_11 , var_12 in var_1 : - var_8 += var_12 - var_10 = max ( var_10 , var_8 ) - return var_10 -",10,2 -360,019_Remove_Nth_Node_From_End_of_List_2.py,"def removeNthFromEnd( head, n): - if head is None: - return None - slow = fast = head - for i in range(n): - fast = fast.next - if fast is None: - head = head.next - return head - while fast.next is not None: - fast = fast.next - slow = slow.next - curr = slow.next - slow.next = curr.next - return head","def sample_funcname ( var_0 , var_1 ) : - if var_0 is None : - return None - var_4 = var_3 = var_0 - for var_6 in range ( var_1 ) : - var_3 = var_3.next - if var_3 is None : - var_0 = var_0.next - return var_0 - while var_3.next is not None : - var_3 = var_3.next - var_4 = var_4.next - var_8 = var_4.next - var_4.next = var_8.next - return var_0 -",None,1 -361,027_Remove_Element_2.py,"def removeElement( nums, val): - ls = len(nums) - if ls == 0: - return ls - count = 0 - index = 0 - while index < ls - count: - if nums[index] == val: - nums[index] = nums[ls - 1 - count] - count += 1 - else: - index += 1 - return ls - count","def sample_funcname ( var_0 , var_1 ) : - var_3 = len ( var_0 ) - if var_3 == 0 : - return var_3 - var_5 = 0 - var_6 = 0 - while var_6 < var_3 - var_5 : - if var_0 [ var_6 ] == var_1 : - var_0 [ var_6 ] = var_0 [ var_3 - 1 - var_5 ] - var_5 += 1 - else : - var_6 += 1 - return var_3 - var_5 -",10,2 -362,389_Find_the_Difference_1.py,"def findTheDifference( s, t): - res = ord(t[-1]) - for i in range(len(s)): - res += ord(t[i]) - res -= ord(s[i]) - return chr(res)","def sample_funcname ( var_0 , var_1 ) : - var_4 = ord ( var_1 [ - 1 ] ) - for var_7 in range ( len ( var_0 ) ) : - var_4 += ord ( var_1 [ var_7 ] ) - var_4 -= ord ( var_0 [ var_7 ] ) - return chr ( var_4 ) -",1,1 -363,370_Range_Addition_1.py,"def getModifiedArray( length, updates): - res = [0] * length - for t in updates: - start, end, val = t - res[start] += val - if end < length - 1: - res[end + 1] -= val - for i in range(1, length): - res[i] = res[i] + res[i - 1] - return res","def sample_funcname ( var_0 , var_1 ) : - var_3 = [ 0 ] * var_0 - for var_4 in var_1 : - var_5 , var_6 , var_7 = var_4 - var_3 [ var_5 ] += var_7 - if var_6 < var_0 - 1 : - var_3 [ var_6 + 1 ] -= var_7 - for var_10 in range ( 1 , var_0 ) : - var_3 [ var_10 ] = var_3 [ var_10 ] + var_3 [ var_10 - 1 ] - return var_3 -",10,2 -364,421_Maximum_XOR_of_Two_Numbers_in_an_Array_1.py,"def findMaximumXOR( nums): - answer = 0 - for i in range(32)[::-1]: - answer <<= 1 - prefixes = {num >> i for num in nums} - answer += any(answer ^ 1 ^ p in prefixes for p in prefixes) - return answer","def sample_funcname ( var_0 ) : - var_2 = 0 - for var_6 in range ( 32 ) [ : : - 1 ] : - var_2 <<= 1 - var_8 = { var_7 >> var_6 for var_7 in var_0 } - var_2 += any ( var_2 ^ 1 ^ var_9 in var_8 for var_9 in var_8 ) - return var_2 -",1032,3 -365,065_Valid_Number_1.py,"def isNumber( s): - s = s.strip() - try: - float(s) - return True - except: - if '.' in s or ' ' in s: - return False - temp = s.split('e') - if len(temp) == 2: - try: - int(temp[0]) - int(temp[1]) - except: - return False - return True - return False","def sample_funcname ( var_0 ) : - var_0 = var_0.strip ( ) - try : - float ( var_0 ) - return True - except : - if '.' in var_0 or ' ' in var_0 : - return False - var_9 = var_0.split ( 'e' ) - if len ( var_9 ) == 2 : - try : - int ( var_9 [ 0 ] ) - int ( var_9 [ 1 ] ) - except : - return False - return True - return False -",0e2.1 ,6 -366,088_Merge_Sorted_Array_2.py,"def merge( nums1, m, nums2, n): - i, j, k = m - 1, n - 1, m + n - 1 - while i >= 0 and j >= 0: - if nums1[i] > nums2[j]: - nums1[k] = nums1[i] - i -= 1 - else: - nums1[k] = nums2[j] - j -= 1 - k -= 1 - - if j >= 0: - nums1[:k + 1] = nums2[:j + 1]","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - var_5 , var_6 , var_7 = var_1 - 1 , var_3 - 1 , var_1 + var_3 - 1 - while var_5 >= 0 and var_6 >= 0 : - if var_0 [ var_5 ] > var_2 [ var_6 ] : - var_0 [ var_7 ] = var_0 [ var_5 ] - var_5 -= 1 - else : - var_0 [ var_7 ] = var_2 [ var_6 ] - var_6 -= 1 - var_7 -= 1 - if var_6 >= 0 : - var_0 [ : var_7 + 1 ] = var_2 [ : var_6 + 1 ] -",10,2 -367,266_Palindrome_Permutation_1.py,"def canPermutePalindrome( s): - dic = {} - for c in s: - dic[c] = dic.get(c, 0) + 1 - odd, even = 0, 0 - for c in dic: - if dic[c] % 2 == 0: - even += 1 - else: - odd += 1 - if odd <= 1: - return True - return False","def sample_funcname ( var_0 ) : - var_1 = { } - for var_2 in var_0 : - var_1 [ var_2 ] = var_1.get ( var_2 , 0 ) + 1 - var_6 , var_7 = 0 , 0 - for var_2 in var_1 : - if var_1 [ var_2 ] % 2 == 0 : - var_7 += 1 - else : - var_6 += 1 - if var_6 <= 1 : - return True - return False -",102,3 -368,074_Search_a_2D_Matrix_2.py,"def searchMatrix( matrix, target): - try: - ls_row, ls_col = len(matrix), len(matrix[0]) - except: - return False - if target < matrix[0][0] or target > matrix[-1][-1]: - return False - begin, end = 0, ls_row * ls_col - 1 - while begin <= end: - mid = (begin + end) / 2 - row, col = mid / ls_col, mid % ls_col - if matrix[row][col] == target: - return True - elif matrix[row][col] > target: - end = mid - 1 - else: - begin = mid + 1 - return False","def sample_funcname ( var_0 , var_1 ) : - try : - var_3 , var_5 = len ( var_0 ) , len ( var_0 [ 0 ] ) - except : - return False - if var_1 < var_0 [ 0 ] [ 0 ] or var_1 > var_0 [ - 1 ] [ - 1 ] : - return False - var_8 , var_9 = 0 , var_3 * var_5 - 1 - while var_8 <= var_9 : - var_11 = ( var_8 + var_9 ) / 2 - var_12 , var_13 = var_11 / var_5 , var_11 % var_5 - if var_0 [ var_12 ] [ var_13 ] == var_1 : - return True - elif var_0 [ var_12 ] [ var_13 ] > var_1 : - var_9 = var_11 - 1 - else : - var_8 = var_11 + 1 - return False -",102,3 -369,280_Wiggle_Sort_2.py,"def wiggleSort( nums): - if nums is None or len(nums) == 0: - return - nums.sort() - for i in range(1, len(nums) - 1, 2): - - nums[i], nums[i + 1] = nums[i + 1], nums[i]","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return - var_0.sort ( ) - for var_8 in range ( 1 , len ( var_0 ) - 1 , 2 ) : - var_0 [ var_8 ] , var_0 [ var_8 + 1 ] = var_0 [ var_8 + 1 ] , var_0 [ var_8 ] -",10None2,4 -370,408_Valid_Word_Abbreviation_2.py,"def validWordAbbreviation( word, abbr): - pos = curr = 0 - for i in range(len(abbr)): - try: - num = int(abbr[i]) - if num == 0 and curr == 0: - return False - curr = curr * 10 + num - except ValueError: - pos += curr - curr = 0 - if pos >= len(word): - return False - if word[pos] != abbr[i]: - return False - pos += 1 - pos += curr - if pos == len(word): - return True - return False","def sample_funcname ( var_0 , var_1 ) : - var_4 = var_2 = 0 - for var_7 in range ( len ( var_1 ) ) : - try : - var_9 = int ( var_1 [ var_7 ] ) - if var_9 == 0 and var_2 == 0 : - return False - var_2 = var_2 * 10 + var_9 - except ValueError : - var_4 += var_2 - var_2 = 0 - if var_4 >= len ( var_0 ) : - return False - if var_0 [ var_4 ] != var_1 [ var_7 ] : - return False - var_4 += 1 - var_4 += var_2 - if var_4 == len ( var_0 ) : - return True - return False -",1001,3 -371,018_4Sum_1.py,"def fourSum( nums, target): - sort_nums = sorted(nums) - ls = len(nums) - res = {} - pairs = {} - for i in range(ls - 3): - for j in range(i + 1, ls - 2): - res_2 = sort_nums[i] + sort_nums[j] - try: - pairs[target - res_2].append([i, j]) - except KeyError: - pairs[target - res_2] = [[i, j]] - for key, temp in pairs.items(): - for pair in temp: - j = pair[1] + 1 - k = ls - 1 - while j < k: - current = sort_nums[j] + sort_nums[k] - if current == key: - result = (sort_nums[pair[0]], sort_nums[pair[1]], sort_nums[j], sort_nums[k]) - res[result] = True - j += 1 - elif current < key: - j += 1 - else: - k -= 1 - return res.keys()","def sample_funcname ( var_0 , var_1 ) : - var_3 = sorted ( var_0 ) - var_5 = len ( var_0 ) - var_6 = { } - var_7 = { } - for var_10 in range ( var_5 - 3 ) : - for var_13 in range ( var_10 + 1 , var_5 - 2 ) : - var_14 = var_3 [ var_10 ] + var_3 [ var_13 ] - try : - var_7 [ var_1 - var_14 ].append ( [ var_10 , var_13 ] ) - except KeyError : - var_7 [ var_1 - var_14 ] = [ [ var_10 , var_13 ] ] - for var_18 , var_19 in var_7.items ( ) : - for var_20 in var_19 : - var_13 = var_20 [ 1 ] + 1 - var_21 = var_5 - 1 - while var_13 < var_21 : - var_22 = var_3 [ var_13 ] + var_3 [ var_21 ] - if var_22 == var_18 : - var_24 = ( var_3 [ var_20 [ 0 ] ] , var_3 [ var_20 [ 1 ] ] , var_3 [ var_13 ] , var_3 [ var_21 ] ) - var_6 [ var_24 ] = True - var_13 += 1 - elif var_22 < var_18 : - var_13 += 1 - else : - var_21 -= 1 - return var_6.keys ( ) -",3102,4 -372,121_Best_Time_to_Buy_and_Sell_Stock_1.py,"def maxProfit( prices): - length = len(prices) - if length == 0: - return 0 - max_profit, low = 0, prices[0] - for i in range(1, length): - if low > prices[i]: - low = prices[i] - else: - temp = prices[i] - low - if temp > max_profit: - max_profit = temp - return max_profit","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - if var_2 == 0 : - return 0 - var_4 , var_5 = 0 , var_0 [ 0 ] - for var_8 in range ( 1 , var_2 ) : - if var_5 > var_0 [ var_8 ] : - var_5 = var_0 [ var_8 ] - else : - var_9 = var_0 [ var_8 ] - var_5 - if var_9 > var_4 : - var_4 = var_9 - return var_4 -",10,2 -374,070_Climbing_Stairs_2.py,"def climbStairs( n): - if n <= 1: - return 1 - dp = [1] * 2 - for i in range(2, n + 1): - dp[1], dp[0] = dp[1] + dp[0], dp[1] - return dp[1]","def sample_funcname ( var_0 ) : - if var_0 <= 1 : - return 1 - var_3 = [ 1 ] * 2 - for var_5 in range ( 2 , var_0 + 1 ) : - var_3 [ 1 ] , var_3 [ 0 ] = var_3 [ 1 ] + var_3 [ 0 ] , var_3 [ 1 ] - return var_3 [ 1 ] -",102,3 -375,043_Multiply_Strings_2.py,"def multiply( num1, num2): - if num1 == '0' or num2 == '0': - return '0' - res = '' - ls1, ls2, = len(num1), len(num2) - ls = ls1 + ls2 - arr = [0] * ls - for i in reversed(range(ls1)): - for j in reversed(range(ls2)): - arr[i + j + 1] += int(num1[i]) * int(num2[j]) - for i in reversed(range(1, ls)): - arr[i - 1] += arr[i] / 10 - arr[i] %= 10 - pos = 0 - if arr[pos] == 0: - pos += 1 - while pos < ls: - res = res + str(arr[pos]) - pos += 1 - return res","def sample_funcname ( var_0 , var_1 ) : - if var_0 == '0' or var_1 == '0' : - return '0' - var_4 = '' - var_6 , var_7 , = len ( var_0 ) , len ( var_1 ) - var_8 = var_6 + var_7 - var_10 = [ 0 ] * var_8 - for var_13 in reversed ( range ( var_6 ) ) : - for var_14 in reversed ( range ( var_7 ) ) : - var_10 [ var_13 + var_14 + 1 ] += int ( var_0 [ var_13 ] ) * int ( var_1 [ var_14 ] ) - for var_13 in reversed ( range ( 1 , var_8 ) ) : - var_10 [ var_13 - 1 ] += var_10 [ var_13 ] / 10 - var_10 [ var_13 ] %= 10 - var_18 = 0 - if var_10 [ var_18 ] == 0 : - var_18 += 1 - while var_18 < var_8 : - var_4 = var_4 + str ( var_10 [ var_18 ] ) - var_18 += 1 - return var_4 -",10001,5 -376,1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number_2.py,"def smallerNumbersThanCurrent( nums: List[int]) -> List[int]: - count_list = [0] * 101 - for v in nums: - count_list[v] += 1 - for i in range(1, 101): - count_list[i] += count_list[i-1] - res = [] - for v in nums: - if v == 0: - res.append(0) - else: - res.append(count_list[v-1]) - return res","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_5 = [ 0 ] * 101 - for var_6 in var_0 : - var_5 [ var_6 ] += 1 - for var_9 in range ( 1 , 101 ) : - var_5 [ var_9 ] += var_5 [ var_9 - 1 ] - var_10 = [ ] - for var_6 in var_0 : - if var_6 == 0 : - var_10.append ( 0 ) - else : - var_10.append ( var_5 [ var_6 - 1 ] ) - return var_10 -",10101,3 -377,049_Group_Anagrams_2.py,"def hash_key( s): - table = [0] * 26 - for ch in s: - index = ord(ch) - ord('a') - table[index] += 1 - return str(table)","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * 26 - for var_4 in var_0 : - var_7 = ord ( var_4 ) - ord ( 'a' ) - var_3 [ var_7 ] += 1 - return str ( var_3 ) -",a0126,4 -378,083_Remove_Duplicates_from_Sorted_List_1.py,"def deleteDuplicates( head): - if head is None: - return None - pos = head - while pos is not None and pos.next is not None: - if pos.val == pos.next.val: - pos.next = pos.next.next - else: - pos = pos.next - return head","def sample_funcname ( var_0 ) : - if var_0 is None : - return None - var_2 = var_0 - while var_2 is not None and var_2.next is not None : - if var_2.val == var_2.next.val : - var_2.next = var_2.next.next - else : - var_2 = var_2.next - return var_0 -",None,1 -379,342_Power_of_Four_1.py,"def isPowerOfFour( num): - return num > 0 and num & (num-1) == 0 and len(bin(num)[3:]) % 2 == 0","def sample_funcname ( var_0 ) : - return var_0 > 0 and var_0 & ( var_0 - 1 ) == 0 and len ( bin ( var_0 ) [ 3 : ] ) % 2 == 0 -",1302,4 -381,160_Intersection_of_Two_Linked_Lists_1.py,"def getIntersectionNode( headA, headB): - if not headA or not headB: - return None - a, b = headA, headB - ans = None - while a or b: - if not a: - a = headB - if not b: - b = headA - if a == b and not ans: - ans = a - a, b = a.next, b.next - return ans","def sample_funcname ( var_0 , var_1 ) : - if not var_0 or not var_1 : - return None - var_3 , var_4 = var_0 , var_1 - var_5 = None - while var_3 or var_4 : - if not var_3 : - var_3 = var_1 - if not var_4 : - var_4 = var_0 - if var_3 == var_4 and not var_5 : - var_5 = var_3 - var_3 , var_4 = var_3.next , var_4.next - return var_5 -",None,1 -382,040_Combination_Sum_II_1.py,"def combinationSum2( candidates, target): - candidates.sort() - dp = [[] for _ in range(target + 1)] - dp[0].append([]) - for i in range(1, target + 1): - for j in range(len(candidates)): - if candidates[j] > i: - break - for k in range(len(dp[i - candidates[j]])): - temp = dp[i - candidates[j]][k][:] - if len(temp) > 0 and temp[-1] >= j: - continue - temp.append(j) - dp[i].append(temp) - res = [] - check = {} - for temp in dp[target]: - value = [candidates[t] for t in temp] - try: - check[str(value)] += 1 - except KeyError: - check[str(value)] = 1 - res.append(value) - return res","def sample_funcname ( var_0 , var_1 ) : - var_0.sort ( ) - var_6 = [ [ ] for var_3 in range ( var_1 + 1 ) ] - var_6 [ 0 ].append ( [ ] ) - for var_9 in range ( 1 , var_1 + 1 ) : - for var_11 in range ( len ( var_0 ) ) : - if var_0 [ var_11 ] > var_9 : - break - for var_12 in range ( len ( var_6 [ var_9 - var_0 [ var_11 ] ] ) ) : - var_13 = var_6 [ var_9 - var_0 [ var_11 ] ] [ var_12 ] [ : ] - if len ( var_13 ) > 0 and var_13 [ - 1 ] >= var_11 : - continue - var_13.append ( var_11 ) - var_6 [ var_9 ].append ( var_13 ) - var_14 = [ ] - var_15 = { } - for var_13 in var_6 [ var_1 ] : - var_17 = [ var_0 [ var_16 ] for var_16 in var_13 ] - try : - var_15 [ str ( var_17 ) ] += 1 - except KeyError : - var_15 [ str ( var_17 ) ] = 1 - var_14.append ( var_17 ) - return var_14 -",10,2 -383,226_Invert_Binary_Tree_1.py,"def invertTree( root): - if root is None: - return None - queue = [root] - while len(queue): - curr = queue.pop(0) - curr.left, curr.right = curr.right, curr.left - if curr.left is not None: - queue.append(curr.left) - if curr.right is not None: - queue.append(curr.right) - return root","def sample_funcname ( var_0 ) : - if var_0 is None : - return None - var_2 = [ var_0 ] - while len ( var_2 ) : - var_6 = var_2.pop ( 0 ) - var_6.left , var_6.right = var_6.right , var_6.left - if var_6.left is not None : - var_2.append ( var_6.left ) - if var_6.right is not None : - var_2.append ( var_6.right ) - return var_0 -",0None,2 -384,206_Reverse_Linked_List_2.py,"def reverseList( head): - prev, curr = None, head - while curr is not None: - next_temp = curr.next - curr.next = prev - prev = curr - curr = next_temp - return prev","def sample_funcname ( var_0 ) : - var_2 , var_3 = None , var_0 - while var_3 is not None : - var_5 = var_3.next - var_3.next = var_2 - var_2 = var_3 - var_3 = var_5 - return var_2 -",None,1 -385,075_Sort_Colors_2.py,"def sortColors( nums): - low, mid, high = 0, 0, len(nums) - 1 - while mid <= high: - if nums[mid] == 0: - nums[low], nums[mid] = nums[mid], nums[low] - low += 1 - mid += 1 - elif nums[mid] == 1: - mid += 1 - else: - nums[high], nums[mid] = nums[mid], nums[high] - high -= 1 - return","def sample_funcname ( var_0 ) : - var_2 , var_3 , var_6 = 0 , 0 , len ( var_0 ) - 1 - while var_3 <= var_6 : - if var_0 [ var_3 ] == 0 : - var_0 [ var_2 ] , var_0 [ var_3 ] = var_0 [ var_3 ] , var_0 [ var_2 ] - var_2 += 1 - var_3 += 1 - elif var_0 [ var_3 ] == 1 : - var_3 += 1 - else : - var_0 [ var_6 ] , var_0 [ var_3 ] = var_0 [ var_3 ] , var_0 [ var_6 ] - var_6 -= 1 - return -",10,2 -386,020_Valid_Parentheses_2.py,"def isValid( s): - n = len(s) - if n == 0: - return True - - if n % 2 != 0: - return False - - while '()' in s or '{}' in s or '[]' in s: - s = s.replace('{}', '').replace('()', '').replace('[]', '') - - if s == '': - return True - else: - return False","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - if var_2 == 0 : - return True - if var_2 % 2 != 0 : - return False - while '()' in var_0 or '{}' in var_0 or '[]' in var_0 : - var_0 = var_0.replace ( '{}' , '' ).replace ( '()' , '' ).replace ( '[]' , '' ) - if var_0 == '' : - return True - else : - return False -",0[]()2{},6 -387,937_Reorder_Log_Files_2.py,"def reorderLogFiles( logs): - letter_logs = [] - digit_logs = [] - for log in logs: - if log.split(' ')[1].isnumeric(): - digit_logs.append(log) - else: - letter_logs.append(log) - return sorted(letter_logs, key=lambda x: x.split(' ')[1:] + x.split(' ')[0]) + digit_logs","def sample_funcname ( var_0 ) : - var_1 = [ ] - var_2 = [ ] - for var_3 in var_0 : - if var_3.split ( ' ' ) [ 1 ].isnumeric ( ) : - var_2.append ( var_3 ) - else : - var_1.append ( var_3 ) - return sorted ( var_1 , var_10 = lambda var_11 : var_11.split ( ' ' ) [ 1 : ] + var_11.split ( ' ' ) [ 0 ] ) + var_2 -",1 0,3 -388,422_Valid_Word_Square_2.py,"def validWordSquare( words): - return map(None, *words) == map(None, *map(None, *words))","def sample_funcname ( var_0 ) : - return map ( None , * var_0 ) == map ( None , * map ( None , * var_0 ) ) -",None,1 -389,090_Subsets_II_2.py,"def subsetsWithDup( nums): - nums.sort() - res = [[]] - begin = 0 - for index in range(len(nums)): - if index == 0 or nums[index] != nums[index - 1]: - begin = 0 - size = len(res) - for j in range(begin, size): - curr = list(res[j]) - curr.append(nums[index]) - res.append(curr) - begin = size - return res","def sample_funcname ( var_0 ) : - var_0.sort ( ) - var_2 = [ [ ] ] - var_4 = 0 - for var_7 in range ( len ( var_0 ) ) : - if var_7 == 0 or var_0 [ var_7 ] != var_0 [ var_7 - 1 ] : - var_4 = 0 - var_9 = len ( var_2 ) - for var_10 in range ( var_4 , var_9 ) : - var_12 = list ( var_2 [ var_10 ] ) - var_12.append ( var_0 [ var_7 ] ) - var_2.append ( var_12 ) - var_4 = var_9 - return var_2 -",10,2 -390,263_Ugly_Number_1.py,"def isUgly( num): - if num <= 0: - return False - if num <= 6: - return True - while num % 2 == 0: - num //= 2 - while num % 3 == 0: - num //= 3 - while num % 5 == 0: - num //= 5 - if num == 1: - return True - return False","def sample_funcname ( var_0 ) : - if var_0 <= 0 : - return False - if var_0 <= 6 : - return True - while var_0 % 2 == 0 : - var_0 //= 2 - while var_0 % 3 == 0 : - var_0 //= 3 - while var_0 % 5 == 0 : - var_0 //= 5 - if var_0 == 1 : - return True - return False -",506213,6 -391,249_Group_Shifted_Strings_1.py,"def hashCode( string): - if string is None or len(string) == 0: - return '' - if len(string) == 1: - return 'a' - step = abs(ord(string[0]) - ord('a')) - if step == 0: - return string - key = 'a' - for ch in string[1:]: - curr = ord(ch) - step - if ord(ch) - step < ord('a'): - curr += 26 - key += chr(curr) - return key","def sample_funcname ( var_0 ) : - if var_0 is None or len ( var_0 ) == 0 : - return '' - if len ( var_0 ) == 1 : - return 'a' - var_9 = abs ( ord ( var_0 [ 0 ] ) - ord ( 'a' ) ) - if var_9 == 0 : - return var_0 - var_10 = 'a' - for var_11 in var_0 [ 1 : ] : - var_12 = ord ( var_11 ) - var_9 - if ord ( var_11 ) - var_9 < ord ( 'a' ) : - var_12 += 26 - var_10 += chr ( var_12 ) - return var_10 -",0aNone126,6 -392,852_Peak_Index_in_a_Mountain_Array_2.py,"def peakIndexInMountainArray( A): - lo, hi = 0, len(A) - 1 - while lo < hi: - mid = (lo + hi) / 2 - if A[mid] < A[mid + 1]: - lo = mid + 1 - else: - hi = mid - return lo","def sample_funcname ( var_0 ) : - var_2 , var_5 = 0 , len ( var_0 ) - 1 - while var_2 < var_5 : - var_7 = ( var_2 + var_5 ) / 2 - if var_0 [ var_7 ] < var_0 [ var_7 + 1 ] : - var_2 = var_7 + 1 - else : - var_5 = var_7 - return var_2 -",102,3 -393,151_Reverse_Words_in_a_String_2.py,"def reverse( array_s, begin, end): - for i in range((end - begin) / 2): - array_s[begin + i], array_s[end - i - 1] = array_s[end - i - 1], array_s[begin + i]","def sample_funcname ( var_0 , var_1 , var_2 ) : - for var_5 in range ( ( var_2 - var_1 ) / 2 ) : - var_0 [ var_1 + var_5 ] , var_0 [ var_2 - var_5 - 1 ] = var_0 [ var_2 - var_5 - 1 ] , var_0 [ var_1 + var_5 ] -",12,2 -394,1323_Maximum_69_Number_1.py,"def maximum69Number ( num: int) -> int: - return(str(num).replace('6', '9', 1))","def sample_funcname ( var_0 : int ) -> int : - return ( str ( var_0 ).replace ( '6' , '9' , 1 ) ) -",196,3 -395,202_Happy_Number_1.py,"def isHappy( n): - seen_numbers = set() - while n > 1 and n not in seen_numbers: - seen_numbers.add(n) - n = sum(map(lambda x: int(x) * int(x), list(str(n)))) - return n == 1","def sample_funcname ( var_0 ) : - var_2 = set ( ) - while var_0 > 1 and var_0 not in var_2 : - var_2.add ( var_0 ) - var_0 = sum ( map ( lambda var_10 : int ( var_10 ) * int ( var_10 ) , list ( str ( var_0 ) ) ) ) - return var_0 == 1 -",1,1 -396,234_Palindrome_Linked_List_1.py,"def isPalindrome( head): - if head is None: - return True - p1, p2 = head, head - p3, pre = p1.next, p1 - while p2.next is not None and p2.next.next is not None: - p2 = p2.next.next - pre = p1 - p1 = p3 - p3 = p3.next - p1.next = pre - if p2.next is None: - p1 = p1.next - - while p3 is not None: - if p1.val != p3.val: - return False - p1 = p1.next - p3 = p3.next - return True","def sample_funcname ( var_0 ) : - if var_0 is None : - return True - var_3 , var_4 = var_0 , var_0 - var_6 , var_7 = var_3.next , var_3 - while var_4.next is not None and var_4.next.next is not None : - var_4 = var_4.next.next - var_7 = var_3 - var_3 = var_6 - var_6 = var_6.next - var_3.next = var_7 - if var_4.next is None : - var_3 = var_3.next - while var_6 is not None : - if var_3.val != var_6.val : - return False - var_3 = var_3.next - var_6 = var_6.next - return True -",None,1 -397,414_Third_Maximum_Number_1.py,"def thirdMax( nums): - import Queue - pq = Queue.PriorityQueue(4) - check = set() - for n in nums: - if n in check: - continue - pq.put(n) - check.add(n) - if len(check) > 3: - check.remove(pq.get()) - total = len(check) - while total < 3 and total > 1: - total -= 1 - return pq.get()","def sample_funcname ( var_0 ) : - import var_1 - var_4 = var_1.PriorityQueue ( 4 ) - var_6 = set ( ) - for var_7 in var_0 : - if var_7 in var_6 : - continue - var_4.put ( var_7 ) - var_6.add ( var_7 ) - if len ( var_6 ) > 3 : - var_6.remove ( var_4.get ( ) ) - var_14 = len ( var_6 ) - while var_14 < 3 and var_14 > 1 : - var_14 -= 1 - return var_4.get ( ) -",314,3 -398,152_1.py,"def maxProduct( nums): - if not nums: - return 0 - - max_so_far, min_so_far, result = nums[0], nums[0], nums[0] - - for index in range(1, len(nums)): - if nums[index] > 0: - max_so_far = max(max_so_far*nums[index], nums[index]) - min_so_far = min(min_so_far*nums[index], nums[index]) - else: - temp = max_so_far - max_so_far = max(min_so_far*nums[index], nums[index]) - min_so_far = min(temp*nums[index], nums[index]) - - result = max(result, max_so_far) - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_2 , var_3 , var_4 = var_0 [ 0 ] , var_0 [ 0 ] , var_0 [ 0 ] - for var_8 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_8 ] > 0 : - var_2 = max ( var_2 * var_0 [ var_8 ] , var_0 [ var_8 ] ) - var_3 = min ( var_3 * var_0 [ var_8 ] , var_0 [ var_8 ] ) - else : - var_11 = var_2 - var_2 = max ( var_3 * var_0 [ var_8 ] , var_0 [ var_8 ] ) - var_3 = min ( var_11 * var_0 [ var_8 ] , var_0 [ var_8 ] ) - var_4 = max ( var_4 , var_2 ) - return var_4 -",10,2 -399,05_2.py,"def expand(s, left, right): - while left >= 0 and right < len(s) and s[left] == s[right]: - left -= 1 - right += 1 - return right-left-1","def sample_funcname ( var_0 , var_1 , var_2 ) : - while var_1 >= 0 and var_2 < len ( var_0 ) and var_0 [ var_1 ] == var_0 [ var_2 ] : - var_1 -= 1 - var_2 += 1 - return var_2 - var_1 - 1 -",10,2 -400,1022_1.py,"def traversal(root, paths, pathlen, allpaths): - if not root: - return - if len(paths) > pathlen: - paths[pathlen] = root.val - else: - paths.append(root.val) - - pathlen +=1 - if not root.left and not root.right: - allpaths.append(int(''.join(str(val) for val in paths[0:pathlen]), 2)) - else: - traversal(root.left, paths, pathlen, allpaths) - traversal(root.right, paths, pathlen, allpaths)","def sample_funcname ( var_1 , var_2 , var_3 , var_4 ) : - if not var_1 : - return - if len ( var_2 ) > var_3 : - var_2 [ var_3 ] = var_1.val - else : - var_2.append ( var_1.val ) - var_3 += 1 - if not var_1.left and not var_1.right : - var_4.append ( int ( ''.join ( str ( val ) for val in var_2 [ 0 : var_3 ] ) , 2 ) ) - else : - var_0 ( var_1.left , var_2 , var_3 , var_4 ) - var_0 ( var_1.right , var_2 , var_3 , var_4 ) -",102,4 -401,410_1.py,"def splitArray( nums, m): - left, right = max(nums), sum(nums) - - while left < right: - mid = left + ((right-left) >> 1) - curr_sum, invalid, groups = 0, True, 0 - for num in nums: - if num > mid: - inalid = False - break - if num + curr_sum > mid: - groups += 1 - curr_sum = 0 - curr_sum += num - if invalid and groups < m: - right = mid - else: - left = mid + 1 - return left","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_5 = max ( var_0 ) , sum ( var_0 ) - while var_3 < var_5 : - var_7 = var_3 + ( ( var_5 - var_3 ) >> 1 ) - var_9 , var_11 , var_12 = 0 , True , 0 - for var_13 in var_0 : - if var_13 > var_7 : - var_15 = False - break - if var_13 + var_9 > var_7 : - var_12 += 1 - var_9 = 0 - var_9 += var_13 - if var_11 and var_12 < var_1 : - var_5 = var_7 - else : - var_3 = var_7 + 1 - return var_3 -",10,2 -402,113_1.py,"def dfs(root, curr_sum, sum, path, result): - if not root: - return - - curr_sum += root.val - if curr_sum == sum and not root.left and not root.right: - result.append(path + [root.val]) - return - - if root.left: - dfs(root.left, curr_sum, sum, path + [root.val], result) - if root.right: - dfs(root.right, curr_sum, sum, path + [root.val], result)","def sample_funcname ( var_1 , var_2 , var_3 , var_4 , var_5 ) : - if not var_1 : - return - var_2 += var_1.val - if var_2 == var_3 and not var_1.left and not var_1.right : - var_5.append ( var_4 + [ var_1.val ] ) - return - if var_1.left : - var_0 ( var_1.left , var_2 , var_3 , var_4 + [ var_1.val ] , var_5 ) - if var_1.right : - var_0 ( var_1.right , var_2 , var_3 , var_4 + [ var_1.val ] , var_5 ) -",,0 -403,328_1.py,"def oddEvenList( head): - if not head: - return None - - odd, even = head, head.next - evenHead = even - while even and even.next: - odd.next = even.next - odd = odd.next - even.next = odd.next - even = even.next - - odd.next = evenHead - return head","def sample_funcname ( var_0 ) : - if not var_0 : - return None - var_2 , var_4 = var_0 , var_0.next - var_5 = var_4 - while var_4 and var_4.next : - var_2.next = var_4.next - var_2 = var_2.next - var_4.next = var_2.next - var_4 = var_4.next - var_2.next = var_5 - return var_0 -",None,1 -404,144_1.py,"def preorderTraversal( root): - if not root: - return [] - - stack, result = [root], [] - while stack: - element = stack.pop() - result.append(element.val) - - if element.right: - stack.append(element.right) - if element.left: - stack.append(element.left) - - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - var_1 , var_2 = [ var_0 ] , [ ] - while var_1 : - var_4 = var_1.pop ( ) - var_2.append ( var_4.val ) - if var_4.right : - var_1.append ( var_4.right ) - if var_4.left : - var_1.append ( var_4.left ) - return var_2 -",,0 -405,1191_2.py,"def prefix(arr): - curr_sum, max_val = 0, float('-inf') - for index, val in enumerate(arr): - curr_sum += val - max_val = max(max_val, curr_sum) - return max_val","def sample_funcname ( var_0 ) : - var_2 , var_5 = 0 , float ( '-inf' ) - for var_7 , var_8 in enumerate ( var_0 ) : - var_2 += var_8 - var_5 = max ( var_5 , var_2 ) - return var_5 -",0-inf,2 -406,67_1.py,"def addBinary( a, b): - result = """" - - carry = 0 - index_a, index_b = len(a)-1, len(b)-1 - while index_a >= 0 and index_b >= 0: - result = (int(a[index_a]) + int(b[index_b]) + carry)%2 + result - carry = (int(a[index_a]) + int(b[index_b]) + carry)%2 - index_a -= 1 - index_b -= 1 - - if index_a >= 0: - while index_a >= 0: - result = (int(a[index_a]) + carry)%2 + result - carry = (int(a[index_a]) + carry)%2 - index_a -= 1 - elif index_b >= 0: - while index_b >= 0: - result = (int(b[index_b]) + carry)%2 + result - carry = (int(b[index_b]) + carry)%2 - index_b -= 1 - else: - if carry == 1: - result = str(carry) + result - return result","def sample_funcname ( var_0 , var_1 ) : - var_3 = """" - var_5 = 0 - var_8 , var_9 = len ( var_0 ) - 1 , len ( var_1 ) - 1 - while var_8 >= 0 and var_9 >= 0 : - var_3 = ( int ( var_0 [ var_8 ] ) + int ( var_1 [ var_9 ] ) + var_5 ) % 2 + var_3 - var_5 = ( int ( var_0 [ var_8 ] ) + int ( var_1 [ var_9 ] ) + var_5 ) % 2 - var_8 -= 1 - var_9 -= 1 - if var_8 >= 0 : - while var_8 >= 0 : - var_3 = ( int ( var_0 [ var_8 ] ) + var_5 ) % 2 + var_3 - var_5 = ( int ( var_0 [ var_8 ] ) + var_5 ) % 2 - var_8 -= 1 - elif var_9 >= 0 : - while var_9 >= 0 : - var_3 = ( int ( var_1 [ var_9 ] ) + var_5 ) % 2 + var_3 - var_5 = ( int ( var_1 [ var_9 ] ) + var_5 ) % 2 - var_9 -= 1 - else : - if var_5 == 1 : - var_3 = str ( var_5 ) + var_3 - return var_3 -",102,4 -407,1018_1.py,"def prefixesDivBy5( A): - result = [] - if not A: - return [] - str_bin = '' - for val in A: - str_bin += str(val) - if(int(str_bin, 2)%5 == 0): - result.append(True) - else: - result.append(False) - return result","def sample_funcname ( var_0 ) : - var_1 = [ ] - if not var_0 : - return [ ] - var_3 = '' - for var_4 in var_0 : - var_3 += str ( var_4 ) - if ( int ( var_3 , 2 ) % 5 == 0 ) : - var_1.append ( True ) - else : - var_1.append ( False ) - return var_1 -",502,4 -408,30_1.py,"def findSubstring( s, words): - if not str or not words: - return [] - - counts = {} - for word in words: - if word in counts: - counts[word] += 1 - else: - counts[word] = 1 - - result = [] - n, numOfWords, fixLen = len(s), len(words),len(words[0]) - - for index in range(0, n-numOfWords*fixLen+1): - seen = {} - - index_j = 0 - while index_j < numOfWords: - word = s[index + index_j*fixLen: index + (index_j+1)*fixLen] - if word in counts: - if word in seen: - seen[word] += 1 - else: - seen[word] = 1 - - if seen[word] > counts[word]: - break - else: - break - index_j += 1 - - if index_j == numOfWords: - result.append(index) - - return","def sample_funcname ( var_0 , var_1 ) : - if not str or not var_1 : - return [ ] - var_3 = { } - for var_4 in var_1 : - if var_4 in var_3 : - var_3 [ var_4 ] += 1 - else : - var_3 [ var_4 ] = 1 - var_6 = [ ] - var_8 , var_9 , var_11 = len ( var_0 ) , len ( var_1 ) , len ( var_1 [ 0 ] ) - for var_13 in range ( 0 , var_8 - var_9 * var_11 + 1 ) : - var_14 = { } - var_15 = 0 - while var_15 < var_9 : - var_4 = var_0 [ var_13 + var_15 * var_11 : var_13 + ( var_15 + 1 ) * var_11 ] - if var_4 in var_3 : - if var_4 in var_14 : - var_14 [ var_4 ] += 1 - else : - var_14 [ var_4 ] = 1 - if var_14 [ var_4 ] > var_3 [ var_4 ] : - break - else : - break - var_15 += 1 - if var_15 == var_9 : - var_6.append ( var_13 ) - return -",10,2 -409,191_1.py,"def hammingWeight( n): - bits = 0 - mask = 1 - - for i in range(32): - if (n&mask) != 0: - bits +=1 - mask <<= 1 - - return bits","def sample_funcname ( var_0 ) : - var_2 = 0 - var_4 = 1 - for var_7 in range ( 32 ) : - if ( var_0 & var_4 ) != 0 : - var_2 += 1 - var_4 <<= 1 - return var_2 -",1032,3 -410,26_1.py,"def removeDuplicates( nums): - if not nums: - return 0 - - index_i = 0 - - for index_j in range(1, len(nums)): - if nums[index_i] != nums[index_j]: - index_i += 1 - nums[index_i] = nums[index_j] - - return index_i + 1","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_2 = 0 - for var_6 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_2 ] != var_0 [ var_6 ] : - var_2 += 1 - var_0 [ var_2 ] = var_0 [ var_6 ] - return var_2 + 1 -",10,2 -411,129_1.py,"def dfs(root, num, total): - if not root: - return total - num = num*10 + root.val - if not root.left and not root.right: - total += num - return total - - return dfs(root.left, num) + dfs(root.right, num)","def sample_funcname ( var_1 , var_2 , var_3 ) : - if not var_1 : - return var_3 - var_2 = var_2 * 10 + var_1.val - if not var_1.left and not var_1.right : - var_3 += var_2 - return var_3 - return var_0 ( var_1.left , var_2 ) + var_0 ( var_1.right , var_2 ) -",10,1 -413,06_1.py,"def convert( s, numRows): - if numRows == 1: - return s - - result = ["""" for _ in range(numRows)] - row, down = 0, 1 - for char in s: - result[row] += char - - if row == numRows - 1: - down = 0 - if row == 0: - down = 1 - - if down: - row += 1 - else: - row -= 1 - final_string = """" - for value in result: - final_string += value - return final_string","def sample_funcname ( var_0 , var_1 ) : - if var_1 == 1 : - return var_0 - var_6 = [ """" for var_4 in range ( var_1 ) ] - var_8 , var_9 = 0 , 1 - for var_10 in var_0 : - var_6 [ var_8 ] += var_10 - if var_8 == var_1 - 1 : - var_9 = 0 - if var_8 == 0 : - var_9 = 1 - if var_9 : - var_8 += 1 - else : - var_8 -= 1 - var_11 = """" - for var_12 in var_6 : - var_11 += var_12 - return var_11 -",10,3 -414,1184_1.py,"def distanceBetweenBusStops( distance, start, destination): - start, destination = min(start, destination), max(start, destination) - clock_dist = sum(distance[start:destination]) - anti_clock_dist = sum(distance[:start]) + sum(distance[destination:]) - return min(clock_dist, anti_clock_dist)","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_1 , var_2 = min ( var_1 , var_2 ) , max ( var_1 , var_2 ) - var_6 = sum ( var_0 [ var_1 : var_2 ] ) - var_7 = sum ( var_0 [ : var_1 ] ) + sum ( var_0 [ var_2 : ] ) - return min ( var_6 , var_7 ) -",,0 -415,1079_1.py,"def numTilePossibilities( tiles): - if not tiles: - return 0 - - import collections - unique = set(tiles) - freq_map = collections.Counter(tiles) - total_len = 1 - while total_len < len(tiles): - new = set() - for char in tiles: - for comb in unique: - new_seq = comb+char - up_freq = collections.Counter(new_seq) - flag =True - for key, val in up_freq.items(): - if val > freq_map[key]: - flag = False - if flag: - new.add(new_seq) - unique.update(new) - - total_len += 1 - return len(unique)","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - import var_2 - var_4 = set ( var_0 ) - var_6 = var_2.Counter ( var_0 ) - var_8 = 1 - while var_8 < len ( var_0 ) : - var_10 = set ( ) - for var_11 in var_0 : - for var_12 in var_4 : - var_13 = var_12 + var_11 - var_14 = var_2.Counter ( var_13 ) - var_16 = True - for var_18 , var_19 in var_14.items ( ) : - if var_19 > var_6 [ var_18 ] : - var_16 = False - if var_16 : - var_10.add ( var_13 ) - var_4.update ( var_10 ) - var_8 += 1 - return len ( var_4 ) -",10,2 -416,1080_1.py,"def reduce_tree(root, limit, curr_sum): - if not root: - return None - - l_sum = [curr_sum[0] + root.val] - r_sum = [l_sum[0]] - - root.left = reduce_tree(root.left, limit, l_sum) - root.right = reduce_tree(root.right, limit, r_sum) - - curr_sum[0] = max(l_sum[0], r_sum[0]) - if curr_sum[0] < limit: - root = None - return root","def sample_funcname ( var_1 , var_2 , var_3 ) : - if not var_1 : - return None - var_7 = [ var_3 [ 0 ] + var_1.val ] - var_8 = [ var_7 [ 0 ] ] - var_1.left = var_0 ( var_1.left , var_2 , var_7 ) - var_1.right = var_0 ( var_1.right , var_2 , var_8 ) - var_3 [ 0 ] = max ( var_7 [ 0 ] , var_8 [ 0 ] ) - if var_3 [ 0 ] < var_2 : - var_1 = None - return var_1 -",0None,2 -417,1043_1.py,"def maxSumAfterPartitioning( A, K): - if not A: - return 0 - - N = len(A) - dp = [0]*(N+1) - for index_i in range(N): - maxi = 0 - for index_j in range(index_i, index_i-K, -1): - if index_j >= 0 and index_j < len(A): - maxi = max(maxi, A[index_j]) - - dp[index_i+1] = max(dp[index_i+1], maxi*(index_i-index_j+1)+dp[index_j]) - - return dp[-1]","def sample_funcname ( var_0 , var_1 ) : - if not var_0 : - return 0 - var_4 = len ( var_0 ) - var_6 = [ 0 ] * ( var_4 + 1 ) - for var_8 in range ( var_4 ) : - var_9 = 0 - for var_10 in range ( var_8 , var_8 - var_1 , - 1 ) : - if var_10 >= 0 and var_10 < len ( var_0 ) : - var_9 = max ( var_9 , var_0 [ var_10 ] ) - var_6 [ var_8 + 1 ] = max ( var_6 [ var_8 + 1 ] , var_9 * ( var_8 - var_10 + 1 ) + var_6 [ var_10 ] ) - return var_6 [ - 1 ] -",10,2 -418,830_1.py,"def largeGroupPositions( S): - if not S: - return [] - - result = [] - count = 1 - prevChar = S[0] - index_i = 0 - for index in range(1,len(S)): - if S[index] == prevChar: - count += 1 - else: - if count >= 3: - result.append([index_i, index-1]) - - count = 1 - prevChar = S[index] - index_i = index - - if count >= 3: - result.append([index_i, len(S)-1]) - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - var_1 = [ ] - var_3 = 1 - var_5 = var_0 [ 0 ] - var_6 = 0 - for var_9 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_9 ] == var_5 : - var_3 += 1 - else : - if var_3 >= 3 : - var_1.append ( [ var_6 , var_9 - 1 ] ) - var_3 = 1 - var_5 = var_0 [ var_9 ] - var_6 = var_9 - if var_3 >= 3 : - var_1.append ( [ var_6 , len ( var_0 ) - 1 ] ) - return var_1 -",310,3 -419,1014_1.py,"def maxScoreSightseeingPair( A): - prev_best, result = 0, 0 - for index in range(0, len(A)): - result = max(result, A[index]-index+prev_best) - prev_best = max(prev_best, A[index]+index) - return result","def sample_funcname ( var_0 ) : - var_2 , var_3 = 0 , 0 - for var_6 in range ( 0 , len ( var_0 ) ) : - var_3 = max ( var_3 , var_0 [ var_6 ] - var_6 + var_2 ) - var_2 = max ( var_2 , var_0 [ var_6 ] + var_6 ) - return var_3 -",0,1 -420,33_2.py,"def searchRecursive(nums, left, right, target): - if left > right: - return -1 - - mid = (left + right) / 2 - if nums[mid] == target: - return mid - - if nums[left] <= nums[mid]: - if nums[left] <= target < nums[mid]: - return searchRecursive(nums, left, mid-1, target) - else: - return searchRecursive(nums, mid+1, right, target) - else: - if nums[mid] < target <= nums[right]: - return searchRecursive(nums, mid+1, right, target) - else: - return searchRecursive(nums, left, mid-1, target)","def sample_funcname ( var_1 , var_2 , var_3 , var_4 ) : - if var_2 > var_3 : - return - 1 - var_7 = ( var_2 + var_3 ) / 2 - if var_1 [ var_7 ] == var_4 : - return var_7 - if var_1 [ var_2 ] <= var_1 [ var_7 ] : - if var_1 [ var_2 ] <= var_4 < var_1 [ var_7 ] : - return var_0 ( var_1 , var_2 , var_7 - 1 , var_4 ) - else : - return var_0 ( var_1 , var_7 + 1 , var_3 , var_4 ) - else : - if var_1 [ var_7 ] < var_4 <= var_1 [ var_3 ] : - return var_0 ( var_1 , var_7 + 1 , var_3 , var_4 ) - else : - return var_0 ( var_1 , var_2 , var_7 - 1 , var_4 ) -",12,2 -421,1002_1.py,"def commonChars( A): - char_map = {} - for char in A[0]: - if char in char_map: - char_map[char] += 1 - else: - char_map[char] = 1 - - int_map = {} - for index in range(1, len(A)): - for char in char_map.keys(): - if char in A[index]: - char_count = min(A[index].count(char), char_map[char]) - char_map[char] = char_count - else: - del char_map[char] - - result = [] - for key, value in char_map.items(): - result.extend([key]*value) - - return result","def sample_funcname ( var_0 ) : - var_1 = { } - for var_3 in var_0 [ 0 ] : - if var_3 in var_1 : - var_1 [ var_3 ] += 1 - else : - var_1 [ var_3 ] = 1 - var_5 = { } - for var_8 in range ( 1 , len ( var_0 ) ) : - for var_3 in var_1.keys ( ) : - if var_3 in var_0 [ var_8 ] : - var_12 = min ( var_0 [ var_8 ].count ( var_3 ) , var_1 [ var_3 ] ) - var_1 [ var_3 ] = var_12 - else : - del var_1 [ var_3 ] - var_13 = [ ] - for var_15 , var_16 in var_1.items ( ) : - var_13.extend ( [ var_15 ] * var_16 ) - return var_13 -",10,2 -422,1281_1.py,"def subtractProductAndSum( n): - from functools import reduce - from operator import mul - digits = [int(x) for x in str(n)] - return reduce(mul, digits) - sum(digits)","def sample_funcname ( var_0 ) : - from var_1 import var_2 - from var_3 import var_4 - var_8 = [ int ( var_6 ) for var_6 in str ( var_0 ) ] - return var_2 ( var_4 , var_8 ) - sum ( var_8 ) -",,0 -423,125_1.py,"def numDistinct( s, t): - row, col = len(s), len(t) - - if col > row: - return 0 - - dp = [[0 for _ in range(col+1)] for _ in range(row+1)] - - for r in range(row+1): - for c in range(col+1): - if r == 0 and c == 0: - dp[r][c] = 1 - elif r == 0: - dp[r][c] = 0 - elif c == 0: - dp[r][c] = 1 - else: - dp[r][c] = dp[r-1][c] - if s[r-1] == t[c-1]: - dp[r][c] += dp[r-1][c-1] - return dp[row][col]","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = len ( var_0 ) , len ( var_1 ) - if var_4 > var_3 : - return 0 - var_9 = [ [ 0 for var_6 in range ( var_4 + 1 ) ] for var_6 in range ( var_3 + 1 ) ] - for var_10 in range ( var_3 + 1 ) : - for var_11 in range ( var_4 + 1 ) : - if var_10 == 0 and var_11 == 0 : - var_9 [ var_10 ] [ var_11 ] = 1 - elif var_10 == 0 : - var_9 [ var_10 ] [ var_11 ] = 0 - elif var_11 == 0 : - var_9 [ var_10 ] [ var_11 ] = 1 - else : - var_9 [ var_10 ] [ var_11 ] = var_9 [ var_10 - 1 ] [ var_11 ] - if var_0 [ var_10 - 1 ] == var_1 [ var_11 - 1 ] : - var_9 [ var_10 ] [ var_11 ] += var_9 [ var_10 - 1 ] [ var_11 - 1 ] - return var_9 [ var_3 ] [ var_4 ] -",10,2 -424,1003_1.py,"def isValid( S): - stack = [] - if not S: - return False - - for char in S: - if char == 'a': - stack.append('a') - if char == 'b': - if not stack: - return False - if stack[-1] == 'a': - stack.pop() - stack.append(char) - if char == 'c': - if not stack: - return False - if stack[-1] == 'b': - stack.pop() - return len(stack) == 0","def sample_funcname ( var_0 ) : - var_1 = [ ] - if not var_0 : - return False - for var_3 in var_0 : - if var_3 == 'a' : - var_1.append ( 'a' ) - if var_3 == 'b' : - if not var_1 : - return False - if var_1 [ - 1 ] == 'a' : - var_1.pop ( ) - var_1.append ( var_3 ) - if var_3 == 'c' : - if not var_1 : - return False - if var_1 [ - 1 ] == 'b' : - var_1.pop ( ) - return len ( var_1 ) == 0 -",b0ac1,5 -425,1296_1.py,"def isPossibleDivide( nums, k): - from collections import Counter - count_map = Counter(nums) - for num in sorted(count_map.keys()): - if count_map[num] <= 0: - continue - for index in range(1, k): - count_map[num+index] -= count_map[num] - if count_map[num+index] < 0: - return False - return True","def sample_funcname ( var_0 , var_1 ) : - from var_2 import var_3 - var_4 = var_3 ( var_0 ) - for var_7 in sorted ( var_4.keys ( ) ) : - if var_4 [ var_7 ] <= 0 : - continue - for var_11 in range ( 1 , var_1 ) : - var_4 [ var_7 + var_11 ] -= var_4 [ var_7 ] - if var_4 [ var_7 + var_11 ] < 0 : - return False - return True -",10,2 -426,1015_1.py,"def smallestRepunitDivByK( K): - length, value = 0, 0 - for no_one in range(100000): - value = (10*value + 1)%K - length += 1 - if value == 0: - return length - return -1","def sample_funcname ( var_0 ) : - var_2 , var_3 = 0 , 0 - for var_6 in range ( 100000 ) : - var_3 = ( 10 * var_3 + 1 ) % var_0 - var_2 += 1 - if var_3 == 0 : - return var_2 - return - 1 -",1001000001,4 -427,85_1.py,"def largestRectangleArea( heights): - if not heights: - return 0 - - stack = [] - result, index = 0, 0 - - while index < len(heights): - if not stack or heights[index] >= heights[stack[-1]]: - stack.append(index) - index += 1 - else: - curr = stack.pop() - if not stack: - area = heights[curr]*index - else: - area = heights[curr] * (index-stack[-1]-1) - result = max(result, area) - - while stack: - curr = stack.pop() - if not stack: - area = heights[curr]*index - else: - area = heights[curr] * (index-stack[-1]-1) - result = max(result, area) - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_2 = [ ] - var_3 , var_4 = 0 , 0 - while var_4 < len ( var_0 ) : - if not var_2 or var_0 [ var_4 ] >= var_0 [ var_2 [ - 1 ] ] : - var_2.append ( var_4 ) - var_4 += 1 - else : - var_9 = var_2.pop ( ) - if not var_2 : - var_10 = var_0 [ var_9 ] * var_4 - else : - var_10 = var_0 [ var_9 ] * ( var_4 - var_2 [ - 1 ] - 1 ) - var_3 = max ( var_3 , var_10 ) - while var_2 : - var_9 = var_2.pop ( ) - if not var_2 : - var_10 = var_0 [ var_9 ] * var_4 - else : - var_10 = var_0 [ var_9 ] * ( var_4 - var_2 [ - 1 ] - 1 ) - var_3 = max ( var_3 , var_10 ) - return var_3 -",10,2 -428,1042_1.py,"def gardenNoAdj( N, paths): - plant = [1, 2, 3, 4] - result = [0 for _ in range(N)] - if not paths: - return [plant[index%4] for index in range(N)] - change = {} - update = [] - for path in paths: - x, y = path[0]-1, path[1]-1 - - if x in change: - change[x].append(y) - else: - change[x] = [y] - - if y in change: - change[y].append(x) - else: - change[y] = [x] - - for garden in range(N): - color_used = [] - if garden in change: - subgarden = change[garden] - for subgarden in change[garden]: - if result[subgarden]: - color_used.append(result[subgarden]) - color_rem = list(set([1, 2, 3, 4]) - set(color_used)) - for color in color_rem: - result[garden] = color - break - return result","def sample_funcname ( var_0 , var_1 ) : - var_6 = [ 1 , 2 , 3 , 4 ] - var_10 = [ 0 for var_8 in range ( var_0 ) ] - if not var_1 : - return [ var_6 [ var_11 % 4 ] for var_11 in range ( var_0 ) ] - var_12 = { } - var_13 = [ ] - for var_14 in var_1 : - var_15 , var_16 = var_14 [ 0 ] - 1 , var_14 [ 1 ] - 1 - if var_15 in var_12 : - var_12 [ var_15 ].append ( var_16 ) - else : - var_12 [ var_15 ] = [ var_16 ] - if var_16 in var_12 : - var_12 [ var_16 ].append ( var_15 ) - else : - var_12 [ var_16 ] = [ var_15 ] - for var_18 in range ( var_0 ) : - var_19 = [ ] - if var_18 in var_12 : - var_20 = var_12 [ var_18 ] - for var_20 in var_12 [ var_18 ] : - if var_10 [ var_20 ] : - var_19.append ( var_10 [ var_20 ] ) - var_23 = list ( set ( [ 1 , 2 , 3 , 4 ] ) - set ( var_19 ) ) - for var_24 in var_23 : - var_10 [ var_18 ] = var_24 - break - return var_10 -",02134,5 -429,132_1.py,"def minCut( s): - if not s: - return 0 - - P = [[False for _ in range(len(s))] for _ in range(len(s))] - cuts = [0 for _ in range(len(s))] - - for index in range(len(s)): - P[index][index] = True - - for length in range(2, len(s)+1): - for i in range(len(s)-length+1): - j = i+length - 1 - - if length == 2: - P[i][j] = s[i] == s[j] - else: - P[i][j] = (s[i] == s[j]) and P[i+1][j-1] - - for index in range(len(s)): - if P[0][index]: - cuts[index] = 0 - else: - cuts[index] = float('inf') - for j in range(index): - if P[j+1][index] and (cuts[index] > 1 + cuts[j]): - cuts[index] = 1+cuts[j] - - return cuts[len(s)-1]","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_6 = [ [ False for var_3 in range ( len ( var_0 ) ) ] for var_3 in range ( len ( var_0 ) ) ] - var_7 = [ 0 for var_3 in range ( len ( var_0 ) ) ] - for var_8 in range ( len ( var_0 ) ) : - var_6 [ var_8 ] [ var_8 ] = True - for var_12 in range ( 2 , len ( var_0 ) + 1 ) : - for var_13 in range ( len ( var_0 ) - var_12 + 1 ) : - var_14 = var_13 + var_12 - 1 - if var_12 == 2 : - var_6 [ var_13 ] [ var_14 ] = var_0 [ var_13 ] == var_0 [ var_14 ] - else : - var_6 [ var_13 ] [ var_14 ] = ( var_0 [ var_13 ] == var_0 [ var_14 ] ) and var_6 [ var_13 + 1 ] [ var_14 - 1 ] - for var_8 in range ( len ( var_0 ) ) : - if var_6 [ 0 ] [ var_8 ] : - var_7 [ var_8 ] = 0 - else : - var_7 [ var_8 ] = float ( 'inf' ) - for var_14 in range ( var_8 ) : - if var_6 [ var_14 + 1 ] [ var_8 ] and ( var_7 [ var_8 ] > 1 + var_7 [ var_14 ] ) : - var_7 [ var_8 ] = 1 + var_7 [ var_14 ] - return var_7 [ len ( var_0 ) - 1 ] -",10inf2,4 -431,11_1.py,"def maxArea( height): - left, right, maxArea = 0, len(height) - 1, 0 - - while left < right: - maxArea = max(maxArea, min(height[left], height[right])*(right-left)) - if height[left] < height[right]: - left += 1 - else: - right -= 1 - - return maxArea","def sample_funcname ( var_0 ) : - var_2 , var_5 , var_6 = 0 , len ( var_0 ) - 1 , 0 - while var_2 < var_5 : - var_6 = max ( var_6 , min ( var_0 [ var_2 ] , var_0 [ var_5 ] ) * ( var_5 - var_2 ) ) - if var_0 [ var_2 ] < var_0 [ var_5 ] : - var_2 += 1 - else : - var_5 -= 1 - return var_6 -",10,2 -432,1039_1.py,"def minScoreTriangulation( A): - n = len(A) - dp = [[0]*n for _ in range(n)] - for length in range(n): - index_i = 0 - for index_j in range(length, n): - if index_j < index_i+2: - dp[index_i][index_j] = 0 - else: - dp[index_i][index_j] = float('inf') - for index_k in range(index_i+1, index_j): - val = dp[index_i][index_k] + dp[index_k][index_j] + (A[index_i]*A[index_k]*A[index_j]) - dp[index_i][index_j] = min(dp[index_i][index_j], val) - index_i += 1 - return dp[0][n-1]","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_6 = [ [ 0 ] * var_2 for var_4 in range ( var_2 ) ] - for var_7 in range ( var_2 ) : - var_8 = 0 - for var_9 in range ( var_7 , var_2 ) : - if var_9 < var_8 + 2 : - var_6 [ var_8 ] [ var_9 ] = 0 - else : - var_6 [ var_8 ] [ var_9 ] = float ( 'inf' ) - for var_14 in range ( var_8 + 1 , var_9 ) : - var_15 = var_6 [ var_8 ] [ var_14 ] + var_6 [ var_14 ] [ var_9 ] + ( var_0 [ var_8 ] * var_0 [ var_14 ] * var_0 [ var_9 ] ) - var_6 [ var_8 ] [ var_9 ] = min ( var_6 [ var_8 ] [ var_9 ] , var_15 ) - var_8 += 1 - return var_6 [ 0 ] [ var_2 - 1 ] -",10inf2,4 -433,1081_1.py,"def smallestSubsequence( text): - if not text: - return '' - import collections - freq_map = collections.Counter(text) - used = [False]*26 - result = '' - - for char in text: - freq_map[char] -= 1 - if used[ord(char)-97]: - continue - while (result and result[-1] > char and freq_map[result[-1]] > 0): - used[ord(result[-1])-97] = False - result = result[:-1] - - used[ord(char)-97] = True - result += char - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return '' - import var_2 - var_4 = var_2.Counter ( var_0 ) - var_7 = [ False ] * 26 - var_8 = '' - for var_9 in var_0 : - var_4 [ var_9 ] -= 1 - if var_7 [ ord ( var_9 ) - 97 ] : - continue - while ( var_8 and var_8 [ - 1 ] > var_9 and var_4 [ var_8 [ - 1 ] ] > 0 ) : - var_7 [ ord ( var_8 [ - 1 ] ) - 97 ] = False - var_8 = var_8 [ : - 1 ] - var_7 [ ord ( var_9 ) - 97 ] = True - var_8 += var_9 - return var_8 -",097126,5 -434,1078_1.py,"def findOcurrences( text, first, second): - result = [] - if not text: - return [] - splitted_text = text.split(' ') - indi = 0 - for index in range(len(splitted_text)-1): - if splitted_text[index] == first and splitted_text[index+1] == second: - index = index+2 - if index < len(splitted_text): - result.append(splitted_text[index]) - return result","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_3 = [ ] - if not var_0 : - return [ ] - var_6 = var_0.split ( ' ' ) - var_8 = 0 - for var_12 in range ( len ( var_6 ) - 1 ) : - if var_6 [ var_12 ] == var_1 and var_6 [ var_12 + 1 ] == var_2 : - var_12 = var_12 + 2 - if var_12 < len ( var_6 ) : - var_3.append ( var_6 [ var_12 ] ) - return var_3 -",10 2,4 -436,128_1.py,"def longestConsecutive( nums): - result = 0 - nums = set(nums) - - for num in nums: - if num-1 not in nums: - curr = num - length = 1 - - while curr+1 in nums: - curr += 1 - length += 1 - result = max(result, length) - return result","def sample_funcname ( var_0 ) : - var_2 = 0 - var_0 = set ( var_0 ) - for var_4 in var_0 : - if var_4 - 1 not in var_0 : - var_6 = var_4 - var_7 = 1 - while var_6 + 1 in var_0 : - var_6 += 1 - var_7 += 1 - var_2 = max ( var_2 , var_7 ) - return var_2 -",10,2 -437,70_1.py,"def climbStairs( n): - if n == 0: - return 0 - - dp = [0]*n - dp[0], dp[1] = 1, 2 - - for index in range(2, n): - dp[index] = dp[index-1] + dp[index-2] - return dp[n-1]","def sample_funcname ( var_0 ) : - if var_0 == 0 : - return 0 - var_2 = [ 0 ] * var_0 - var_2 [ 0 ] , var_2 [ 1 ] = 1 , 2 - for var_6 in range ( 2 , var_0 ) : - var_2 [ var_6 ] = var_2 [ var_6 - 1 ] + var_2 [ var_6 - 2 ] - return var_2 [ var_0 - 1 ] -",102,3 -438,190_1.py,"def reverseBits( n): - res = 0 - for i in range(32): - res += n & 1 - n = n >> 1 - if i != 31: - res = res << 1 - return res","def sample_funcname ( var_0 ) : - var_2 = 0 - for var_5 in range ( 32 ) : - var_2 += var_0 & 1 - var_0 = var_0 >> 1 - if var_5 != 31 : - var_2 = var_2 << 1 - return var_2 -",103132,4 -439,1019_1.py,"def nextLargerNodes( head): - result = [] - while head: - result.append(head.val) - head = head.next - - stack = [result[-1]] - ans = [0] - for val in range(len(result)-2, -1, -1): - if result[val] < stack[-1]: - ans.append(stack[-1]) - else: - while stack and stack[-1] <= result[val]: - stack.pop() - if stack: - ans.append(stack[-1]) - else: - ans.append(0) - stack.append(result[val]) - return ans[::-1]","def sample_funcname ( var_0 ) : - var_1 = [ ] - while var_0 : - var_1.append ( var_0.val ) - var_0 = var_0.next - var_6 = [ var_1 [ - 1 ] ] - var_8 = [ 0 ] - for val in range ( len ( var_1 ) - 2 , - 1 , - 1 ) : - if var_1 [ val ] < var_6 [ - 1 ] : - var_8.append ( var_6 [ - 1 ] ) - else : - while var_6 and var_6 [ - 1 ] <= var_1 [ val ] : - var_6.pop ( ) - if var_6 : - var_8.append ( var_6 [ - 1 ] ) - else : - var_8.append ( 0 ) - var_6.append ( var_1 [ val ] ) - return var_8 [ : : - 1 ] -",102,3 -440,31_1.py,"def nextPermutation( nums): - index_i = len(nums) - 2 - while index_i >= 0 and nums[index_i] >= nums[index_i+1]: - index_i -= 1 - - if index_i >= 0: - index_j = len(nums) - 1 - while index_j >= index_i and nums[index_j] <= nums[index_i]: - index_j -= 1 - - nums[index_i], nums[index_j] = nums[index_j], nums[index_i] - - start = index_i + 1 - end = len(nums) - 1 - - while start < end: - nums[start], nums[end] = nums[end], nums[start] - start += 1 - end -= 1","def sample_funcname ( var_0 ) : - var_3 = len ( var_0 ) - 2 - while var_3 >= 0 and var_0 [ var_3 ] >= var_0 [ var_3 + 1 ] : - var_3 -= 1 - if var_3 >= 0 : - var_6 = len ( var_0 ) - 1 - while var_6 >= var_3 and var_0 [ var_6 ] <= var_0 [ var_3 ] : - var_6 -= 1 - var_0 [ var_3 ] , var_0 [ var_6 ] = var_0 [ var_6 ] , var_0 [ var_3 ] - var_7 = var_3 + 1 - var_8 = len ( var_0 ) - 1 - while var_7 < var_8 : - var_0 [ var_7 ] , var_0 [ var_8 ] = var_0 [ var_8 ] , var_0 [ var_7 ] - var_7 += 1 - var_8 -= 1 -",102,3 -441,240_1.py,"def searchMatrix( matrix, target): - if not matrix: - return False - - left, right = 0, len(matrix[0])-1 - while left < len(matrix) and right >= 0: - if matrix[left][right] == target: - return True - elif matrix[left][right] < target: - left += 1 - else: - right -= 1 - return False","def sample_funcname ( var_0 , var_1 ) : - if not var_0 : - return False - var_4 , var_7 = 0 , len ( var_0 [ 0 ] ) - 1 - while var_4 < len ( var_0 ) and var_7 >= 0 : - if var_0 [ var_4 ] [ var_7 ] == var_1 : - return True - elif var_0 [ var_4 ] [ var_7 ] < var_1 : - var_4 += 1 - else : - var_7 -= 1 - return False -",10,2 -442,1275_1.py,"def check(grid): - for x in range(3): - row = set([grid[x][0],grid[x][1],grid[x][2]]) - if len(row) == 1 and grid[x][0] != 0: - return grid[x][0] - - for x in range(3): - column = set([grid[0][x],grid[1][x],grid[2][x]]) - if len(column) == 1 and grid[0][x] != 0: - return grid[0][x] - - diag1 = set([grid[0][0],grid[1][1],grid[2][2]]) - diag2 = set([grid[0][2],grid[1][1],grid[2][0]]) - if len(diag1) == 1 or len(diag2) == 1 and grid[1][1] != 0: - return grid[1][1] - - return 0","def sample_funcname ( var_0 ) : - for var_3 in range ( 3 ) : - var_8 = set ( [ var_0 [ var_3 ] [ 0 ] , var_0 [ var_3 ] [ 1 ] , var_0 [ var_3 ] [ 2 ] ] ) - if len ( var_8 ) == 1 and var_0 [ var_3 ] [ 0 ] != 0 : - return var_0 [ var_3 ] [ 0 ] - for var_3 in range ( 3 ) : - var_10 = set ( [ var_0 [ 0 ] [ var_3 ] , var_0 [ 1 ] [ var_3 ] , var_0 [ 2 ] [ var_3 ] ] ) - if len ( var_10 ) == 1 and var_0 [ 0 ] [ var_3 ] != 0 : - return var_0 [ 0 ] [ var_3 ] - var_11 = set ( [ var_0 [ 0 ] [ 0 ] , var_0 [ 1 ] [ 1 ] , var_0 [ 2 ] [ 2 ] ] ) - var_12 = set ( [ var_0 [ 0 ] [ 2 ] , var_0 [ 1 ] [ 1 ] , var_0 [ 2 ] [ 0 ] ] ) - if len ( var_11 ) == 1 or len ( var_12 ) == 1 and var_0 [ 1 ] [ 1 ] != 0 : - return var_0 [ 1 ] [ 1 ] - return 0 -",1302,4 -443,997_1.py,"def findJudge( N, trust): - if not trust: - return 1 - mapping = {} - unique = set() - for truste_list in trust: - unique.add(truste_list[0]) - if truste_list[1] in mapping: - mapping[truste_list[1]] += 1 - else: - mapping[truste_list[1]] = 1 - - unique_set = len(unique) - for key, value in mapping.items(): - if value == unique_set: - return key - return -1","def sample_funcname ( var_0 , var_1 ) : - if not var_1 : - return 1 - var_3 = { } - var_5 = set ( ) - for var_6 in var_1 : - var_5.add ( var_6 [ 0 ] ) - if var_6 [ 1 ] in var_3 : - var_3 [ var_6 [ 1 ] ] += 1 - else : - var_3 [ var_6 [ 1 ] ] = 1 - var_10 = len ( var_5 ) - for var_12 , var_13 in var_3.items ( ) : - if var_13 == var_10 : - return var_12 - return - 1 -",10,2 -444,66_1.py,"def plusOne( digits): - result = [] - if not digits: - return [] - - carry = 1 - new_digits = digits[::-1] - - for index in range(len(new_digits)): - new_digits[index], carry = (new_digits[index] + carry)%10, (new_digits[index] + carry)/10 - - if carry > 0: - new_digits.append(carry) - return new_digits[::-1]","def sample_funcname ( var_0 ) : - var_1 = [ ] - if not var_0 : - return [ ] - var_3 = 1 - var_4 = var_0 [ : : - 1 ] - for var_7 in range ( len ( var_4 ) ) : - var_4 [ var_7 ] , var_3 = ( var_4 [ var_7 ] + var_3 ) % 10 , ( var_4 [ var_7 ] + var_3 ) / 10 - if var_3 > 0 : - var_4.append ( var_3 ) - return var_4 [ : : - 1 ] -",1010,3 -445,1191_3.py,"def kadane(arr): - curr_sum, max_sum = arr[0], arr[0] - for index in range(1, len(arr)): - curr_sum = max(arr[index], curr_sum + arr[index]) - max_sum = max(max_sum, curr_sum) - return max_sum","def sample_funcname ( var_0 ) : - var_2 , var_3 = var_0 [ 0 ] , var_0 [ 0 ] - for var_7 in range ( 1 , len ( var_0 ) ) : - var_2 = max ( var_0 [ var_7 ] , var_2 + var_0 [ var_7 ] ) - var_3 = max ( var_3 , var_2 ) - return var_3 -",10,2 -446,145_1.py,"def recursive(root, result): - if not root: - return - recursive(root.left, result) - recursive(root.right, result) - result.append(root.val)","def sample_funcname ( var_1 , var_2 ) : - if not var_1 : - return - var_0 ( var_1.left , var_2 ) - var_0 ( var_1.right , var_2 ) - var_2.append ( var_1.val ) -",,0 -447,1035_1.py,"def maxUncrossedLines( A, B): - dp = [[0]*len(A) for _ in range(len(B))] - - dp[0][0] = 1 if A[0] == B[0] else 0 - for index_i in range(1, len(dp)): - dp[index_i][0] = dp[index_i-1][0] - if A[0] == B[index_i]: - dp[index_i][0] = 1 - - for index_j in range(1, len(dp[0])): - dp[0][index_j] = dp[0][index_j-1] - if B[0] == A[index_j]: - dp[0][index_j] = 1 - - for index_i in range(1, len(dp)): - for index_j in range(1, len(dp[0])): - if A[index_j] == B[index_i]: - dp[index_i][index_j] = max(dp[index_i-1][index_j-1] + 1, max(dp[index_i-1][index_j], dp[index_i][index_j-1])) - else: - dp[index_i][index_j] = max(dp[index_i-1][index_j-1], max(dp[index_i-1][index_j], dp[index_i][index_j-1])) - return dp[len(B)-1][len(A)-1]","def sample_funcname ( var_0 , var_1 ) : - var_6 = [ [ 0 ] * len ( var_0 ) for var_4 in range ( len ( var_1 ) ) ] - var_6 [ 0 ] [ 0 ] = 1 if var_0 [ 0 ] == var_1 [ 0 ] else 0 - for var_8 in range ( 1 , len ( var_6 ) ) : - var_6 [ var_8 ] [ 0 ] = var_6 [ var_8 - 1 ] [ 0 ] - if var_0 [ 0 ] == var_1 [ var_8 ] : - var_6 [ var_8 ] [ 0 ] = 1 - for var_9 in range ( 1 , len ( var_6 [ 0 ] ) ) : - var_6 [ 0 ] [ var_9 ] = var_6 [ 0 ] [ var_9 - 1 ] - if var_1 [ 0 ] == var_0 [ var_9 ] : - var_6 [ 0 ] [ var_9 ] = 1 - for var_8 in range ( 1 , len ( var_6 ) ) : - for var_9 in range ( 1 , len ( var_6 [ 0 ] ) ) : - if var_0 [ var_9 ] == var_1 [ var_8 ] : - var_6 [ var_8 ] [ var_9 ] = max ( var_6 [ var_8 - 1 ] [ var_9 - 1 ] + 1 , max ( var_6 [ var_8 - 1 ] [ var_9 ] , var_6 [ var_8 ] [ var_9 - 1 ] ) ) - else : - var_6 [ var_8 ] [ var_9 ] = max ( var_6 [ var_8 - 1 ] [ var_9 - 1 ] , max ( var_6 [ var_8 - 1 ] [ var_9 ] , var_6 [ var_8 ] [ var_9 - 1 ] ) ) - return var_6 [ len ( var_1 ) - 1 ] [ len ( var_0 ) - 1 ] -",10,2 -448,283_1.py,"def moveZeroes( nums): - zeroIndex = 0 - for index in range(len(nums)): - if nums[index] != 0: - nums[zeroIndex] = nums[index] - zeroIndex += 1 - - for index in range(zeroIndex, len(nums)): - nums[index] = 0","def sample_funcname ( var_0 ) : - var_2 = 0 - for var_5 in range ( len ( var_0 ) ) : - if var_0 [ var_5 ] != 0 : - var_0 [ var_2 ] = var_0 [ var_5 ] - var_2 += 1 - for var_5 in range ( var_2 , len ( var_0 ) ) : - var_0 [ var_5 ] = 0 -",10,2 -449,387_1.py,"def firstUniqChar( s): - letters='abcdefghijklmnopqrstuvwxyz' - index=[s.index(l) for l in letters if s.count(l) == 1] - return min(index) if len(index) > 0 else -1","def sample_funcname ( var_0 ) : - var_2 = 'abcdefghijklmnopqrstuvwxyz' - index = [ var_0.index ( var_4 ) for var_4 in var_2 if var_0.count ( var_4 ) == 1 ] - return min ( index ) if len ( index ) > 0 else - 1 -",10abcdefghijklmnopqrstuvwxyz,3 -450,153_1.py,"def findMin( nums): - if not nums: - return 0 - - if len(nums) == 1: - return nums[0] - left, right = 0, len(nums)-1 - - if nums[left] < nums[right]: - return nums[left] - while left <= right: - while nums[left] == nums[right] and left != right: - left += 1 - - if nums[left] <= nums[right]: - return nums[left] - - mid = (left + right)/2 - if nums[mid] >= nums[left]: - left = mid+1 - else: - right = mid - return -1","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - if len ( var_0 ) == 1 : - return var_0 [ 0 ] - var_4 , var_5 = 0 , len ( var_0 ) - 1 - if var_0 [ var_4 ] < var_0 [ var_5 ] : - return var_0 [ var_4 ] - while var_4 <= var_5 : - while var_0 [ var_4 ] == var_0 [ var_5 ] and var_4 != var_5 : - var_4 += 1 - if var_0 [ var_4 ] <= var_0 [ var_5 ] : - return var_0 [ var_4 ] - var_7 = ( var_4 + var_5 ) / 2 - if var_0 [ var_7 ] >= var_0 [ var_4 ] : - var_4 = var_7 + 1 - else : - var_5 = var_7 - return - 1 -",102,3 -451,1189_1.py,"def maxNumberOfBalloons( text): - if not text: - return 0 - - import collections - cnt = collections.Counter(text) - cnt_ballon = collections.Counter('balloon') - - return min([cnt[c]//cnt_ballon[c] for c in cnt_ballon])","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - import var_2 - var_4 = var_2.Counter ( var_0 ) - var_6 = var_2.Counter ( 'balloon' ) - return min ( [ var_4 [ var_8 ] // var_6 [ var_8 ] for var_8 in var_6 ] ) -",balloon0,2 -452,1023_1.py,"def camelMatch( queries, pattern): - import re - result = [] - patterns = re.findall('[A-Z][a-z]*', pattern) - - for query in queries: - splitter = re.findall('[A-Z][a-z]*', query) - flag = True - if len(patterns) == len(splitter): - for index in range(len(patterns)): - p_i, s_i = 1, 1 - if patterns[index][0] == splitter[index][0]: - while p_i < len(patterns[index]) and s_i < len(splitter[index]): - if patterns[index][p_i] == splitter[index][s_i]: - p_i += 1 - s_i += 1 - else: - s_i += 1 - if p_i != len(patterns[index]): - flag = False - break - else: - flag = False - break - if flag: - result.append(True) - else: - result.append(False) - else: - result.append(False) - return result","def sample_funcname ( var_0 , var_1 ) : - import var_2 - var_3 = [ ] - var_6 = var_2.findall ( '[A-Z][a-z]*' , var_1 ) - for var_7 in var_0 : - var_8 = var_2.findall ( '[A-Z][a-z]*' , var_7 ) - var_10 = True - if len ( var_6 ) == len ( var_8 ) : - for var_13 in range ( len ( var_6 ) ) : - var_15 , var_16 = 1 , 1 - if var_6 [ var_13 ] [ 0 ] == var_8 [ var_13 ] [ 0 ] : - while var_15 < len ( var_6 [ var_13 ] ) and var_16 < len ( var_8 [ var_13 ] ) : - if var_6 [ var_13 ] [ var_15 ] == var_8 [ var_13 ] [ var_16 ] : - var_15 += 1 - var_16 += 1 - else : - var_16 += 1 - if var_15 != len ( var_6 [ var_13 ] ) : - var_10 = False - break - else : - var_10 = False - break - if var_10 : - var_3.append ( True ) - else : - var_3.append ( False ) - else : - var_3.append ( False ) - return var_3 -",[A-Z][a-z]*10,3 -453,1028_1.py,"def longestArithSeqLength( A): - from collections import defaultdict - - dp = defaultdict(int) - for index_i in range(len(A)): - for index_j in range(index_i): - diff = A[index_i] - A[index_j] - dp[(index_i, diff)] = max(dp[(index_i, diff)], dp[(index_j, diff)]+1) - return max(dp.itervalues())+1","def sample_funcname ( var_0 ) : - from var_1 import var_2 - var_4 = var_2 ( int ) - for var_7 in range ( len ( var_0 ) ) : - for var_8 in range ( var_7 ) : - var_9 = var_0 [ var_7 ] - var_0 [ var_8 ] - var_4 [ ( var_7 , var_9 ) ] = max ( var_4 [ ( var_7 , var_9 ) ] , var_4 [ ( var_8 , var_9 ) ] + 1 ) - return max ( var_4.itervalues ( ) ) + 1 -",1,1 -454,334_1.py,"def increasingTriplet( nums): - first, second = float('inf'), float('inf') - for val in nums: - if val <= first: - first = val - elif val <= second: - second = val - else: - return True - - return False","def sample_funcname ( var_0 ) : - var_3 , var_4 = float ( 'inf' ) , float ( 'inf' ) - for var_5 in var_0 : - if var_5 <= var_3 : - var_3 = var_5 - elif var_5 <= var_4 : - var_4 = var_5 - else : - return True - return False -",inf,1 -455,1090_1.py,"def largestValsFromLabels( values, labels, num_wanted, use_limit): - sorted_values = sorted([(i, j) for i, j in zip(values, labels)], key = lambda x : x[0]*-1) - label_used_count = {label: 0 for label in set(labels)} - result = 0 - for s_v in sorted_values: - if num_wanted: - if label_used_count[s_v[1]] < use_limit: - result += s_v[0] - label_used_count[s_v[1]] +=1 - num_wanted -= 1 - else: - break - return result","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - var_12 = sorted ( [ ( var_5 , var_6 ) for var_5 , var_6 in zip ( var_0 , var_1 ) ] , var_8 = lambda var_9 : var_9 [ 0 ] * - 1 ) - var_15 = { var_13 : 0 for var_13 in set ( var_1 ) } - var_16 = 0 - for var_17 in var_12 : - if var_2 : - if var_15 [ var_17 [ 1 ] ] < var_3 : - var_16 += var_17 [ 0 ] - var_15 [ var_17 [ 1 ] ] += 1 - var_2 -= 1 - else : - break - return var_16 -",10,2 -456,226_1.py,"def invertTree( root): - if not root: - return None - - queue = [root] - while queue: - node = queue.pop(0) - node.left, node.right = node.right, node.left - if node.left: - queue.append(node.left) - if node.right: - queue.append(node.right) - - return root","def sample_funcname ( var_0 ) : - if not var_0 : - return None - var_2 = [ var_0 ] - while var_2 : - var_5 = var_2.pop ( 0 ) - var_5.left , var_5.right = var_5.right , var_5.left - if var_5.left : - var_2.append ( var_5.left ) - if var_5.right : - var_2.append ( var_5.right ) - return var_0 -",0None,2 -457,119_1.py,"def getRow( rowIndex): - row = [1]*(rowIndex+1) - for i in range(1, rowIndex+1): - for j in range(i-1, 0, -1): - row[j] += row[j-1] - return row","def sample_funcname ( var_0 ) : - var_2 = [ 1 ] * ( var_0 + 1 ) - for var_4 in range ( 1 , var_0 + 1 ) : - for var_6 in range ( var_4 - 1 , 0 , - 1 ) : - var_2 [ var_6 ] += var_2 [ var_6 - 1 ] - return var_2 -",10,2 -458,1086_1.py,"def highFive( items): - if not items: - return [] - - score_map = {} - for item in items: - if item[0] in score_map: - score_map[item[0]].append(item[1]) - else: - score_map[item[0]] = [item[1]] - - result = [] - for key, value in score_map.items(): - value.sort(reverse=True) - if len(value) >= 5: - average = value[:5] - else: - average = value - score_map[key] = sum(average)/len(average) - result.append([key, score_map[key] ]) - - return result","def sample_funcname ( items ) : - if not items : - return [ ] - var_1 = { } - for var_2 in items : - if var_2 [ 0 ] in var_1 : - var_1 [ var_2 [ 0 ] ].append ( var_2 [ 1 ] ) - else : - var_1 [ var_2 [ 0 ] ] = [ var_2 [ 1 ] ] - var_6 = [ ] - for var_7 , var_8 in var_1.items ( ) : - var_8.sort ( var_10 = True ) - if len ( var_8 ) >= 5 : - var_14 = var_8 [ : 5 ] - else : - var_14 = var_8 - var_1 [ var_7 ] = sum ( var_14 ) / len ( var_14 ) - var_6.append ( [ var_7 , var_1 [ var_7 ] ] ) - return var_6 -",105,3 -459,41_1.py,"def firstMissingPositive( nums): - index_i = 0 - for index_j in range(len(nums)): - if nums[index_j] <= 0: - nums[index_i], nums[index_j] = nums[index_j], nums[index_i] - index_i += 1 - - for index in range(index_i, len(nums)): - if abs(nums[index]) - 1 < len(nums) and nums[abs(nums[index]) - 1] > 0: - nums[abs(nums[index]) - 1] = -nums[abs(nums[index]) - 1] - - for index in range(nums): - if nums[index] > 0: - return index + 1 - return len(nums) + 1","def sample_funcname ( var_0 ) : - var_2 = 0 - for var_5 in range ( len ( var_0 ) ) : - if var_0 [ var_5 ] <= 0 : - var_0 [ var_2 ] , var_0 [ var_5 ] = var_0 [ var_5 ] , var_0 [ var_2 ] - var_2 += 1 - for var_7 in range ( var_2 , len ( var_0 ) ) : - if abs ( var_0 [ var_7 ] ) - 1 < len ( var_0 ) and var_0 [ abs ( var_0 [ var_7 ] ) - 1 ] > 0 : - var_0 [ abs ( var_0 [ var_7 ] ) - 1 ] = - var_0 [ abs ( var_0 [ var_7 ] ) - 1 ] - for var_7 in range ( var_0 ) : - if var_0 [ var_7 ] > 0 : - return var_7 + 1 - return len ( var_0 ) + 1 -",10,2 -460,230_1.py,"def kthSmallest( root, k): - if not root: - return 0 - - stack = [root] - count, curr = 0, root - - - while stack: - if curr.left: - stack.append(curr.left) - curr = curr.left - else: - val = stack.pop() - count += 1 - if count == k: - return val.val - - if val.right: - stack.append(val.right) - curr = val.right - return float('-inf')","def sample_funcname ( var_0 , var_1 ) : - if not var_0 : - return 0 - var_3 = [ var_0 ] - var_4 , var_5 = 0 , var_0 - while var_3 : - if var_5.left : - var_3.append ( var_5.left ) - var_5 = var_5.left - else : - val = var_3.pop ( ) - var_4 += 1 - if var_4 == var_1 : - return val.val - if val.right : - var_3.append ( val.right ) - var_5 = val.right - return float ( '-inf' ) -",10-inf,3 -461,16_1.py,"def threeSumClosest( nums, target): - nums.sort() - result, min_diff = 0, float('inf') - - for index in range(len(nums)-1): - left = index + 1 - right = len(nums) - 1 - - while left < right: - currSum = nums[index] + nums[left] + nums[right] - diff = abs(target - currSum) - - if diff == 0: - return target - if diff < min_diff: - min_diff = diff - result = currSum - - if currSum < target: - left += 1 - else: - right -= 1 - return result","def sample_funcname ( var_0 , var_1 ) : - var_0.sort ( ) - var_4 , var_7 = 0 , float ( 'inf' ) - for var_11 in range ( len ( var_0 ) - 1 ) : - var_12 = var_11 + 1 - var_13 = len ( var_0 ) - 1 - while var_12 < var_13 : - var_14 = var_0 [ var_11 ] + var_0 [ var_12 ] + var_0 [ var_13 ] - var_16 = abs ( var_1 - var_14 ) - if var_16 == 0 : - return var_1 - if var_16 < var_7 : - var_7 = var_16 - var_4 = var_14 - if var_14 < var_1 : - var_12 += 1 - else : - var_13 -= 1 - return var_4 -",10inf,3 -462,322_1.py,"def coinChange( coins, amount): - if not coins: - return 0 - - dp = [float('inf') for _ in range(amount+1)] - dp[0] = 0 - - for val in range(1, amount+1): - for coin in coins: - if coin <= val: - dp[val] = min(dp[val-coin]+1, dp[val]) - return dp[amount] if dp[amount] != float('inf') else -1","def sample_funcname ( var_0 , var_1 ) : - if not var_0 : - return 0 - var_8 = [ float ( 'inf' ) for var_5 in range ( var_1 + 1 ) ] - var_8 [ 0 ] = 0 - for var_9 in range ( 1 , var_1 + 1 ) : - for var_10 in var_0 : - if var_10 <= var_9 : - var_8 [ var_9 ] = min ( var_8 [ var_9 - var_10 ] + 1 , var_8 [ var_9 ] ) - return var_8 [ var_1 ] if var_8 [ var_1 ] != float ( 'inf' ) else - 1 -",10inf,3 -463,162_1.py,"def findPeakElement( nums): - left, right = 0, len(nums)-1 - while left < right: - mid = (left + right) /2 - if nums[mid] > nums[mid+1]: - right = mid - else: - left = mid + 1 - return left","def sample_funcname ( var_0 ) : - var_2 , var_5 = 0 , len ( var_0 ) - 1 - while var_2 < var_5 : - var_7 = ( var_2 + var_5 ) / 2 - if var_0 [ var_7 ] > var_0 [ var_7 + 1 ] : - var_5 = var_7 - else : - var_2 = var_7 + 1 - return var_2 -",102,3 -464,1291_1.py,"def sequentialDigits( low, high): - result = [] - start = int(str(low)[0]) - for val in range(1, len(str(low))): - new_val = start%10 + 1 - start = start*10 + new_val - if start > high: - return result - - result.append(start) - - while result[-1] <= high: - temp = str(result[-1]) - next_elem = int(temp[-1]) + 1 - - if next_elem > 9: - next_greater = 0 - for index in range(len(temp) + 1): - next_greater = next_greater*10 + (index+1) - else: - next_greater = int(temp[1:]) * 10 + next_elem - if next_greater <= high: - result.append(next_greater) - else: - break - final_result = [] - for val in result: - if '0' not in str(val) and val >= low: - final_result.append(val) - return final_result","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - var_6 = int ( str ( var_0 ) [ 0 ] ) - for var_10 in range ( 1 , len ( str ( var_0 ) ) ) : - var_12 = var_6 % 10 + 1 - var_6 = var_6 * 10 + var_12 - if var_6 > var_1 : - return var_2 - var_2.append ( var_6 ) - while var_2 [ - 1 ] <= var_1 : - var_14 = str ( var_2 [ - 1 ] ) - var_15 = int ( var_14 [ - 1 ] ) + 1 - if var_15 > 9 : - var_17 = 0 - for var_18 in range ( len ( var_14 ) + 1 ) : - var_17 = var_17 * 10 + ( var_18 + 1 ) - else : - var_17 = int ( var_14 [ 1 : ] ) * 10 + var_15 - if var_17 <= var_1 : - var_2.append ( var_17 ) - else : - break - var_19 = [ ] - for var_10 in var_2 : - if '0' not in str ( var_10 ) and var_10 >= var_0 : - var_19.append ( var_10 ) - return var_19 -",100019,5 -465,1004_1.py,"def longestOnes( A, K): - start_index = 0 - for end_index in range(0, len(A)): - K -= 1-A[end_index] - if K < 0: - K += 1-A[start_index] - start_index += 1 - return end_index-start_index+1","def sample_funcname ( var_0 , var_1 ) : - var_3 = 0 - for var_6 in range ( 0 , len ( var_0 ) ) : - var_1 -= 1 - var_0 [ var_6 ] - if var_1 < 0 : - var_1 += 1 - var_0 [ var_3 ] - var_3 += 1 - return var_6 - var_3 + 1 -",10,2 -466,94_1.py,"def inorderTraversal( root): - if not root: - return [] - - stack, result = [root], [] - while stack: - if root.left: - stack.append(root.left) - root = root.left - else: - node = stack.pop() - result.append(node.val) - - if node.right: - stack.append(node.right) - root = node.right - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - var_1 , var_2 = [ var_0 ] , [ ] - while var_1 : - if var_0.left : - var_1.append ( var_0.left ) - var_0 = var_0.left - else : - var_6 = var_1.pop ( ) - var_2.append ( var_6.val ) - if var_6.right : - var_1.append ( var_6.right ) - var_0 = var_6.right - return var_2 -",,0 -467,1053_1.py,"def prevPermOpt1( A): - left, right = len(A)-2, len(A)-1 - for left in range(len(A)-2, -1, -1): - if A[left] > A[left+1]: - break - else: - return A - right = A.index(max(ele for ele in A[left+1:] if ele < A[left]), left) - A[left], A[right] = A[right], A[left] - return A","def sample_funcname ( var_0 ) : - var_3 , var_5 = len ( var_0 ) - 2 , len ( var_0 ) - 1 - for var_3 in range ( len ( var_0 ) - 2 , - 1 , - 1 ) : - if var_0 [ var_3 ] > var_0 [ var_3 + 1 ] : - break - else : - return var_0 - var_5 = var_0.index ( max ( var_9 for var_9 in var_0 [ var_3 + 1 : ] if var_9 < var_0 [ var_3 ] ) , var_3 ) - var_0 [ var_3 ] , var_0 [ var_5 ] = var_0 [ var_5 ] , var_0 [ var_3 ] - return var_0 -",12,2 -468,123_1.py,"def maxProfit( prices): - if len(prices) < 2: - return 0 - dp = [[0 for _ in range(len(prices))] for _ in range(3)] - for i in range(1,3): - maxDiff = -prices[0] - for j in range(1,len(prices)): - dp[i][j] = max(dp[i][j-1], prices[j] + maxDiff) - maxDiff = max(maxDiff, dp[i-1][j] -prices[j]) - - return dp[2][len(prices)-1]","def sample_funcname ( var_0 ) : - if len ( var_0 ) < 2 : - return 0 - var_7 = [ [ 0 for var_4 in range ( len ( var_0 ) ) ] for var_4 in range ( 3 ) ] - for var_9 in range ( 1 , 3 ) : - var_10 = - var_0 [ 0 ] - for var_11 in range ( 1 , len ( var_0 ) ) : - var_7 [ var_9 ] [ var_11 ] = max ( var_7 [ var_9 ] [ var_11 - 1 ] , var_0 [ var_11 ] + var_10 ) - var_10 = max ( var_10 , var_7 [ var_9 - 1 ] [ var_11 ] - var_0 [ var_11 ] ) - return var_7 [ 2 ] [ len ( var_0 ) - 1 ] -",1302,4 -469,103_1.py,"def zigzagLevelOrder( root): - if not root: - return [] - - queue = [(root, 0)] - levelMap = {} - - while queue: - node, level = queue.pop(0) - if node.left: - queue.append((node.left, level+1)) - if node.right: - queue.append((node.right, level+1)) - - if level in levelMap: - levelMap[level].append(node.val) - else: - levelMap[level] = [node.val] - - result = [] - spiral = False - for key, value in levelMap.iteritems(): - if spiral: - value = value[::-1] - result.append(value) - spiral = not spiral - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - var_2 = [ ( var_0 , 0 ) ] - var_3 = { } - while var_2 : - var_5 , var_6 = var_2.pop ( 0 ) - if var_5.left : - var_2.append ( ( var_5.left , var_6 + 1 ) ) - if var_5.right : - var_2.append ( ( var_5.right , var_6 + 1 ) ) - if var_6 in var_3 : - var_3 [ var_6 ].append ( var_5.val ) - else : - var_3 [ var_6 ] = [ var_5.val ] - var_12 = [ ] - var_14 = False - for var_16 , var_17 in var_3.iteritems ( ) : - if var_14 : - var_17 = var_17 [ : : - 1 ] - var_12.append ( var_17 ) - var_14 = not var_14 - return var_12 -",10,2 -470,115_1.py,"def numDistinct( s, t): - row, col = len(s), len(t) - - if col > row: - return 0 - - dp = [[0 for _ in range(col+1)] for _ in range(row+1)] - - for r in range(row+1): - for c in range(col+1): - if r == 0 and c == 0: - dp[r][c] = 1 - elif r == 0: - dp[r][c] = 0 - elif c == 0: - dp[r][c] = 1 - else: - dp[r][c] = dp[r-1][c] - if s[r-1] == t[c-1]: - dp[r][c] += dp[r-1][c-1] - return dp[row][col]","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = len ( var_0 ) , len ( var_1 ) - if var_4 > var_3 : - return 0 - var_9 = [ [ 0 for var_6 in range ( var_4 + 1 ) ] for var_6 in range ( var_3 + 1 ) ] - for var_10 in range ( var_3 + 1 ) : - for var_11 in range ( var_4 + 1 ) : - if var_10 == 0 and var_11 == 0 : - var_9 [ var_10 ] [ var_11 ] = 1 - elif var_10 == 0 : - var_9 [ var_10 ] [ var_11 ] = 0 - elif var_11 == 0 : - var_9 [ var_10 ] [ var_11 ] = 1 - else : - var_9 [ var_10 ] [ var_11 ] = var_9 [ var_10 - 1 ] [ var_11 ] - if var_0 [ var_10 - 1 ] == var_1 [ var_11 - 1 ] : - var_9 [ var_10 ] [ var_11 ] += var_9 [ var_10 - 1 ] [ var_11 - 1 ] - return var_9 [ var_3 ] [ var_4 ] -",10,2 -471,TwoSum_1.py,"def twoSum( nums, target): - mapping = {} - - for index, val in enumerate(nums): - diff = target - val - if diff in mapping: - return [index, mapping[diff]] - else: - mapping[val] = index","def sample_funcname ( var_0 , var_1 ) : - var_2 = { } - for var_4 , var_5 in enumerate ( var_0 ) : - var_6 = var_1 - var_5 - if var_6 in var_2 : - return [ var_4 , var_2 [ var_6 ] ] - else : - var_2 [ var_5 ] = var_4 -",,0 -472,1065_1.py,"def indexPairs( text, words): - if not words: - return [] - result = [] - for word in words: - starting = [index for index in range(len(text)) if text.startswith(word, index)] - for start in starting: - result.append([start, start+len(word)-1]) - result.sort() - return result","def sample_funcname ( var_0 , var_1 ) : - if not var_1 : - return [ ] - var_2 = [ ] - for var_3 in var_1 : - var_8 = [ var_4 for var_4 in range ( len ( var_0 ) ) if var_0.startswith ( var_3 , var_4 ) ] - for var_9 in var_8 : - var_2.append ( [ var_9 , var_9 + len ( var_3 ) - 1 ] ) - var_2.sort ( ) - return var_2 -",1,1 -473,142_1.py,"def detectCycle( head): - if not head: - return None - - slow, fast = head, head.next - - while fast and fast.next: - slow = slow.next - fast = fast.next.next - if slow == fast: - break - - if slow == fast: - slow = head - while slow != fast: - slow = slow.next - fast = fast.next - return slow - return None","def sample_funcname ( var_0 ) : - if not var_0 : - return None - var_2 , var_4 = var_0 , var_0.next - while var_4 and var_4.next : - var_2 = var_2.next - var_4 = var_4.next.next - if var_2 == var_4 : - break - if var_2 == var_4 : - var_2 = var_0 - while var_2 != var_4 : - var_2 = var_2.next - var_4 = var_4.next - return var_2 - return None -",None,1 -474,61_1.py,"def rotateRight( head, k): - if k == 0: - return head - if not head: - return None - - tempHead, length = head, 1 - while tempHead.next: - length += 1 - tempHead = tempHead.next - - tempHead.next = head - jump = (length-k)%length - - previous = tempHead - while jump > 0: - previous = previous.next - jump -= 1 - head = previous.next - previous.next = None - - return head","def sample_funcname ( var_0 , var_1 ) : - if var_1 == 0 : - return var_0 - if not var_0 : - return None - var_4 , var_6 = var_0 , 1 - while var_4.next : - var_6 += 1 - var_4 = var_4.next - var_4.next = var_0 - var_8 = ( var_6 - var_1 ) % var_6 - var_9 = var_4 - while var_8 > 0 : - var_9 = var_9.next - var_8 -= 1 - var_0 = var_9.next - var_9.next = None - return var_0 -",10None,3 -475,990_1.py,"def equationsPossible( equations): - equal_list, unequal_list = [], [] - for equation in equations: - x, y = equation[0], equation[3] - if '==' in equation: - if not equal_list: - equal_list.append(x+y) - else: - found = False - for index in range(0, len(equal_list)): - val = equal_list[index] - if x in val or y in val: - val = val+x+y - equal_list[index] = val - found = True - if not found: - equal_list.append(x+y) - else: - if x == y: - return False - unequal_list.append([x, y]) - - for val in unequal_list: - for equal in equal_list: - if val[0] in equal and val[1] in equal: - return False - return True","def sample_funcname ( var_0 ) : - var_1 , var_2 = [ ] , [ ] - for var_3 in var_0 : - var_5 , var_7 = var_3 [ 0 ] , var_3 [ 3 ] - if '==' in var_3 : - if not var_1 : - var_1.append ( var_5 + var_7 ) - else : - var_11 = False - for var_14 in range ( 0 , len ( var_1 ) ) : - var_15 = var_1 [ var_14 ] - if var_5 in var_15 or var_7 in var_15 : - var_15 = var_15 + var_5 + var_7 - var_1 [ var_14 ] = var_15 - var_11 = True - if not var_11 : - var_1.append ( var_5 + var_7 ) - else : - if var_5 == var_7 : - return False - var_2.append ( [ var_5 , var_7 ] ) - for var_15 in var_2 : - for var_17 in var_1 : - if var_15 [ 0 ] in var_17 and var_15 [ 1 ] in var_17 : - return False - return True -",==301,4 -476,1011_2.py,"def shipWithinDays( weights, D): - left, right = max(weights), sum(weights) - - while left < right: - curr_sum, groups, invalid = 0, 0, True - mid = left + ((right-left) >> 1) - for weight in weights: - if weight > mid: - invalid = False - break - if curr_sum + weight > mid: - groups += 1 - curr_sum = 0 - curr_sum += weight - if invalid and groups < D: - right = mid - else: - left = mid + 1 - return left","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_5 = max ( var_0 ) , sum ( var_0 ) - while var_3 < var_5 : - var_7 , var_8 , var_10 = 0 , 0 , True - var_12 = var_3 + ( ( var_5 - var_3 ) >> 1 ) - for var_13 in var_0 : - if var_13 > var_12 : - var_10 = False - break - if var_7 + var_13 > var_12 : - var_8 += 1 - var_7 = 0 - var_7 += var_13 - if var_10 and var_8 < var_1 : - var_5 = var_12 - else : - var_3 = var_12 + 1 - return var_3 -",10,2 -477,36_1.py,"def isValidSudoku( board): - import collections - dict_row, dict_col, dict_cell = collections.defaultdict(set), collections.defaultdict(set), collections.defaultdict(set) - - for row_index in range(1, 4): - for col_index in range(1, 4): - for row in range(3*(row_index-1), 3*row_index): - for col in range(3*(col_index-1), 3*col_index): - cell_data = board[row][col] - if cell_data == '.': - continue - if cell_data in dict_row[row] or cell_data in dict_col[col] or cell_data in dict_cell[(row_index, col_index)]: - return False - - dict_row[row].add(cell_data) - dict_col[col].add(cell_data) - dict_cell[(row_index, col_index)].add(cell_data) - - return True","def sample_funcname ( var_0 ) : - import var_1 - var_4 , var_5 , var_6 = var_1.defaultdict ( set ) , var_1.defaultdict ( set ) , var_1.defaultdict ( set ) - for var_10 in range ( 1 , 4 ) : - for var_11 in range ( 1 , 4 ) : - for var_13 in range ( 3 * ( var_10 - 1 ) , 3 * var_10 ) : - for var_14 in range ( 3 * ( var_11 - 1 ) , 3 * var_11 ) : - var_15 = var_0 [ var_13 ] [ var_14 ] - if var_15 == '.' : - continue - if var_15 in var_4 [ var_13 ] or var_15 in var_5 [ var_14 ] or var_15 in var_6 [ ( var_10 , var_11 ) ] : - return False - var_4 [ var_13 ].add ( var_15 ) - var_5 [ var_14 ].add ( var_15 ) - var_6 [ ( var_10 , var_11 ) ].add ( var_15 ) - return True -",314.,4 -478,482_1.py,"def licenseKeyFormatting( S, K): - S = S.replace('-','').upper() - result = """" - - if len(S)%K == 0: - for index in range(0, len(S), K): - result += S[index:index+K] + ""-"" - else: - result = S[:len(S)%K] + ""-"" - for index in range(len(S)%K, len(S), K): - result += S[index:index+K] + ""-"" - return result[:-1]","def sample_funcname ( var_0 , var_1 ) : - var_0 = var_0.var_2 ( '-' , '' ).upper ( ) - var_7 = """" - if len ( var_0 ) % var_1 == 0 : - for var_11 in range ( 0 , len ( var_0 ) , var_1 ) : - var_7 += var_0 [ var_11 : var_11 + var_1 ] + ""-"" - else : - var_7 = var_0 [ : len ( var_0 ) % var_1 ] + ""-"" - for var_11 in range ( len ( var_0 ) % var_1 , len ( var_0 ) , var_1 ) : - var_7 += var_0 [ var_11 : var_11 + var_1 ] + ""-"" - return var_7 [ : - 1 ] -",0-1-,6 -479,206_1.py,"def reverseList( head): - if not head: - return None - - prev, curr = None, head - while curr: - temp = curr.next - curr.next = prev - prev = curr - curr = temp - return prev","def sample_funcname ( var_0 ) : - if not var_0 : - return None - var_2 , var_3 = None , var_0 - while var_3 : - var_5 = var_3.next - var_3.next = var_2 - var_2 = var_3 - var_3 = var_5 - return var_2 -",None,1 -480,98_1.py,"def isValidBST( root): - if not root: - return True - - stack, result = [], [] - while stack or root: - if root: - stack.append(root) - root = root.left - else: - root = stack.pop() - result.append(root.val) - root = root.right - - previous = result[0] - for index in range(1, len(result)): - if previous >= result[index]: - return False - previous = result[index] - return True","def sample_funcname ( var_0 ) : - if not var_0 : - return True - var_2 , var_3 = [ ] , [ ] - while var_2 or var_0 : - if var_0 : - var_2.append ( var_0 ) - var_0 = var_0.left - else : - var_0 = var_2.pop ( ) - var_3.append ( var_0.val ) - var_0 = var_0.right - var_10 = var_3 [ 0 ] - for var_14 in range ( 1 , len ( var_3 ) ) : - if var_10 >= var_3 [ var_14 ] : - return False - var_10 = var_3 [ var_14 ] - return True -",10,2 -481,1009_1.py,"def bitwiseComplement( N): - if N == 0: - return 1 - import math - bits = (int)(math.floor(math.log(N) /math.log(2))) + 1 - return ((1 << bits) - 1) ^ N","def sample_funcname ( var_0 ) : - if var_0 == 0 : - return 1 - import var_3 - var_8 = ( int ) ( var_3.floor ( var_3.log ( var_0 ) / var_3.log ( 2 ) ) ) + 1 - return ( ( 1 << var_8 ) - 1 ) ^ var_0 -",102,3 -482,60_1.py,"def permute(nums): - if len(nums) == 0: - return [] - if len(nums) == 1: - return [nums] - - result = [] - for index in range(len(nums)): - for p in permute(nums[0:index] + nums[index+1:]): - result.append([nums[index]] + p) - - return result","def sample_funcname ( var_1 ) : - if len ( var_1 ) == 0 : - return [ ] - if len ( var_1 ) == 1 : - return [ var_1 ] - var_5 = [ ] - for var_7 in range ( len ( var_1 ) ) : - for var_8 in var_0 ( var_1 [ 0 : var_7 ] + var_1 [ var_7 + 1 : ] ) : - var_5.append ( [ var_1 [ var_7 ] ] + var_8 ) - return var_5 -",10,2 -483,143_1.py,"def reorderList( head): - if not head: - return None - - slow, fast = head, head.next - - while fast and fast.next: - slow = slow.next - fast = fast.next.next - - head1, head2 = head, slow.next - slow.next = None - prev = None - curr = head2 - while curr: - nex = curr.next - curr.next = prev - prev = curr - curr = nex - head2 = prev - - while head2: - n1 = head1.next - n2 = head2.next - head1.next = head2 - head1.next.next = n1 - head2 = n2 - head1 = head1.next.next - - head = head1","def sample_funcname ( var_0 ) : - if not var_0 : - return None - var_2 , var_4 = var_0 , var_0.next - while var_4 and var_4.next : - var_2 = var_2.next - var_4 = var_4.next.next - var_5 , var_6 = var_0 , var_2.next - var_2.next = None - var_7 = None - var_8 = var_6 - while var_8 : - var_9 = var_8.next - var_8.next = var_7 - var_7 = var_8 - var_8 = var_9 - var_6 = var_7 - while var_6 : - var_10 = var_5.next - var_11 = var_6.next - var_5.next = var_6 - var_5.next.next = var_10 - var_6 = var_11 - var_5 = var_5.next.next - var_0 = var_5 -",None,1 -484,1033_1.py,"def numMovesStones( a, b, c): - lista = [a, b, c] - lista.sort() - a, b, c = lista[0], lista[1], lista[2] - minsteps = 0 - if b == a+1 and c == a+2: - return [0, 0] - elif b == a+1 or c == b+1 or c == b+2 or b == a+2: - minsteps = 1 - else: - minsteps = 2 - return [minsteps, b-a-1+c-b-1]","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_3 = [ var_0 , var_1 , var_2 ] - var_3.sort ( ) - var_0 , var_1 , var_2 = var_3 [ 0 ] , var_3 [ 1 ] , var_3 [ 2 ] - var_8 = 0 - if var_1 == var_0 + 1 and var_2 == var_0 + 2 : - return [ 0 , 0 ] - elif var_1 == var_0 + 1 or var_2 == var_1 + 1 or var_2 == var_1 + 2 or var_1 == var_0 + 2 : - var_8 = 1 - else : - var_8 = 2 - return [ var_8 , var_1 - var_0 - 1 + var_2 - var_1 - 1 ] -",102,3 -485,285_1.py,"def inorderSuccessor( root, p): - if not root or not p: - return None - - if p.right: - p = p.right - while p.left: - p = p.left - return p - - successor = None - while root and root != p: - if root.val > p.val: - successor = root - root = root.left - else: - root = root.right - return successor","def sample_funcname ( var_0 , var_1 ) : - if not var_0 or not var_1 : - return None - if var_1.right : - var_1 = var_1.right - while var_1.left : - var_1 = var_1.left - return var_1 - var_5 = None - while var_0 and var_0 != var_1 : - if var_0.val > var_1.val : - var_5 = var_0 - var_0 = var_0.left - else : - var_0 = var_0.right - return var_5 -",None,1 -486,1064_1.py,"def fixedPoint( A): - if not A: - return -1 - for index, num in enumerate(A): - if num == index: - return index - return -1","def sample_funcname ( var_0 ) : - if not var_0 : - return - 1 - for var_3 , var_4 in enumerate ( var_0 ) : - if var_4 == var_3 : - return var_3 - return - 1 -",1,1 -487,378_1.py,"def kthSmallest( matrix, k): - if not matrix: - return 0 - - import heapq - heap = [] - for col in range(len(matrix[0])): - heapq.heappush(heap, (matrix[0][col], 0, col)) - - val = 0 - for index in range(k): - val, row, col = heapq.heappop(heap) - new_val = float('inf') - if row < len(matrix)-1: - new_val = matrix[row+1][col] - heapq.heappush(heap, (new_val, row+1, col)) - return val","def sample_funcname ( var_0 , var_1 ) : - if not var_0 : - return 0 - import var_3 - var_4 = [ ] - for var_7 in range ( len ( var_0 [ 0 ] ) ) : - var_3.heappush ( var_4 , ( var_0 [ 0 ] [ var_7 ] , 0 , var_7 ) ) - var_9 = 0 - for var_10 in range ( var_1 ) : - var_9 , var_12 , var_7 = var_3.heappop ( var_4 ) - var_15 = float ( 'inf' ) - if var_12 < len ( var_0 ) - 1 : - var_15 = var_0 [ var_12 + 1 ] [ var_7 ] - var_3.heappush ( var_4 , ( var_15 , var_12 + 1 , var_7 ) ) - return var_9 -",10inf,3 -488,102_1.py,"def levelOrder( root): - if not root: - return [] - - queue = [(root, 0)] - levelMap = {} - - while queue: - node, level = queue.pop(0) - if node.left: - queue.append((node.left, level+1)) - if node.right: - queue.append((node.right, level+1)) - - if level in levelMap: - levelMap[level].append(node.val) - else: - levelMap[level] = [node.val] - - result = [] - for key, value in levelMap.iteritems(): - result.append(value) - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - var_2 = [ ( var_0 , 0 ) ] - var_3 = { } - while var_2 : - var_5 , var_6 = var_2.pop ( 0 ) - if var_5.left : - var_2.append ( ( var_5.left , var_6 + 1 ) ) - if var_5.right : - var_2.append ( ( var_5.right , var_6 + 1 ) ) - if var_6 in var_3 : - var_3 [ var_6 ].append ( var_5.val ) - else : - var_3 [ var_6 ] = [ var_5.val ] - var_12 = [ ] - for var_14 , var_15 in var_3.iteritems ( ) : - var_12.append ( var_15 ) - return var_12 -",10,2 -489,1025_1.py,"def divisorGame( N): - if N == 0: - return False - - move = 0 - while N > 1: - for num in range(1, N): - if N%num == 0: - N -= num - move += 1 - break - if move%2: - return True - return False","def sample_funcname ( var_0 ) : - if var_0 == 0 : - return False - var_3 = 0 - while var_0 > 1 : - for var_6 in range ( 1 , var_0 ) : - if var_0 % var_6 == 0 : - var_0 -= var_6 - var_3 += 1 - break - if var_3 % 2 : - return True - return False -",102,3 -490,1052_1.py,"def maxSatisfied( customers, grumpy, X): - result = 0 - - prefix_sum = [0]*(len(customers)+1) - index = 0 - for customer, grump in zip(customers, grumpy): - prefix_sum[index+1] = prefix_sum[index] - if grump == 0: - result += customer - else: - prefix_sum[index+1] += customer - index += 1 - curr_max = result + prefix_sum[X] - for index in range(X+1, len(prefix_sum)): - temp_max = result + prefix_sum[index] - prefix_sum[index-X] - curr_max = max(curr_max, temp_max) - return curr_max","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_4 = 0 - var_7 = [ 0 ] * ( len ( var_0 ) + 1 ) - var_8 = 0 - for var_10 , var_11 in zip ( var_0 , var_1 ) : - var_7 [ var_8 + 1 ] = var_7 [ var_8 ] - if var_11 == 0 : - var_4 += var_10 - else : - var_7 [ var_8 + 1 ] += var_10 - var_8 += 1 - var_12 = var_4 + var_7 [ var_2 ] - for var_8 in range ( var_2 + 1 , len ( var_7 ) ) : - var_14 = var_4 + var_7 [ var_8 ] - var_7 [ var_8 - var_2 ] - var_12 = max ( var_12 , var_14 ) - return var_12 -",10,2 -491,1005_1.py,"def largestSumAfterKNegations( A, K): - A.sort() - index = 0 - while K > 0: - if A[index] < 0: - A[index] *= -1 - if A[index+1] < A[index] and index < len(A)-1: - index += 1 - else: - A[index] *= -1 - K -= 1 - return sum(A)","def sample_funcname ( var_0 , var_1 ) : - var_0.sort ( ) - var_4 = 0 - while var_1 > 0 : - if var_0 [ var_4 ] < 0 : - var_0 [ var_4 ] *= - 1 - if var_0 [ var_4 + 1 ] < var_0 [ var_4 ] and var_4 < len ( var_0 ) - 1 : - var_4 += 1 - else : - var_0 [ var_4 ] *= - 1 - var_1 -= 1 - return sum ( var_0 ) -",10,2 -492,1290_1.py,"def getDecimalValue( head): - result = '' - if not head: - return 0 - while head: - result+= str(head.val) - head = head.next - return int(result, 2)","def sample_funcname ( var_0 ) : - var_2 = '' - if not var_0 : - return 0 - while var_0 : - var_2 += str ( var_0.val ) - var_0 = var_0.next - return int ( var_2 , 2 ) -",02,3 -493,163_1.py,"def missingRange( A, lower, upper): - if not A: - return [] - - result = [] - if A[0] != lower: - end = A[0] - 1 - if end == lower: - m_r = str(lower) - else: - m_r = str(lower) + ""->"" + str(end) - result.append(m_r) - - for index in range(1, len(A)): - if A[index] != A[index-1] + 1: - start = A[index-1] + 1 - end = A[index] - 1 - if start == end: - m_r = str(start) - else: - m_r = str(start) + ""->"" + str(end) - result.append(m_r) - - if A[len(A) - 1] != upper: - start = A[len(A)-1] + 1 - if start == upper: - m_r = str(start) - else: - m_r = str(start) + ""->"" + str(upper) - result.append(m_r) - return result","def sample_funcname ( var_0 , var_1 , var_2 ) : - if not var_0 : - return [ ] - var_3 = [ ] - if var_0 [ 0 ] != var_1 : - var_6 = var_0 [ 0 ] - 1 - if var_6 == var_1 : - var_8 = str ( var_1 ) - else : - var_8 = str ( var_1 ) + ""->"" + str ( var_6 ) - var_3.append ( var_8 ) - for var_13 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_13 ] != var_0 [ var_13 - 1 ] + 1 : - var_14 = var_0 [ var_13 - 1 ] + 1 - var_6 = var_0 [ var_13 ] - 1 - if var_14 == var_6 : - var_8 = str ( var_14 ) - else : - var_8 = str ( var_14 ) + ""->"" + str ( var_6 ) - var_3.append ( var_8 ) - if var_0 [ len ( var_0 ) - 1 ] != var_2 : - var_14 = var_0 [ len ( var_0 ) - 1 ] + 1 - if var_14 == var_2 : - var_8 = str ( var_14 ) - else : - var_8 = str ( var_14 ) + ""->"" + str ( var_2 ) - var_3.append ( var_8 ) - return var_3 -",10->,3 -494,83_1.py,"def deleteDuplicates( head): - if not head: - return None - - curr = head - while curr and curr.next: - if curr.val == curr.next.val: - curr.next = curr.next.next - else: - curr = curr.next - - return head","def sample_funcname ( var_0 ) : - if not var_0 : - return None - var_2 = var_0 - while var_2 and var_2.next : - if var_2.val == var_2.next.val : - var_2.next = var_2.next.next - else : - var_2 = var_2.next - return var_0 -",None,1 -495,134_1.py,"def canCompleteCircuit( gas, cost): - start, curr_sum, total_sum =0, 0, 0 - for index in range(len(gas)): - diff = gas[index] - cost[index] - total_sum += diff - curr_sum += diff - - if curr_sum < 0: - start = index + 1 - curr_sum = 0 - - if total_sum >= 0: - return start - return -1","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 , var_5 = 0 , 0 , 0 - for var_8 in range ( len ( var_0 ) ) : - var_9 = var_0 [ var_8 ] - var_1 [ var_8 ] - var_5 += var_9 - var_4 += var_9 - if var_4 < 0 : - var_3 = var_8 + 1 - var_4 = 0 - if var_5 >= 0 : - return var_3 - return - 1 -",10,2 -496,289_1.py,"def around(i, j, board): - count = 0 - for k in range(i-1, i+2): - for l in range(j-1, j+2): - if 0<=k < len(board) and 0 <= l < len(board[0]): - if board[k][l] == 1: - count += 1 - - return count-1 if board[i][j] == 1 else count","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_4 = 0 - for var_8 in range ( var_0 - 1 , var_0 + 2 ) : - for var_9 in range ( var_1 - 1 , var_1 + 2 ) : - if 0 <= var_8 < len ( var_2 ) and 0 <= var_9 < len ( var_2 [ 0 ] ) : - if var_2 [ var_8 ] [ var_9 ] == 1 : - var_4 += 1 - return var_4 - 1 if var_2 [ var_0 ] [ var_1 ] == 1 else var_4 -",102,3 -498,118_1.py,"def generate( numRows): - triangle = [] - - for row in range(numRows): - new_row = [0 for _ in range(row+1)] - new_row[0], new_row[-1] = 1, 1 - - for col in range(1, len(new_row)-1): - new_row[col] = triangle[row-1][col-1] + triangle[row-1][col] - triangle.append(new_row) - return triangle","def sample_funcname ( var_0 ) : - var_1 = [ ] - for var_3 in range ( var_0 ) : - var_7 = [ 0 for var_4 in range ( var_3 + 1 ) ] - var_7 [ 0 ] , var_7 [ - 1 ] = 1 , 1 - for var_9 in range ( 1 , len ( var_7 ) - 1 ) : - var_7 [ var_9 ] = var_1 [ var_3 - 1 ] [ var_9 - 1 ] + var_1 [ var_3 - 1 ] [ var_9 ] - var_1.append ( var_7 ) - return var_1 -",10,2 -499,1087_1.py,"def permute( S): - if not S: - return [] - if '{' not in S: - return [S] - stack, stack2 = [], [] - brace = 0 - for char in S: - if char == '{': - brace = 1 - elif char == '}': - if not stack: - stack = stack2 - else: - new_stack = [] - for char in stack: - for char2 in stack2: - new_stack.append(char + char2) - - stack = new_stack - stack2 = [] - brace = 2 - elif char != ',': - if brace == 1: - stack2.append(char) - elif brace == 2: - stack = [c + char for c in stack] - stack2 = [] - else: - stack.append(char) - - stack.sort() - stack.sort(key = len) - return stack","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - if '{' not in var_0 : - return [ var_0 ] - var_2 , var_3 = [ ] , [ ] - var_5 = 0 - for var_6 in var_0 : - if var_6 == '{' : - var_5 = 1 - elif var_6 == '}' : - if not var_2 : - var_2 = var_3 - else : - var_9 = [ ] - for var_6 in var_2 : - for var_10 in var_3 : - var_9.append ( var_6 + var_10 ) - var_2 = var_9 - var_3 = [ ] - var_5 = 2 - elif var_6 != ',' : - if var_5 == 1 : - var_3.append ( var_6 ) - elif var_5 == 2 : - var_2 = [ var_14 + var_6 for var_14 in var_2 ] - var_3 = [ ] - else : - var_2.append ( var_6 ) - var_2.sort ( ) - var_2.sort ( var_16 = len ) - return var_2 -",",02{1}",6 -500,117_2.py,"def getNext( node): - node = node.next - while node: - if node.left: - return node.left - if node.right: - return node.right - node = node.next - return None","def sample_funcname ( var_0 ) : - var_0 = var_0.next - while var_0 : - if var_0.left : - return var_0.left - if var_0.right : - return var_0.right - var_0 = var_0.next - return None -",None,1 -501,159_1.py,"def lengthOfLongestSubstringTwoDistinct( s): - if not s: - return 0 - - unique_char, start, result = {}, 0, 0 - for index, char in enumerate(s): - if char in unique_char: - unique_char[s] += 1 - else: - unique_char[s] = 1 - - if len(unique_char) <= 2: - result = max(result, index-start+1) - else: - while len(unique_char) > 2: - char_index = s[start] - count = unique_char[char_index] - if count == 1: - del unique_char[char_index] - else: - unique_char[char_index] -= 1 - start += 1 - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_2 , var_3 , var_4 = { } , 0 , 0 - for var_6 , var_7 in enumerate ( var_0 ) : - if var_7 in var_2 : - var_2 [ var_0 ] += 1 - else : - var_2 [ var_0 ] = 1 - if len ( var_2 ) <= 2 : - var_4 = max ( var_4 , var_6 - var_3 + 1 ) - else : - while len ( var_2 ) > 2 : - var_12 = var_0 [ var_3 ] - var_13 = var_2 [ var_12 ] - if var_13 == 1 : - del var_2 [ var_12 ] - else : - var_2 [ var_12 ] -= 1 - var_3 += 1 - return var_4 -",102,3 -502,1029_1.py,"def twoCitySchedCost( costs): - result = 0 - costs = sorted(costs, key=lambda x : x[0] - x[1]) - for index in range(len(costs)): - if index < len(costs)//2: - result += costs[index][0] - else: - result += costs[index][1] - return result","def sample_funcname ( var_0 ) : - var_2 = 0 - var_0 = sorted ( var_0 , var_4 = lambda var_5 : var_5 [ 0 ] - var_5 [ 1 ] ) - for var_9 in range ( len ( var_0 ) ) : - if var_9 < len ( var_0 ) // 2 : - var_2 += var_0 [ var_9 ] [ 0 ] - else : - var_2 += var_0 [ var_9 ] [ 1 ] - return var_2 -",102,3 -503,1051_1.py,"def heightChecker( heights): - result = 0 - for new_h, hei in zip(heights, sorted(heights)): - if new_h != hei: - result += 1 - return result","def sample_funcname ( var_0 ) : - var_2 = 0 - for var_4 , var_6 in zip ( var_0 , sorted ( var_0 ) ) : - if var_4 != var_6 : - var_2 += 1 - return var_2 -",10,2 -504,199_1.py,"def rightSideView( root): - if not root: - return [] - - stack, node_depth = [(root, 0)], {} - - while stack: - node, depth = stack.pop(0) - if depth not in node_depth: - node_depth[depth] = node.val - - if node.right: - stack.append((node.right, depth+1)) - if node.left: - stack.append((node.left, depth+1)) - return node_depth.values()","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - var_2 , var_3 = [ ( var_0 , 0 ) ] , { } - while var_2 : - var_5 , var_6 = var_2.pop ( 0 ) - if var_6 not in var_3 : - var_3 [ var_6 ] = var_5.val - if var_5.right : - var_2.append ( ( var_5.right , var_6 + 1 ) ) - if var_5.left : - var_2.append ( ( var_5.left , var_6 + 1 ) ) - return var_3.values ( ) -",10,2 -506,38_1.py,"def countAndSay( n): - if n == 1: - return ""1"" - new_num = """" - count_iter = 1 - num = ""1"" - - while count_iter < n: - index_i, index_j = 0, 0 - count, new_num = 0, """" - - while index_j < len(num): - if num[index_i] != num[index_j]: - new_num += str(count) + str(num[index_i]) - count = 0 - index_i = index_j - else: - count += 1 - index_j += 1 - - if count > 0: - new_num += str(count) + str(num[index_i]) - num = new_num - count_iter += 1 - - return new_num","def sample_funcname ( var_0 ) : - if var_0 == 1 : - return ""1"" - var_4 = """" - var_5 = 1 - var_6 = ""1"" - while var_5 < var_0 : - var_8 , var_9 = 0 , 0 - var_10 , var_4 = 0 , """" - while var_9 < len ( var_6 ) : - if var_6 [ var_8 ] != var_6 [ var_9 ] : - var_4 += str ( var_10 ) + str ( var_6 [ var_8 ] ) - var_10 = 0 - var_8 = var_9 - else : - var_10 += 1 - var_9 += 1 - if var_10 > 0 : - var_4 += str ( var_10 ) + str ( var_6 [ var_8 ] ) - var_6 = var_4 - var_5 += 1 - return var_4 -",110,4 -507,1010_1.py,"def numPairsDivisibleBy60( time): - count_arr = [0]*60 - result = 0 - for t in time: - remainder = t%60 - complement = (60-remainder)%60 - result += count_arr[complement] - count_arr[remainder] += 1 - return result","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * 60 - var_4 = 0 - for var_5 in var_0 : - var_6 = var_5 % 60 - var_7 = ( 60 - var_6 ) % 60 - var_4 += var_3 [ var_7 ] - var_3 [ var_6 ] += 1 - return var_4 -",6001,3 -508,926_1.py,"def minFlipsMonoIncr( S): - ones = [0] - for char in S: - ones.append(ones[-1] + int(char)) - result = float('inf') - for index in range(len(ones)): - zeroes = len(S) - index - (ones[-1]-ones[index]) - result = min(zeroes+ones[index], result) - return result","def sample_funcname ( var_0 ) : - var_2 = [ 0 ] - for var_3 in var_0 : - var_2.append ( var_2 [ - 1 ] + int ( var_3 ) ) - var_9 = float ( 'inf' ) - for var_12 in range ( len ( var_2 ) ) : - var_13 = len ( var_0 ) - var_12 - ( var_2 [ - 1 ] - var_2 [ var_12 ] ) - var_9 = min ( var_13 + var_2 [ var_12 ] , var_9 ) - return var_9 -",10inf,3 -509,4_1.py,"def findMedianSortedArrays( nums1, nums2): - if len(nums1) > len(nums2): - nums1, nums2 = nums2, nums1 - - x, y = len(nums1), len(nums2) - low , high = 0, x - - while low <= high: - partitionx = (low+high)/2 - partitiony = (x+y+1)/2 - partitionx - if partitionx == 0: - maxLeftX = float('-inf') - else: - maxLeftX = nums1[partitionx-1] - - if partitionx == x: - minRightX = float('inf') - else: - minRightX = nums1[partitionx] - - if partitiony == 0: - maxLeftY = float('-inf') - else: - maxLeftY = nums2[partitiony-1] - - if partitiony == y: - minRightY = float('inf') - else: - minRightY = nums2[partitiony] - - if maxLeftX <= minRightY and maxLeftY <= minRightX: - if((x+y)%2 == 0): - return (max(maxLeftX, maxLeftY) + min(minRightX, minRightY))/2.0 - else: - return max(maxLeftY, maxLeftX) - elif maxLeftX > minRightY: - high = partitionx - 1 - else: - low = partitionx + 1","def sample_funcname ( var_0 , var_1 ) : - if len ( var_0 ) > len ( var_1 ) : - var_0 , var_1 = var_1 , var_0 - var_3 , var_4 = len ( var_0 ) , len ( var_1 ) - var_6 , var_7 = 0 , var_3 - while var_6 <= var_7 : - var_9 = ( var_6 + var_7 ) / 2 - var_11 = ( var_3 + var_4 + 1 ) / 2 - var_9 - if var_9 == 0 : - var_14 = float ( '-inf' ) - else : - var_14 = var_0 [ var_9 - 1 ] - if var_9 == var_3 : - var_16 = float ( 'inf' ) - else : - var_16 = var_0 [ var_9 ] - if var_11 == 0 : - var_17 = float ( '-inf' ) - else : - var_17 = var_1 [ var_11 - 1 ] - if var_11 == var_4 : - var_18 = float ( 'inf' ) - else : - var_18 = var_1 [ var_11 ] - if var_14 <= var_18 and var_17 <= var_16 : - if ( ( var_3 + var_4 ) % 2 == 0 ) : - return ( max ( var_14 , var_17 ) + min ( var_16 , var_18 ) ) / 2.0 - else : - return max ( var_17 , var_14 ) - elif var_14 > var_18 : - var_7 = var_9 - 1 - else : - var_6 = var_9 + 1 -",02.0-infinf21,6 -510,80_1.py,"def removeDuplicates( nums): - if len(nums) <= 2: - return len(nums) - - prev, curr = 1, 2 - - while curr < len(nums): - if nums[prev] == nums[curr] and nums[curr] == nums[prev-1]: - curr += 1 - else: - prev += 1 - nums[prev] = nums[curr] - curr += 1 - return prev+1","def sample_funcname ( var_0 ) : - if len ( var_0 ) <= 2 : - return len ( var_0 ) - var_4 , var_5 = 1 , 2 - while var_5 < len ( var_0 ) : - if var_0 [ var_4 ] == var_0 [ var_5 ] and var_0 [ var_5 ] == var_0 [ var_4 - 1 ] : - var_5 += 1 - else : - var_4 += 1 - var_0 [ var_4 ] = var_0 [ var_5 ] - var_5 += 1 - return var_4 + 1 -",12,2 -511,1047_1.py,"def removeDuplicates( S): - stack = [] - if not S: - return """" - for char in S: - if not stack: - stack.append(char) - else: - first = stack[-1] - if first == char: - stack.pop() - else: - stack.append(char) - if not stack: - return """" - return ''.join(stack)","def sample_funcname ( var_0 ) : - var_1 = [ ] - if not var_0 : - return """" - for var_3 in var_0 : - if not var_1 : - var_1.append ( var_3 ) - else : - var_6 = var_1 [ - 1 ] - if var_6 == var_3 : - var_1.pop ( ) - else : - var_1.append ( var_3 ) - if not var_1 : - return """" - return ''.join ( var_1 ) -",1,3 -512,14_1.py,"def prefix(strs, index): - check_prefix = strs[0][:index] - for index in range(1, len(strs)): - if not strs[index].startswith(check_prefix): - return False - return True","def sample_funcname ( var_0 , var_1 ) : - var_3 = var_0 [ 0 ] [ : var_1 ] - for var_1 in range ( 1 , len ( var_0 ) ) : - if not var_0 [ var_1 ].startswith ( var_3 ) : - return False - return True -",10,2 -513,674_1.py,"def findLengthOfLCIS( nums): - if not nums: - return 0 - start, result = 0, 1 - for end in range(1, len(nums)): - if nums[end-1] >= nums[end]: - start = end - result = max(result, end-start+1) - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_2 , var_4 = 0 , 1 - for var_7 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_7 - 1 ] >= var_0 [ var_7 ] : - var_2 = var_7 - var_4 = max ( var_4 , var_7 - var_2 + 1 ) - return var_4 -",10,2 -514,361_1.py,"def maxKilledEnemies( grid): - if not grid or len(grid) == 0 or len(grid[0]) == 0: - return 0 - - result, row_count = float('-inf'), 0 - column_count = [0]*len(grid[0]) - for row in range(len(grid)): - for column in range(len(grid[0])): - if column == 0 or grid[row][column-1] == 'W': - row_count = 0 - for index in range(column, len(grid[0])): - if grid[row][index] == 'W': - break - row_count += 1 if grid[row][index] == 'E' else 0 - - if row == 0 or grid[row-1][column] == 'W': - column_count[column] = 0 - for index in range(row, len(grid)): - if grid[index][column] == 'W': - break - column_count[column] += 1 if grid[index][column] == 'E' else 0 - - if grid[row][column] == '0': - result = max(result, row_count + column_count[column]) - return result","def sample_funcname ( var_0 ) : - if not var_0 or len ( var_0 ) == 0 or len ( var_0 [ 0 ] ) == 0 : - return 0 - var_5 , var_6 = float ( '-inf' ) , 0 - var_7 = [ 0 ] * len ( var_0 [ 0 ] ) - for var_9 in range ( len ( var_0 ) ) : - for var_10 in range ( len ( var_0 [ 0 ] ) ) : - if var_10 == 0 or var_0 [ var_9 ] [ var_10 - 1 ] == 'W' : - var_6 = 0 - for var_13 in range ( var_10 , len ( var_0 [ 0 ] ) ) : - if var_0 [ var_9 ] [ var_13 ] == 'W' : - break - var_6 += 1 if var_0 [ var_9 ] [ var_13 ] == 'E' else 0 - if var_9 == 0 or var_0 [ var_9 - 1 ] [ var_10 ] == 'W' : - var_7 [ var_10 ] = 0 - for var_13 in range ( var_9 , len ( var_0 ) ) : - if var_0 [ var_13 ] [ var_10 ] == 'W' : - break - var_7 [ var_10 ] += 1 if var_0 [ var_13 ] [ var_10 ] == 'E' else 0 - if var_0 [ var_9 ] [ var_10 ] == '0' : - var_5 = max ( var_5 , var_6 + var_7 [ var_10 ] ) - return var_5 -",0-infE01W,6 -515,1092_1.py,"def lcs(A, B): - n, m = len(A)+1, len(B)+1 - dp = [["""" for _ in range(m)] for _ in range(n)] - for index_i in range(1, n): - for index_j in range(1, m): - if A[index_i-1] == B[index_j-1]: - dp[index_i][index_j] = dp[index_i-1][index_j-1] + A[index_i - 1] - else: - dp[index_i][index_j] = max(dp[index_i-1][index_j], dp[index_i][index_j-1], key=len) - return dp[-1][-1]","def sample_funcname ( var_0 , var_1 ) : - var_4 , var_5 = len ( var_0 ) + 1 , len ( var_1 ) + 1 - var_9 = [ [ """" for var_7 in range ( var_5 ) ] for var_7 in range ( var_4 ) ] - for var_10 in range ( 1 , var_4 ) : - for var_11 in range ( 1 , var_5 ) : - if var_0 [ var_10 - 1 ] == var_1 [ var_11 - 1 ] : - var_9 [ var_10 ] [ var_11 ] = var_9 [ var_10 - 1 ] [ var_11 - 1 ] + var_0 [ var_10 - 1 ] - else : - var_9 [ var_10 ] [ var_11 ] = max ( var_9 [ var_10 - 1 ] [ var_11 ] , var_9 [ var_10 ] [ var_11 - 1 ] , var_12 = len ) - return var_9 [ - 1 ] [ - 1 ] -",1,2 -516,75_1.py,"def sortColors( nums): - zero, last = 0, len(nums)-1 - index = 0 - while index <= last: - if nums[index] == 1: - index += 1 - elif nums[index] == 0: - nums[index], nums[zero] = nums[zero], nums[index] - index += 1 - zero += 1 - elif nums[index] == 2: - nums[last], nums[index] = nums[index], nums[last] - last -= 1","def sample_funcname ( var_0 ) : - var_2 , var_5 = 0 , len ( var_0 ) - 1 - var_6 = 0 - while var_6 <= var_5 : - if var_0 [ var_6 ] == 1 : - var_6 += 1 - elif var_0 [ var_6 ] == 0 : - var_0 [ var_6 ] , var_0 [ var_2 ] = var_0 [ var_2 ] , var_0 [ var_6 ] - var_6 += 1 - var_2 += 1 - elif var_0 [ var_6 ] == 2 : - var_0 [ var_5 ] , var_0 [ var_6 ] = var_0 [ var_6 ] , var_0 [ var_5 ] - var_5 -= 1 -",102,3 -518,253_1.py,"def minMeetingRooms( intervals): - if not intervals or len(intervals) == 0: - return 0 - - import heapq - - sorted_intervals = sorted(intervals, key=lambda it:(it.start, it.end)) - heap, result = [], 0 - - for interval in sorted_intervals: - start, end = interval.start, interval.end - - while heap and heap[0] <= start: - heapq.heappop(heap) - - heapq.heappush(heap, end) - - result = max(result, len(heap)) - return result","def sample_funcname ( var_0 ) : - if not var_0 or len ( var_0 ) == 0 : - return 0 - import var_3 - var_9 = sorted ( var_0 , var_5 = lambda var_6 : ( var_6.start , var_6.end ) ) - var_10 , var_11 = [ ] , 0 - for var_12 in var_9 : - start , end = var_12.start , var_12.end - while var_10 and var_10 [ 0 ] <= start : - var_3.heappop ( var_10 ) - var_3.heappush ( var_10 , end ) - var_11 = max ( var_11 , len ( var_10 ) ) - return var_11 -",0,1 -519,1266_1.py,"def minTimeToVisitAllPoints( points): - if not points: - return 0 - result = 0 - for index in range(1, len(points)): - result += max(abs(points[index][0]-points[index-1][0]), abs(points[index][1]-points[index-1][1])) - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_2 = 0 - for var_6 in range ( 1 , len ( var_0 ) ) : - var_2 += max ( abs ( var_0 [ var_6 ] [ 0 ] - var_0 [ var_6 - 1 ] [ 0 ] ) , abs ( var_0 [ var_6 ] [ 1 ] - var_0 [ var_6 - 1 ] [ 1 ] ) ) - return var_2 -",10,2 -520,34_1.py,"def searchRange( nums, target): - left, right = 0, len(nums)-1 - - while left <= right: - mid = (left + right) / 2 - if target > nums[mid]: - left = mid + 1 - else: - right = mid - - if left == len(nums) or nums[left] != target: - return [-1, -1] - - result = [left] - left, right = 0, len(nums) -1 - while left <= right: - mid = (left + right) / 2 - if nums[mid] > target: - right = mid - else: - left = mid + 1 - - result.append(left + 1) - return result","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_6 = 0 , len ( var_0 ) - 1 - while var_3 <= var_6 : - var_8 = ( var_3 + var_6 ) / 2 - if var_1 > var_0 [ var_8 ] : - var_3 = var_8 + 1 - else : - var_6 = var_8 - if var_3 == len ( var_0 ) or var_0 [ var_3 ] != var_1 : - return [ - 1 , - 1 ] - var_9 = [ var_3 ] - var_3 , var_6 = 0 , len ( var_0 ) - 1 - while var_3 <= var_6 : - var_8 = ( var_3 + var_6 ) / 2 - if var_0 [ var_8 ] > var_1 : - var_6 = var_8 - else : - var_3 = var_8 + 1 - var_9.append ( var_3 + 1 ) - return var_9 -",102,3 -521,300_1.py,"def lengthOfLIS( nums): - if len(nums) <= 1: - return len(nums) - - count = [0 for _ in range(len(nums))] - result = 1 - count[0] = nums[0] - - for index in range(1, len(nums)): - if nums[index] < count[0]: - count[0] = nums[index] - elif nums[index] > count[result-1]: - count[result] = nums[index] - result += 1 - else: - left, right = -1, result-1 - while (right-left > 1): - mid = (left+right)/2 - if count[mid] >= nums[index]: - right = mid - else: - left = mid - count[right] = nums[index] - - return result","def sample_funcname ( var_0 ) : - if len ( var_0 ) <= 1 : - return len ( var_0 ) - var_6 = [ 0 for var_4 in range ( len ( var_0 ) ) ] - var_7 = 1 - var_6 [ 0 ] = var_0 [ 0 ] - for var_8 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_8 ] < var_6 [ 0 ] : - var_6 [ 0 ] = var_0 [ var_8 ] - elif var_0 [ var_8 ] > var_6 [ var_7 - 1 ] : - var_6 [ var_7 ] = var_0 [ var_8 ] - var_7 += 1 - else : - var_9 , var_10 = - 1 , var_7 - 1 - while ( var_10 - var_9 > 1 ) : - var_12 = ( var_9 + var_10 ) / 2 - if var_6 [ var_12 ] >= var_0 [ var_8 ] : - var_10 = var_12 - else : - var_9 = var_12 - var_6 [ var_10 ] = var_0 [ var_8 ] - return var_7 -",102,3 -522,63_1.py,"def uniquePathsWithObstacles( obstacleGrid): - m, n = len(obstacleGrid), len(obstacleGrid[0]) - dp = [[0 for _ in range(n)] for _ in range(m)] - - if obstacleGrid[0][0] == 1 or obstacleGrid[m-1][n-1] == 1: - return 0 - - dp[0][0] = 1 - for index in range(1, m): - if obstacleGrid[index][0] == 1: - dp[index][0] = 0 - else: - dp[index][0] = dp[index-1][0] - - for index in range(1, n): - if obstacleGrid[0][index] == 1: - dp[0][index] = 0 - else: - dp[0][index] = dp[0][index-1] - - for index_i in range(1, m): - for index_j in range(1, n): - if obstacleGrid[index_i][index_j] == 1: - dp[index_i][index_j] = 0 - else: - dp[index_i][index_j] = dp[index_i-1][index_j] + dp[index_i][index_j-1] - - return dp[m-1][n-1]","def sample_funcname ( var_0 ) : - var_2 , var_4 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_7 = [ [ 0 for var_5 in range ( var_4 ) ] for var_5 in range ( var_2 ) ] - if var_0 [ 0 ] [ 0 ] == 1 or var_0 [ var_2 - 1 ] [ var_4 - 1 ] == 1 : - return 0 - var_7 [ 0 ] [ 0 ] = 1 - for var_9 in range ( 1 , var_2 ) : - if var_0 [ var_9 ] [ 0 ] == 1 : - var_7 [ var_9 ] [ 0 ] = 0 - else : - var_7 [ var_9 ] [ 0 ] = var_7 [ var_9 - 1 ] [ 0 ] - for var_9 in range ( 1 , var_4 ) : - if var_0 [ 0 ] [ var_9 ] == 1 : - var_7 [ 0 ] [ var_9 ] = 0 - else : - var_7 [ 0 ] [ var_9 ] = var_7 [ 0 ] [ var_9 - 1 ] - for var_10 in range ( 1 , var_2 ) : - for var_11 in range ( 1 , var_4 ) : - if var_0 [ var_10 ] [ var_11 ] == 1 : - var_7 [ var_10 ] [ var_11 ] = 0 - else : - var_7 [ var_10 ] [ var_11 ] = var_7 [ var_10 - 1 ] [ var_11 ] + var_7 [ var_10 ] [ var_11 - 1 ] - return var_7 [ var_2 - 1 ] [ var_4 - 1 ] -",10,2 -524,1030_1.py,"def allCellsDistOrder( R, C, r0, c0): - cells = [[x, y] for x in range(R) for y in range(C)] - distance = {} - for cell in cells: - diff = abs(cell[0]-r0) + abs(cell[1]-c0) - if diff in distance: - distance[diff].append(cell) - else: - distance[diff] = [cell] - result = [] - for key in sorted(distance): - for value in distance[key]: - result.append(value) - return result","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - var_7 = [ [ var_4 , var_5 ] for var_4 in range ( var_0 ) for var_5 in range ( var_1 ) ] - var_8 = { } - for var_9 in var_7 : - var_13 = abs ( var_9 [ 0 ] - var_2 ) + abs ( var_9 [ 1 ] - var_3 ) - if var_13 in var_8 : - var_8 [ var_13 ].append ( var_9 ) - else : - var_8 [ var_13 ] = [ var_9 ] - var_15 = [ ] - for var_17 in sorted ( var_8 ) : - for var_18 in var_8 [ var_17 ] : - var_15.append ( var_18 ) - return var_15 -",10,2 -525,18_1.py,"def fourSum( nums, target): - sumMapping = {} - for index_i in range(len(nums)-1): - for index_j in range(index_i+1, len(nums)): - currSum = nums[index_i] + nums[index_j] - if currSum in sumMapping: - sumMapping[currSum].append((index_i, index_j)) - else: - sumMapping[currSum] = [(index_i, index_j)] - - result = set() - for key, value in sumMapping.iteritems(): - diff = target - key - if diff in sumMapping: - firstSet = value - secondSet = sumMapping[diff] - - for (i, j) in firstSet: - for (k, l) in secondSet: - fourlet = [i, j, k, l] - if len(set(fourlet)) != len(fourlet): - continue - fourlist = [nums[i], nums[j], nums[k], nums[l]] - fourlist.sort() - result.add(tuple(fourlist)) - - return list(result)","def sample_funcname ( var_0 , var_1 ) : - var_2 = { } - for var_6 in range ( len ( var_0 ) - 1 ) : - for var_7 in range ( var_6 + 1 , len ( var_0 ) ) : - var_8 = var_0 [ var_6 ] + var_0 [ var_7 ] - if var_8 in var_2 : - var_2 [ var_8 ].append ( ( var_6 , var_7 ) ) - else : - var_2 [ var_8 ] = [ ( var_6 , var_7 ) ] - var_11 = set ( ) - for var_13 , var_14 in var_2.iteritems ( ) : - var_15 = var_1 - var_13 - if var_15 in var_2 : - var_16 = var_14 - var_17 = var_2 [ var_15 ] - for ( var_18 , var_19 ) in var_16 : - for ( var_20 , var_21 ) in var_17 : - var_22 = [ var_18 , var_19 , var_20 , var_21 ] - if len ( set ( var_22 ) ) != len ( var_22 ) : - continue - var_23 = [ var_0 [ var_18 ] , var_0 [ var_19 ] , var_0 [ var_20 ] , var_0 [ var_21 ] ] - var_23.sort ( ) - var_11.add ( tuple ( var_23 ) ) - return list ( var_11 ) -",1,1 -526,140_1.py,"def check( s, wordDict): - dp = [False for _ in range(len(s)+1)] - dp[0] = True - - for i in range(len(s)): - for j in range(i, -1, -1): - if dp[j] and s[j:i+1] in wordDict: - dp[i+1] = True - break - - return dp[len(s)]","def sample_funcname ( var_0 , var_1 ) : - var_7 = [ False for var_3 in range ( len ( var_0 ) + 1 ) ] - var_7 [ 0 ] = True - for var_10 in range ( len ( var_0 ) ) : - for var_11 in range ( var_10 , - 1 , - 1 ) : - if var_7 [ var_11 ] and var_0 [ var_11 : var_10 + 1 ] in var_1 : - var_7 [ var_10 + 1 ] = True - break - return var_7 [ len ( var_0 ) ] -",10,2 -527,117_1.py,"def connect( root): - if root == None: - return - queue = [root] - queue.append(None) - - while queue: - front = queue.pop(0) - if front is not None: - front.next = queue[0] - if front.left: - queue.append(front.left) - if front.right: - queue.append(front.right) - elif queue: - queue.append(None)","def sample_funcname ( var_0 ) : - if var_0 == None : - return - var_2 = [ var_0 ] - var_2.append ( None ) - while var_2 : - var_6 = var_2.pop ( 0 ) - if var_6 is not None : - var_6.next = var_2 [ 0 ] - if var_6.left : - var_2.append ( var_6.left ) - if var_6.right : - var_2.append ( var_6.right ) - elif var_2 : - var_2.append ( None ) -",0None,2 -528,1071_1.py,"def gcdOfStrings( str1, str2): - if len(str1) > len(str2): - str1, str2 = str2, str1 - - l_str1 = len(str1) - for index in range(1, len(str1)+1): - if l_str1%index != 0: - continue - - size_to_take = int(l_str1/index) - substr1 = str1[:size_to_take] - substr2 = str2 - - while substr1 == substr2[:size_to_take]: - substr2 = substr2[size_to_take:] - - if substr2 == """": - return substr1 - return """"","def sample_funcname ( var_0 , var_1 ) : - if len ( var_0 ) > len ( var_1 ) : - var_0 , var_1 = var_1 , var_0 - var_3 = len ( var_0 ) - for var_6 in range ( 1 , len ( var_0 ) + 1 ) : - if var_3 % var_6 != 0 : - continue - var_9 = int ( var_3 / var_6 ) - var_10 = var_0 [ : var_9 ] - var_11 = var_1 - while var_10 == var_11 [ : var_9 ] : - var_11 = var_11 [ var_9 : ] - if var_11 == """" : - return var_10 - return """" -",10,3 -529,101_1.py,"def dfs(left, right): - if not left and not right: - return True - - if not left or not right: - return False - return (left.val == right.val) and dfs(left.left, right.right) and dfs(left.right, right.left)","def sample_funcname ( left , right ) : - if not left and not right : - return True - if not left or not right : - return False - return ( left.val == right.val ) and var_0 ( left.left , right.right ) and var_0 ( left.right , right.left ) -",,0 -530,1026_1.py,"def utility_fun(root, res): - if not root: - return 2147483648, -2147483648, res - if not root.left and not root.right: - return root.val, root.val, res - left_t, lmax_t, res = utility_fun(root.left, res) - right_t, rmax_t, res = utility_fun(root.right, res) - m_val = min(left_t, right_t) - max_val = max(lmax_t, rmax_t) - - res = max(res, max(abs(root.val-m_val), abs(root.val-max_val))) - return min(m_val, root.val), max(max_val, root.val), res","def sample_funcname ( var_1 , var_2 ) : - if not var_1 : - return 2147483648 , - 2147483648 , var_2 - if not var_1.left and not var_1.right : - return var_1.val , var_1.val , var_2 - var_7 , var_8 , var_2 = var_0 ( var_1.left , var_2 ) - var_9 , var_10 , var_2 = var_0 ( var_1.right , var_2 ) - var_12 = min ( var_7 , var_9 ) - var_14 = max ( var_8 , var_10 ) - var_2 = max ( var_2 , max ( abs ( var_1.val - var_12 ) , abs ( var_1.val - var_14 ) ) ) - return min ( var_12 , var_1.val ) , max ( var_14 , var_1.val ) , var_2 -",2147483648,1 -531,442_1.py,"def findDuplicates( nums): - if not nums: - return [] - - result = [] - for _, num in enumerate(nums): - index = abs(num)-1 - if nums[index] < 0: - result.append(index+1) - nums[index]*=-1 - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - var_1 = [ ] - for var_3 , var_4 in enumerate ( var_0 ) : - var_7 = abs ( var_4 ) - 1 - if var_0 [ var_7 ] < 0 : - var_1.append ( var_7 + 1 ) - var_0 [ var_7 ] *= - 1 - return var_1 -",10,2 -532,1027_1.py,"def longestArithSeqLength( A): - from collections import defaultdict - - dp = defaultdict(int) - for index_i in range(len(A)): - for index_j in range(index_i): - diff = A[index_i] - A[index_j] - dp[(index_i, diff)] = max(dp[(index_i, diff)], dp[(index_j, diff)]+1) - return max(dp.itervalues())+1","def sample_funcname ( var_0 ) : - from var_1 import var_2 - var_4 = var_2 ( int ) - for var_7 in range ( len ( var_0 ) ) : - for var_8 in range ( var_7 ) : - var_9 = var_0 [ var_7 ] - var_0 [ var_8 ] - var_4 [ ( var_7 , var_9 ) ] = max ( var_4 [ ( var_7 , var_9 ) ] , var_4 [ ( var_8 , var_9 ) ] + 1 ) - return max ( var_4.itervalues ( ) ) + 1 -",1,1 -533,100_1.py,"def isSameTree( p, q): - if not p and not q: - return True - - stack = [(p, q)] - - while stack: - node1, node2 = stack.pop() - if node1 and node2 and node1.val == node2.val: - stack.append((node1.left, node2.left)) - stack.append((node1.right, node2.right)) - else: - if not node1 == node2: - return False - - return True","def sample_funcname ( var_0 , var_1 ) : - if not var_0 and not var_1 : - return True - var_3 = [ ( var_0 , var_1 ) ] - while var_3 : - var_5 , var_6 = var_3.pop ( ) - if var_5 and var_6 and var_5.val == var_6.val : - var_3.append ( ( var_5.left , var_6.left ) ) - var_3.append ( ( var_5.right , var_6.right ) ) - else : - if not var_5 == var_6 : - return False - return True -",,0 -534,1089_1.py,"def duplicateZeros( arr): - arr_copy = arr[:] - index, n = 0, len(arr_copy) - for elem in arr_copy: - arr[index] = elem - index += 1 - if index >= n: - break - if elem == 0: - arr[index] = elem - index += 1 - if index >= n: - break","def sample_funcname ( var_0 ) : - var_1 = var_0 [ : ] - var_3 , var_5 = 0 , len ( var_1 ) - for var_6 in var_1 : - var_0 [ var_3 ] = var_6 - var_3 += 1 - if var_3 >= var_5 : - break - if var_6 == 0 : - var_0 [ var_3 ] = var_6 - var_3 += 1 - if var_3 >= var_5 : - break -",10,2 -535,116_1.py,"def recursive(node): - if node is None: - return - - if node.left: - node.left.next = node.right - if node.right: - if node.next: - node.right.next = node.next.left - else: - node.right.next = None - recursive(node.left) - recursive(node.right)","def sample_funcname ( var_1 ) : - if var_1 is None : - return - if var_1.left : - var_1.left.next = var_1.right - if var_1.right : - if var_1.next : - var_1.right.next = var_1.next.left - else : - var_1.right.next = None - var_0 ( var_1.left ) - var_0 ( var_1.right ) -",None,1 -536,268_1.py,"def missingNumber( nums): - if not nums: - return 0 - totalSum, n = sum(nums), len(nums) - expectedSum = (n*(n+1))/2 - return expectedSum - totalSum","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_3 , var_5 = sum ( var_0 ) , len ( var_0 ) - var_8 = ( var_5 * ( var_5 + 1 ) ) / 2 - return var_8 - var_3 -",102,3 -537,287_1.py,"def findDuplicate( nums): - slow, fast = nums[0], nums[0] - while True: - slow = nums[slow] - fast = nums[nums[fast]] - if slow == fast: - break - - num1= nums[0] - num2 = slow - while num1 != num2: - num1 = nums[num1] - num2 = nums[num2] - return num2","def sample_funcname ( var_0 ) : - var_2 , var_3 = var_0 [ 0 ] , var_0 [ 0 ] - while True : - var_2 = var_0 [ var_2 ] - var_3 = var_0 [ var_0 [ var_3 ] ] - if var_2 == var_3 : - break - var_5 = var_0 [ 0 ] - var_6 = var_2 - while var_5 != var_6 : - var_5 = var_0 [ var_5 ] - var_6 = var_0 [ var_6 ] - return var_6 -",0,1 -538,454_1.py,"def fourSumCount( A, B, C, D): - hashTable ={} - - for a in A: - for b in B: - if a+b in hashTable: - hashTable[a+b] += 1 - else: - hashTable[a+b] = 1 - - result = 0 - for c in C: - for d in D: - if -(c+d) in hashTable: - result += hashTable[-(c+d)] - return result","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - var_4 = { } - for var_5 in var_0 : - for var_6 in var_1 : - if var_5 + var_6 in var_4 : - var_4 [ var_5 + var_6 ] += 1 - else : - var_4 [ var_5 + var_6 ] = 1 - var_9 = 0 - for var_10 in var_2 : - for var_11 in var_3 : - if - ( var_10 + var_11 ) in var_4 : - var_9 += var_4 [ - ( var_10 + var_11 ) ] - return var_9 -",10,2 -539,19_1.py,"def removeNthFromEnd( head, n): - if not head: - return None - - ref = head - while n > 0: - ref = ref.next - n -= 1 - - if ref is None: - return head.next - else: - main = head - while ref.next: - main = main.next - ref = ref.next - - main.next = main.next.next - return head","def sample_funcname ( var_0 , var_1 ) : - if not var_0 : - return None - var_3 = var_0 - while var_1 > 0 : - var_3 = var_3.next - var_1 -= 1 - if var_3 is None : - return var_0.next - else : - var_7 = var_0 - while var_3.next : - var_7 = var_7.next - var_3 = var_3.next - var_7.next = var_7.next.next - return var_0 -",10None,3 -540,141_1.py,"def hasCycle( head): - if not head: - return False - - slow, fast = head,head - while fast and fast.next: - slow = slow.next - fast = fast.next.next - if slow == fast: - return True - return False","def sample_funcname ( var_0 ) : - if not var_0 : - return False - var_2 , var_3 = var_0 , var_0 - while var_3 and var_3.next : - var_2 = var_2.next - var_3 = var_3.next.next - if var_2 == var_3 : - return True - return False -",,0 -541,62_1.py,"def uniquePaths( m, n): - dp = [[0 for _ in range(n)] for _ in range(m)] - for index in range(m): - dp[index][0] = 1 - - for index in range(n): - dp[0][index] = 1 - - for index_i in range(1, m): - for index_j in range(1, n): - dp[index_i][index_j] = dp[index_i-1][index_j] + dp[index_i][index_j-1] - - return dp[m-1][n-1]","def sample_funcname ( var_0 , var_1 ) : - var_5 = [ [ 0 for var_3 in range ( var_1 ) ] for var_3 in range ( var_0 ) ] - for var_6 in range ( var_0 ) : - var_5 [ var_6 ] [ 0 ] = 1 - for var_6 in range ( var_1 ) : - var_5 [ 0 ] [ var_6 ] = 1 - for var_8 in range ( 1 , var_0 ) : - for var_9 in range ( 1 , var_1 ) : - var_5 [ var_8 ] [ var_9 ] = var_5 [ var_8 - 1 ] [ var_9 ] + var_5 [ var_8 ] [ var_9 - 1 ] - return var_5 [ var_0 - 1 ] [ var_1 - 1 ] -",10,2 -542,301_1.py,"def isValid(s): - count = 0 - for char in s: - if char == '(': - count += 1 - elif char == ')': - count -= 1 - if count < 0: - return False - return (count==0)","def sample_funcname ( var_0 ) : - var_2 = 0 - for var_3 in var_0 : - if var_3 == '(' : - var_2 += 1 - elif var_3 == ')' : - var_2 -= 1 - if var_2 < 0 : - return False - return ( var_2 == 0 ) -",1(0),4 -543,162_2.py,"def findPeakElement( nums): - left = [False]*len(nums) - right = [False]*len(nums) - left[0], right[len(nums)-1] = True, True - - for index in range(1, len(nums)): - if nums[index] > nums[index-1]: - left[index] = True - - for index in range(len(nums)-2, -1, -1): - if nums[index] > nums[index+1]: - right[index] = True - - for index in range(len(left)): - if left[index] and right[index]: - return index - return -1","def sample_funcname ( var_0 ) : - var_3 = [ False ] * len ( var_0 ) - var_4 = [ False ] * len ( var_0 ) - var_3 [ 0 ] , var_4 [ len ( var_0 ) - 1 ] = True , True - for var_9 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_9 ] > var_0 [ var_9 - 1 ] : - var_3 [ var_9 ] = True - for var_9 in range ( len ( var_0 ) - 2 , - 1 , - 1 ) : - if var_0 [ var_9 ] > var_0 [ var_9 + 1 ] : - var_4 [ var_9 ] = True - for var_9 in range ( len ( var_3 ) ) : - if var_3 [ var_9 ] and var_4 [ var_9 ] : - return var_9 - return - 1 -",102,3 -544,317_1.py,"def bfs(grid, distance_reach_map, row, col): - if(row < 0 or row > len(grid) or col < 0 or col > len(grid[0])): - return - queue = [[row, col]] - qdist = [1] - - direction = [[-1, 0], [0, 1], [1, 0], [0, -1]] - while queue: - x, y = queue.pop(0) - curr_dist = qdist.pop(0) - - for dx, dy in direction: - new_x, new_y = x+dx, y+dy - if((0 <= new_x < len(grid)) and (0 <= new_y < len(grid[0])) and grid[new_x][new_y] == 0): - grid[new_x][new_y] = -1 - queue.append([new_x, new_y]) - - - temp = distance_reach_map[new_x][new_y] - dist, reach = temp[0], temp[1] - dist += curr_dist - reach += 1 - distance_reach_map[new_x][new_y] = [dist, reach] - qdist.append(curr_dist+1) - - for row in range(len(grid)): - for col in range(len(grid[0])): - if grid[row][col] == -1: - grid[row][col] =0","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - if ( var_2 < 0 or var_2 > len ( var_0 ) or var_3 < 0 or var_3 > len ( var_0 [ 0 ] ) ) : - return - var_6 = [ [ var_2 , var_3 ] ] - var_8 = [ 1 ] - var_9 = [ [ - 1 , 0 ] , [ 0 , 1 ] , [ 1 , 0 ] , [ 0 , - 1 ] ] - while var_6 : - var_11 , var_12 = var_6.pop ( 0 ) - var_13 = var_8.pop ( 0 ) - for var_14 , var_15 in var_9 : - var_16 , var_17 = var_11 + var_14 , var_12 + var_15 - if ( ( 0 <= var_16 < len ( var_0 ) ) and ( 0 <= var_17 < len ( var_0 [ 0 ] ) ) and var_0 [ var_16 ] [ var_17 ] == 0 ) : - var_0 [ var_16 ] [ var_17 ] = - 1 - var_6.append ( [ var_16 , var_17 ] ) - var_19 = var_1 [ var_16 ] [ var_17 ] - var_20 , var_21 = var_19 [ 0 ] , var_19 [ 1 ] - var_20 += var_13 - var_21 += 1 - var_1 [ var_16 ] [ var_17 ] = [ var_20 , var_21 ] - var_8.append ( var_13 + 1 ) - for var_2 in range ( len ( var_0 ) ) : - for var_3 in range ( len ( var_0 [ 0 ] ) ) : - if var_0 [ var_2 ] [ var_3 ] == - 1 : - var_0 [ var_2 ] [ var_3 ] = 0 -",10,2 -545,1267_1.py,"def countServers( grid): - if not grid: - return 0 - - row_count = [0] * len(grid) - col_count = [0] * len(grid[0]) - for index_r in range(len(grid)): - for index_c in range(len(grid[0])): - if grid[index_r][index_c] == 1: - row_count[index_r] += 1 - col_count[index_c] += 1 - - result = 0 - for index_r in range(len(grid)): - for index_c in range(len(grid[0])): - if grid[index_r][index_c] == 1 and (row_count[index_r] > 1 or col_count[index_c] > 1): - result += 1 - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_3 = [ 0 ] * len ( var_0 ) - var_4 = [ 0 ] * len ( var_0 [ 0 ] ) - for var_6 in range ( len ( var_0 ) ) : - for var_7 in range ( len ( var_0 [ 0 ] ) ) : - if var_0 [ var_6 ] [ var_7 ] == 1 : - var_3 [ var_6 ] += 1 - var_4 [ var_7 ] += 1 - var_9 = 0 - for var_6 in range ( len ( var_0 ) ) : - for var_7 in range ( len ( var_0 [ 0 ] ) ) : - if var_0 [ var_6 ] [ var_7 ] == 1 and ( var_3 [ var_6 ] > 1 or var_4 [ var_7 ] > 1 ) : - var_9 += 1 - return var_9 -",10,2 -546,340_1.py,"def lengthOfLongestSubstringKDistinct( S, K): - charMapping, start = {}, 0 - result = 0 - for end, s in enumerate(S): - if s in charMapping: - charMapping[s] += 1 - else: - charMapping[s] = 1 - - if len(charMapping) <= K: - result = max(result, end-start+1) - else: - while len(charMapping) > K : - character = S[start] - freq = charMapping[character] - if freq == 1: - del charMapping[character] - else: - charMapping[character] -= 1 - start += 1 - return result","def sample_funcname ( var_0 , var_1 ) : - var_2 , var_4 = { } , 0 - var_5 = 0 - for var_7 , var_8 in enumerate ( var_0 ) : - if var_8 in var_2 : - var_2 [ var_8 ] += 1 - else : - var_2 [ var_8 ] = 1 - if len ( var_2 ) <= var_1 : - var_5 = max ( var_5 , var_7 - var_4 + 1 ) - else : - while len ( var_2 ) > var_1 : - var_12 = var_0 [ var_4 ] - var_13 = var_2 [ var_12 ] - if var_13 == 1 : - del var_2 [ var_12 ] - else : - var_2 [ var_12 ] -= 1 - var_4 += 1 - return var_5 -",10,2 -547,985_1.py,"def sumEvenAfterQueries( A, queries): - result = 0 - for val in A: - if val%2 == 0: - result += val - - f_result = [] - for val_index in queries: - val, index = val_index[0], val_index[1] - prev_val = A[index] - if prev_val%2 == 0: - result -= prev_val - new_val = prev_val + val - if new_val %2 == 0: - result += new_val - A[index] = new_val - f_result.append(result) - return f_result","def sample_funcname ( var_0 , var_1 ) : - var_3 = 0 - for var_4 in var_0 : - if var_4 % 2 == 0 : - var_3 += var_4 - var_6 = [ ] - for var_7 in var_1 : - var_4 , var_9 = var_7 [ 0 ] , var_7 [ 1 ] - var_10 = var_0 [ var_9 ] - if var_10 % 2 == 0 : - var_3 -= var_10 - var_11 = var_10 + var_4 - if var_11 % 2 == 0 : - var_3 += var_11 - var_0 [ var_9 ] = var_11 - var_6.append ( var_3 ) - return var_6 -",102,3 -548,74_1.py,"def searchMatrix( matrix, target): - if not matrix: - return 0 - left, right = 0, len(matrix[0])-1 - - while left < len(matrix) and right >= 0: - if matrix[left][right] == target: - return True - elif matrix[left][right] < target: - left += 1 - else: - right -= 1 - return False","def sample_funcname ( var_0 , var_1 ) : - if not var_0 : - return 0 - var_3 , var_6 = 0 , len ( var_0 [ 0 ] ) - 1 - while var_3 < len ( var_0 ) and var_6 >= 0 : - if var_0 [ var_3 ] [ var_6 ] == var_1 : - return True - elif var_0 [ var_3 ] [ var_6 ] < var_1 : - var_3 += 1 - else : - var_6 -= 1 - return False -",10,2 -549,03_1.py,"def lengthOfLongestSubstring( s): - mapSet = {} - start, result = 0, 0 - - for end in range(len(s)): - if s[end] in mapSet: - start = max(mapSet[s[end]], start) - result = max(result, end-start+1) - mapSet[s[end]] = end+1 - - return result","def sample_funcname ( var_0 ) : - var_1 = { } - var_3 , var_4 = 0 , 0 - for var_7 in range ( len ( var_0 ) ) : - if var_0 [ var_7 ] in var_1 : - var_3 = max ( var_1 [ var_0 [ var_7 ] ] , var_3 ) - var_4 = max ( var_4 , var_7 - var_3 + 1 ) - var_1 [ var_0 [ var_7 ] ] = var_7 + 1 - return var_4 -",10,2 -550,54_1.py,"def spiralOrder( matrix): - if not matrix: - return [] - - R, C = len(matrix), len(matrix[0]) - dr = [0, 1, 0, -1] - dc = [1, 0, -1, 0] - - result = [] - seen = [[False]*C for _ in range(R)] - row = 0 - col = 0 - di = 0 - for _ in range(R*C): - result.append(matrix[row][col]) - seen[row][col] = True - rr, cc = row + dr[di], col + dc[di] - if 0 <= rr < R and 0 <= cc < C and not seen[rr][cc]: - row, col = rr, cc - else: - di = (di+1)%4 - row, col = row + dr[di], col + dc[di] - - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - var_2 , var_4 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_6 = [ 0 , 1 , 0 , - 1 ] - var_7 = [ 1 , 0 , - 1 , 0 ] - var_8 = [ ] - var_12 = [ [ False ] * var_4 for var_10 in range ( var_2 ) ] - var_13 = 0 - var_14 = 0 - var_15 = 0 - for var_10 in range ( var_2 * var_4 ) : - var_8.append ( var_0 [ var_13 ] [ var_14 ] ) - var_12 [ var_13 ] [ var_14 ] = True - var_18 , var_19 = var_13 + var_6 [ var_15 ] , var_14 + var_7 [ var_15 ] - if 0 <= var_18 < var_2 and 0 <= var_19 < var_4 and not var_12 [ var_18 ] [ var_19 ] : - var_13 , var_14 = var_18 , var_19 - else : - var_15 = ( var_15 + 1 ) % 4 - var_13 , var_14 = var_13 + var_6 [ var_15 ] , var_14 + var_7 [ var_15 ] - return var_8 -",104,3 -551,42_1.py,"def trap( height): - if not height: - return 0 - - left, right = 0, len(height) - 1 - leftMax, rightMax = 0, 0 - result = 0 - while left < right: - if height[left] < height[right]: - if height[left] > leftMax: - leftMax = height[left] - else: - result += (leftMax - height[left]) - left += 1 - else: - if height[right] > rightMax: - rightMax = height[right] - else: - result += (rightMax - height[right]) - right -= 1 - - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_2 , var_5 = 0 , len ( var_0 ) - 1 - var_6 , var_7 = 0 , 0 - var_8 = 0 - while var_2 < var_5 : - if var_0 [ var_2 ] < var_0 [ var_5 ] : - if var_0 [ var_2 ] > var_6 : - var_6 = var_0 [ var_2 ] - else : - var_8 += ( var_6 - var_0 [ var_2 ] ) - var_2 += 1 - else : - if var_0 [ var_5 ] > var_7 : - var_7 = var_0 [ var_5 ] - else : - var_8 += ( var_7 - var_0 [ var_5 ] ) - var_5 -= 1 - return var_8 -",10,2 -552,1085_1.py,"def sumOfDigits( A): - if not A: - return 0 - - mini = min(A) - result = 0 - while mini > 0: - quo = mini%10 - rem = mini/10 - result += quo - mini = rem - - return 0 if result%2 else 1","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_3 = min ( var_0 ) - var_4 = 0 - while var_3 > 0 : - var_6 = var_3 % 10 - var_7 = var_3 / 10 - var_4 += var_6 - var_3 = var_7 - return 0 if var_4 % 2 else 1 -",10012,4 -553,15_1.py,"def threeSum( nums): - nums.sort() - - if (len(nums) >= 3) and (nums[0] == nums[len(nums) -1]) and (nums[0] == 0): - return [[0, 0, 0]] - - result = [] - for index in range(len(nums) - 1): - left = index+1 - right = len(nums) - 1 - - while left < right: - currSum = nums[index] + nums[left] + nums[right] - if currSum == 0: - result.append([nums[index], nums[left], nums[right]]) - left += 1 - right -= 1 - elif currSum < 0: - left += 1 - else: - right -= 1 - return [list(t) for t in set(tuple(element) for element in result)]","def sample_funcname ( var_0 ) : - var_0.sort ( ) - if ( len ( var_0 ) >= 3 ) and ( var_0 [ 0 ] == var_0 [ len ( var_0 ) - 1 ] ) and ( var_0 [ 0 ] == 0 ) : - return [ [ 0 , 0 , 0 ] ] - var_6 = [ ] - for var_8 in range ( len ( var_0 ) - 1 ) : - var_9 = var_8 + 1 - var_10 = len ( var_0 ) - 1 - while var_9 < var_10 : - var_11 = var_0 [ var_8 ] + var_0 [ var_9 ] + var_0 [ var_10 ] - if var_11 == 0 : - var_6.append ( [ var_0 [ var_8 ] , var_0 [ var_9 ] , var_0 [ var_10 ] ] ) - var_9 += 1 - var_10 -= 1 - elif var_11 < 0 : - var_9 += 1 - else : - var_10 -= 1 - return [ list ( var_14 ) for var_14 in set ( tuple ( var_17 ) for var_17 in var_6 ) ] -",130,3 -554,81_1.py,"def search( nums, target): - left, right = 0, len(nums) -1 - while left <= right: - mid = (left + right) / 2 - if nums[mid] == target: - return True - if nums[left] < nums[mid]: - if nums[left] <= target < nums[mid]: - right = mid - 1 - else: - left = mid + 1 - elif nums[mid] < nums[left]: - if nums[mid] < target <= nums[right]: - left = mid + 1 - else: - right = mid -1 - else: - left += 1 - - return False","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_6 = 0 , len ( var_0 ) - 1 - while var_3 <= var_6 : - var_8 = ( var_3 + var_6 ) / 2 - if var_0 [ var_8 ] == var_1 : - return True - if var_0 [ var_3 ] < var_0 [ var_8 ] : - if var_0 [ var_3 ] <= var_1 < var_0 [ var_8 ] : - var_6 = var_8 - 1 - else : - var_3 = var_8 + 1 - elif var_0 [ var_8 ] < var_0 [ var_3 ] : - if var_0 [ var_8 ] < var_1 <= var_0 [ var_6 ] : - var_3 = var_8 + 1 - else : - var_6 = var_8 - 1 - else : - var_3 += 1 - return False -",102,3 -555,1046_1.py,"def lastStoneWeight( stones): - while len(stones) > 1: - max_x = max(stones) - stones.remove(max_x) - max_y = max(stones) - stones.remove(max_y) - - if max_x != max_y: - stones.append(max_x-max_y) - return stones[0] if stones else 0","def sample_funcname ( var_0 ) : - while len ( var_0 ) > 1 : - var_4 = max ( var_0 ) - var_0.remove ( var_4 ) - var_6 = max ( var_0 ) - var_0.remove ( var_6 ) - if var_4 != var_6 : - var_0.append ( var_4 - var_6 ) - return var_0 [ 0 ] if var_0 else 0 -",10,2 -556,1011_1.py,"def shipWithinDays( weights, D): - high, low = sum(weights)+1, max(weights) - - while(low < high): - mid = (high+low)/2 - temp_left = mid - packet_at_left = D-1 - for weight in weights: - if weight <= mid: - if temp_left < weight: - if packet_at_left == 0: - low = mid+1 - break - packet_at_left -= 1 - temp_left = mid-weight - else: - temp_left -= weight - else: - high = mid - - return low","def sample_funcname ( var_0 , var_1 ) : - var_4 , var_6 = sum ( var_0 ) + 1 , max ( var_0 ) - while ( var_6 < var_4 ) : - var_8 = ( var_4 + var_6 ) / 2 - var_9 = var_8 - var_10 = var_1 - 1 - for var_11 in var_0 : - if var_11 <= var_8 : - if var_9 < var_11 : - if var_10 == 0 : - var_6 = var_8 + 1 - break - var_10 -= 1 - var_9 = var_8 - var_11 - else : - var_9 -= var_11 - else : - var_4 = var_8 - return var_6 -",12,2 -557,1007_1.py,"def minDominoRotations( A, B): - if len(A) != len(B): - return -1 - if len(A) == 0: - return 0 - - for possibility in set([A[0], B[0]]): - top_rotation, bottom_rotation =0, 0 - for a_num, b_num in zip(A, B): - if possibility not in [a_num, b_num]: - break - top_rotation += int(b_num != possibility) - bottom_rotation += int(a_num != possibility) - else: - return min(top_rotation, bottom_rotation) - return -1","def sample_funcname ( var_0 , var_1 ) : - if len ( var_0 ) != len ( var_1 ) : - return - 1 - if len ( var_0 ) == 0 : - return 0 - for var_6 in set ( [ var_0 [ 0 ] , var_1 [ 0 ] ] ) : - var_7 , var_8 = 0 , 0 - for var_10 , var_11 in zip ( var_0 , var_1 ) : - if var_6 not in [ var_10 , var_11 ] : - break - var_7 += int ( var_11 != var_6 ) - var_8 += int ( var_10 != var_6 ) - else : - return min ( var_7 , var_8 ) - return - 1 -",10,2 -558,78_1.py,"def subsets( nums): - result = [[]] - for num in nums: - for j in range(len(result)): - result.append(result[j] + [num]) - return result","def sample_funcname ( var_0 ) : - var_1 = [ [ ] ] - for var_2 in var_0 : - for var_5 in range ( len ( var_1 ) ) : - var_1.append ( var_1 [ var_5 ] + [ var_2 ] ) - return var_1 -",,0 -559,989_1.py,"def addToArrayForm( A, K): - arr_k = [] - while K >0: - digit = K%10 - K /= 10 - arr_k.append(digit) - - arr_k.reverse() - if len(arr_k) > len(A): - A, arr_k = arr_k, A - - sum_arr = [0]*len(A) - i, j = len(A)-1, len(arr_k)-1 - k = len(A) -1 - digit_sum, carry = 0, 0 - while j >= 0: - curr_sum = A[i] + arr_k[j] + carry - sum_arr[k] = (curr_sum%10) - carry = curr_sum//10 - i -= 1 - k -= 1 - j -= 1 - - while i >= 0: - curr_sum = A[i] + carry - sum_arr[k] = (curr_sum%10) - carry =curr_sum//10 - i -= 1 - k -= 1 - - if carry: - sum_arr = [carry] + sum_arr - return sum_arr","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - while var_1 > 0 : - var_5 = var_1 % 10 - var_1 /= 10 - var_2.append ( var_5 ) - var_2.reverse ( ) - if len ( var_2 ) > len ( var_0 ) : - var_0 , var_2 = var_2 , var_0 - var_9 = [ 0 ] * len ( var_0 ) - var_11 , var_12 = len ( var_0 ) - 1 , len ( var_2 ) - 1 - var_13 = len ( var_0 ) - 1 - var_14 , var_15 = 0 , 0 - while var_12 >= 0 : - var_16 = var_0 [ var_11 ] + var_2 [ var_12 ] + var_15 - var_9 [ var_13 ] = ( var_16 % 10 ) - var_15 = var_16 // 10 - var_11 -= 1 - var_13 -= 1 - var_12 -= 1 - while var_11 >= 0 : - var_16 = var_0 [ var_11 ] + var_15 - var_9 [ var_13 ] = ( var_16 % 10 ) - var_15 = var_16 // 10 - var_11 -= 1 - var_13 -= 1 - if var_15 : - var_9 = [ var_15 ] + var_9 - return var_9 -",1001,3 -560,120_1.py,"def minimumTotal( triangle): - length = len(triangle) - columns = len(triangle[length-1]) - - matrix = [[ 0 for col in range(columns)] for row in range(length)] - row_index = 0 - - for row in range(length): - elements = triangle[row] - col_index = 0 - - for val in elements: - matrix[row_index][col_index] = val - col_index += 1 - row_index += 1 - - for row in range(length-2, -1, -1): - for col in range(row+1): - matrix[row][col] += min(matrix[row+1][col+1], matrix[row+1][col]) - return matrix[0][0]","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_4 = len ( var_0 [ var_2 - 1 ] ) - var_9 = [ [ 0 for var_6 in range ( var_4 ) ] for var_8 in range ( var_2 ) ] - var_10 = 0 - for var_8 in range ( var_2 ) : - var_11 = var_0 [ var_8 ] - var_12 = 0 - for var_13 in var_11 : - var_9 [ var_10 ] [ var_12 ] = var_13 - var_12 += 1 - var_10 += 1 - for var_8 in range ( var_2 - 2 , - 1 , - 1 ) : - for var_6 in range ( var_8 + 1 ) : - var_9 [ var_8 ] [ var_6 ] += min ( var_9 [ var_8 + 1 ] [ var_6 + 1 ] , var_9 [ var_8 + 1 ] [ var_6 ] ) - return var_9 [ 0 ] [ 0 ] -",102,3 -561,97_1.py,"def isInterleave( s1, s2, s3): - if len(s3) != len(s1) + len(s2): - return False - - dp = [[False for _ in range(len(s2)+1)] for _ in range(len(s1)+1)] - for row in range(len(s1)+1): - for col in range(len(s2)+1): - if row == 0 and col == 0: - dp[row][col] = True - elif row == 0: - dp[row][col] =dp[row][col-1] and s2[col-1] == s3[row+col-1] - elif col == 0: - dp[row][col] = dp[row-1][col] and s1[row-1] == s3[row+col-1] - else: - dp[row][col] = (dp[row][col-1] and s2[col-1] == s3[row+col-1]) or (dp[row-1][col] and s1[row-1] == s3[row+col-1]) - - return dp[len(s1)][len(s2)]","def sample_funcname ( var_0 , var_1 , var_2 ) : - if len ( var_2 ) != len ( var_0 ) + len ( var_1 ) : - return False - var_8 = [ [ False for var_5 in range ( len ( var_1 ) + 1 ) ] for var_5 in range ( len ( var_0 ) + 1 ) ] - for var_9 in range ( len ( var_0 ) + 1 ) : - for var_10 in range ( len ( var_1 ) + 1 ) : - if var_9 == 0 and var_10 == 0 : - var_8 [ var_9 ] [ var_10 ] = True - elif var_9 == 0 : - var_8 [ var_9 ] [ var_10 ] = var_8 [ var_9 ] [ var_10 - 1 ] and var_1 [ var_10 - 1 ] == var_2 [ var_9 + var_10 - 1 ] - elif var_10 == 0 : - var_8 [ var_9 ] [ var_10 ] = var_8 [ var_9 - 1 ] [ var_10 ] and var_0 [ var_9 - 1 ] == var_2 [ var_9 + var_10 - 1 ] - else : - var_8 [ var_9 ] [ var_10 ] = ( var_8 [ var_9 ] [ var_10 - 1 ] and var_1 [ var_10 - 1 ] == var_2 [ var_9 + var_10 - 1 ] ) or ( var_8 [ var_9 - 1 ] [ var_10 ] and var_0 [ var_9 - 1 ] == var_2 [ var_9 + var_10 - 1 ] ) - return var_8 [ len ( var_0 ) ] [ len ( var_1 ) ] -",10,2 -562,73_1.py,"def setZeroes( matrix): - col0 = 1 - for row in range(len(matrix)): - if matrix[row][0] == 0: - col0 = 0 - for col in range(1, len(matrix[0])): - if matrix[row][col] == 0: - matrix[row][0] = 0 - matrix[0][col] = 0 - for row in range(len(matrix)-1, -1, -1): - for col in range(len(matrix[0])-1, 0, -1): - if matrix[row][0] == 0 or matrix[0][col] == 0: - matrix[row][col] = 0 - if col0 == 0: - matrix[row][0] = 0","def sample_funcname ( var_0 ) : - var_2 = 1 - for var_5 in range ( len ( var_0 ) ) : - if var_0 [ var_5 ] [ 0 ] == 0 : - var_2 = 0 - for var_7 in range ( 1 , len ( var_0 [ 0 ] ) ) : - if var_0 [ var_5 ] [ var_7 ] == 0 : - var_0 [ var_5 ] [ 0 ] = 0 - var_0 [ 0 ] [ var_7 ] = 0 - for var_5 in range ( len ( var_0 ) - 1 , - 1 , - 1 ) : - for var_7 in range ( len ( var_0 [ 0 ] ) - 1 , 0 , - 1 ) : - if var_0 [ var_5 ] [ 0 ] == 0 or var_0 [ 0 ] [ var_7 ] == 0 : - var_0 [ var_5 ] [ var_7 ] = 0 - if var_2 == 0 : - var_0 [ var_5 ] [ 0 ] = 0 -",10,2 -563,24_1.py,"def swapPairs( head): - if head is None: - return head - - ref = head - - while ref is not None and ref.next is not None: - ref.val, ref.next.val = ref.next.val, ref.val - ref = ref.next.next - - return head","def sample_funcname ( var_0 ) : - if var_0 is None : - return var_0 - var_2 = var_0 - while var_2 is not None and var_2.next is not None : - var_2.val , var_2.next.val = var_2.next.val , var_2.val - var_2 = var_2.next.next - return var_0 -",None,1 -564,32_1.py,"def longestValidParentheses( s): - stack, result = [-1], 0 - - for index in range(len(s)): - if s[index] == '(': - stack.append(index) - else: - currIndex = stack.pop() - if currIndex == -1: - stack.append(index) - else: - result = max(result, index-currIndex+1) - return result","def sample_funcname ( var_0 ) : - var_2 , var_4 = [ - 1 ] , 0 - for var_7 in range ( len ( var_0 ) ) : - if var_0 [ var_7 ] == '(' : - var_2.append ( var_7 ) - else : - var_11 = var_2.pop ( ) - if var_11 == - 1 : - var_2.append ( var_7 ) - else : - var_4 = max ( var_4 , var_7 - var_11 + 1 ) - return var_4 -",(10,3 -565,1276_1.py,"def numOfBurgers( tomatoSlices, cheeseSlices): - jumbo = tomatoSlices - 2*cheeseSlices - if jumbo >= 0 and jumbo%2 == 0: - x = jumbo/2 - y = cheeseSlices-(jumbo/2) - if x >= 0 and y >= 0: - return [x, y] - else: - return [] - return []","def sample_funcname ( var_0 , var_1 ) : - var_3 = var_0 - 2 * var_1 - if var_3 >= 0 and var_3 % 2 == 0 : - var_5 = var_3 / 2 - var_6 = var_1 - ( var_3 / 2 ) - if var_5 >= 0 and var_6 >= 0 : - return [ var_5 , var_6 ] - else : - return [ ] - return [ ] -",02,2 -566,994_1.py,"def valid( row, col, row_size, col_size): - return row >= 0 and col >= 0 and row < row_size and col < col_size","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - return var_0 >= 0 and var_1 >= 0 and var_0 < var_2 and var_1 < var_3 -",0,1 -567,65_1.py,"def isNumber( s): - s = s.strip() - try: - if isinstance(float(s),float) or isinstance(int(s),int): - return True - except Exception as e: - return False","def sample_funcname ( var_0 ) : - var_0 = var_0.strip ( ) - try : - if isinstance ( float ( var_0 ) , float ) or isinstance ( int ( var_0 ) , int ) : - return True - except Exception as var_7 : - return False -",,0 -568,146_1.py,"def remove( node): - prev_node = node.prev - prev_node.next = node.next - node.next.prev = prev_node","def sample_funcname ( var_0 ) : - var_2 = var_0.prev - var_2.next = var_0.next - var_0.next.prev = var_2 -",,0 -569,111_1.py,"def minDepth( root): - if not root: - return 0 - depth = float('inf') - stack = [(root, 1)] - - while stack: - node, level = stack.pop() - if node: - - if not node.left and not node.right: - depth = min(depth, level) - - stack.append((node.left, level+1)) - stack.append((node.right, level+1)) - - return depth","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_4 = float ( 'inf' ) - var_6 = [ ( var_0 , 1 ) ] - while var_6 : - var_8 , var_9 = var_6.pop ( ) - if var_8 : - if not var_8.left and not var_8.right : - var_4 = min ( var_4 , var_9 ) - var_6.append ( ( var_8.left , var_9 + 1 ) ) - var_6.append ( ( var_8.right , var_9 + 1 ) ) - return var_4 -",10inf,3 -570,107_1.py,"def levelOrderBottom( root): - if not root: - return [] - - queue = [(root, 0)] - levelMap = {} - - while queue: - node, level = queue.pop(0) - if node.left: - queue.append((node.left, level+1)) - if node.right: - queue.append((node.right, level+1)) - - if level in levelMap: - levelMap[level].append(node.val) - else: - levelMap[level] = [node.val] - - result = [] - for key, value in levelMap.iteritems(): - result.append(value) - return result[::-1]","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - var_2 = [ ( var_0 , 0 ) ] - var_3 = { } - while var_2 : - var_5 , var_6 = var_2.pop ( 0 ) - if var_5.left : - var_2.append ( ( var_5.left , var_6 + 1 ) ) - if var_5.right : - var_2.append ( ( var_5.right , var_6 + 1 ) ) - if var_6 in var_3 : - var_3 [ var_6 ].append ( var_5.val ) - else : - var_3 [ var_6 ] = [ var_5.val ] - var_12 = [ ] - for var_14 , var_15 in var_3.iteritems ( ) : - var_12.append ( var_15 ) - return var_12 [ : : - 1 ] -",10,2 -571,1020_1.py,"def numEnclaves( A): - result = 0 - queue = [] - for row in range(len(A)): - for col in range(len(A[0])): - result += A[row][col] - if (row*col == 0 or row == len(A)-1 or col == len(A[0])-1) and A[row][col] == 1: - queue.append((row, col)) - - x_move = [-1, 0, 1, 0] - y_move = [0, 1, 0, -1] - - while queue: - x, y = queue.pop(0) - A[x][y] = 0 - result -= 1 - - for xm, ym in zip(x_move, y_move): - nx = x + xm - ny = y + ym - - if 0<= nx 0,2 -572,150_1.py,"def evalRPN( tokens): - if not tokens: - return 0 - - stack = [] - for val in tokens: - if val == '+': - val1 = stack.pop() - val2 = stack.pop() - stack.append(val1 + val2) - elif val == '-': - val1 = stack.pop() - val2 = stack.pop() - stack.append(val2-val1) - elif val == '*': - val1 = stack.pop() - val2 = stack.pop() - stack.append(val2*val1) - elif val == '/': - val1 = stack.pop() - val2 = stack.pop() - if val1*val2 < 0: - stack.append(-(-val2/val1)) - else: - stack.append(val2/val1) - else: - stack.append(int(val)) - return stack[0]","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_2 = [ ] - for var_3 in var_0 : - if var_3 == '+' : - var_6 = var_2.pop ( ) - var_7 = var_2.pop ( ) - var_2.append ( var_6 + var_7 ) - elif var_3 == '-' : - var_6 = var_2.pop ( ) - var_7 = var_2.pop ( ) - var_2.append ( var_7 - var_6 ) - elif var_3 == '*' : - var_6 = var_2.pop ( ) - var_7 = var_2.pop ( ) - var_2.append ( var_7 * var_6 ) - elif var_3 == '/' : - var_6 = var_2.pop ( ) - var_7 = var_2.pop ( ) - if var_6 * var_7 < 0 : - var_2.append ( - ( - var_7 / var_6 ) ) - else : - var_2.append ( var_7 / var_6 ) - else : - var_2.append ( int ( var_3 ) ) - return var_2 [ 0 ] -",0*+-/,5 -573,279_1.py,"def numSquares( n): - mapping = {} - squares = [num*num for num in range(1, int(pow(n, 0.5)) + 1)] - for square in squares: - mapping[square] = 1 - - for val in range(1, n+1): - if val not in mapping: - mapping[val] = float('inf') - for square in squares: - if square < val: - mapping[val] = min(mapping[val], mapping[square] + mapping[val-square]) - return mapping[n]","def sample_funcname ( var_0 ) : - var_1 = { } - var_8 = [ var_2 * var_2 for var_2 in range ( 1 , int ( pow ( var_0 , 0.5 ) ) + 1 ) ] - for var_9 in var_8 : - var_1 [ var_9 ] = 1 - for var_10 in range ( 1 , var_0 + 1 ) : - if var_10 not in var_1 : - var_1 [ var_10 ] = float ( 'inf' ) - for var_9 in var_8 : - if var_9 < var_10 : - var_1 [ var_10 ] = min ( var_1 [ var_10 ] , var_1 [ var_9 ] + var_1 [ var_10 - var_9 ] ) - return var_1 [ var_0 ] -",10.5inf,3 -574,90_1.py,"def subsetsWithDup( nums): - result = [[]] - for num in nums: - for index in range(len(result)): - new_list = result[index] + [num] - new_list.sort() - result.append(new_list) - unique = set(tuple(val) for val in result) - return list(list(val) for val in unique)","def sample_funcname ( var_0 ) : - var_1 = [ [ ] ] - for var_2 in var_0 : - for var_5 in range ( len ( var_1 ) ) : - var_6 = var_1 [ var_5 ] + [ var_2 ] - var_6.sort ( ) - var_1.append ( var_6 ) - var_12 = set ( tuple ( var_11 ) for var_11 in var_1 ) - return list ( list ( var_11 ) for var_11 in var_12 ) -",,0 -575,1283_1.py,"def getSum(divisor, xs): - return sum([x // divisor + 1 if x % divisor else x // divisor for x in xs])","def sample_funcname ( var_0 , var_1 ) : - return sum ( [ var_3 // var_0 + 1 if var_3 % var_0 else var_3 // var_0 for var_3 in var_1 ] ) -",1,1 -576,1295_1.py,"def findNumbers( nums): - return len([num for num in nums if len(str(num))%2 == 0])","def sample_funcname ( var_0 ) : - return len ( [ var_2 for var_2 in var_0 if len ( str ( var_2 ) ) % 2 == 0 ] ) -",02,2 -577,1016_1.py,"def queryString( S, N): - for num in range(1, N+1): - binary_str = '' - while (num != 0): - binary_str += str(num%2) - num /= 2 - reversed_str = binary_str[::-1] - - if reversed_str not in S: - return False - return True","def sample_funcname ( var_0 , var_1 ) : - for var_4 in range ( 1 , var_1 + 1 ) : - var_6 = '' - while ( var_4 != 0 ) : - var_6 += str ( var_4 % 2 ) - var_4 /= 2 - var_10 = var_6 [ : : - 1 ] - if var_10 not in var_0 : - return False - return True -",102,4 -578,131_1.py,"def valid(s): - for i in range(len(s)/2): - if s[i] != s[-(i+1)]: - return False - return True","def sample_funcname ( var_0 ) : - for var_4 in range ( len ( var_0 ) / 2 ) : - if var_0 [ var_4 ] != var_0 [ - ( var_4 + 1 ) ] : - return False - return True -",12,2 -580,977_1.py,"def sortedSquares( A): - N = len(A) - j = 0 - while j = 0 and j < N: - if A[i]**2 < A[j]**2: - result.append(A[i]**2) - i -= 1 - else: - result.append(A[j]**2) - j += 1 - while i>= 0: - result.append(A[i]**2) - i -= 1 - - while j < N: - result.append(A[j]**2) - j += 1 - - return result","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_4 = 0 - while var_4 < var_2 and var_0 [ var_4 ] < 0 : - var_4 += 1 - var_6 = var_4 - 1 - var_7 = [ ] - while var_6 >= 0 and var_4 < var_2 : - if var_0 [ var_6 ] ** 2 < var_0 [ var_4 ] ** 2 : - var_7.append ( var_0 [ var_6 ] ** 2 ) - var_6 -= 1 - else : - var_7.append ( var_0 [ var_4 ] ** 2 ) - var_4 += 1 - while var_6 >= 0 : - var_7.append ( var_0 [ var_6 ] ** 2 ) - var_6 -= 1 - while var_4 < var_2 : - var_7.append ( var_0 [ var_4 ] ** 2 ) - var_4 += 1 - return var_7 -",102,3 -581,326_1.py,"def isPowerOfThree( n): - if n <= 0: - return False - - import math - return (math.log10(n)/math.log10(3))%1 == 0","def sample_funcname ( var_0 ) : - if var_0 <= 0 : - return False - import var_3 - return ( var_3.log10 ( var_0 ) / var_3.log10 ( 3 ) ) % 1 == 0 -",130,3 -582,1190_1.py,"def reverseParentheses( s): - if not s: - return '' - - stack = [] - for char in s: - if char == ')': - combine_str = '' - while stack and stack[-1] != '(': - elem = stack.pop()[::-1] - combine_str += elem - stack.pop() - stack.append(combine_str) - else: - stack.append(char) - return """".join(stack)","def sample_funcname ( var_0 ) : - if not var_0 : - return '' - var_2 = [ ] - for var_3 in var_0 : - if var_3 == ')' : - var_5 = '' - while var_2 and var_2 [ - 1 ] != '(' : - var_9 = var_2.pop ( ) [ : : - 1 ] - var_5 += var_9 - var_2.pop ( ) - var_2.append ( var_5 ) - else : - var_2.append ( var_3 ) - return """".join ( var_2 ) -",1(),5 -583,145_2.py,"def postorderTraversal( root): - if not root: - return [] - - stack, result = [], [] - - while True: - while root: - if root.right: - stack.append(root.right) - stack.append(root) - root = root.left - - root = stack.pop() - - if root.right and stack and stack[-1] == root.right: - stack.pop() - stack.append(root) - root = root.right - else: - result.append(root.val) - root = None - - if len(stack)<=0: - break - - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - var_1 , var_2 = [ ] , [ ] - while True : - while var_0 : - if var_0.right : - var_1.append ( var_0.right ) - var_1.append ( var_0 ) - var_0 = var_0.left - var_0 = var_1.pop ( ) - if var_0.right and var_1 and var_1 [ - 1 ] == var_0.right : - var_1.pop ( ) - var_1.append ( var_0 ) - var_0 = var_0.right - else : - var_2.append ( var_0.val ) - var_0 = None - if len ( var_1 ) <= 0 : - break - return var_2 -",1None0,3 -584,234_1.py,"def isPalindrome( head): - rev = None - slow, fast = head, head.next - while fast and fast.next: - fast = fast.next.next - temp = slow - slow = slow.next - temp.next = rev - rev = temp - - if fast: - slow = slow.next - - while rev and rev.val == slow.val: - rev = rev.next - slow = slow.next - return not rev","def sample_funcname ( var_0 ) : - var_2 = None - var_3 , var_5 = var_0 , var_0.next - while var_5 and var_5.next : - var_5 = var_5.next.next - var_6 = var_3 - var_3 = var_3.next - var_6.next = var_2 - var_2 = var_6 - if var_5 : - var_3 = var_3.next - while var_2 and var_2.val == var_3.val : - var_2 = var_2.next - var_3 = var_3.next - return not var_2 -",None,1 -585,388_1.py,"def lengthLongestPath( input): - if not input: - return 0 - directories = input.split('\n') - stack = [[-1, 0]] - result = 0 - for direct in directories: - n_tabs = direct.count('\t') - while stack and stack[-1][0] >= n_tabs: - stack.pop() - if ""."" in direct: - result = max(result, stack[-1][1] + len(direct)-n_tabs) - stack.append([n_tabs, stack[-1][1] + len(direct) + 1 -n_tabs]) - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_4 = var_0.split ( '\n' ) - var_6 = [ [ - 1 , 0 ] ] - var_7 = 0 - for var_8 in var_4 : - var_11 = var_8.count ( '\t' ) - while var_6 and var_6 [ - 1 ] [ 0 ] >= var_11 : - var_6.pop ( ) - if ""."" in var_8 : - var_7 = max ( var_7 , var_6 [ - 1 ] [ 1 ] + len ( var_8 ) - var_11 ) - var_6.append ( [ var_11 , var_6 [ - 1 ] [ 1 ] + len ( var_8 ) + 1 - var_11 ] ) - return var_7 -",\n0\t1.,5 -586,53_1.py,"def maxSubArray( nums): - if not nums: - return 0 - - currSum, result = nums[0], nums[0] - - for index in range(1, len(nums)): - currSum = max(nums[index], currSum+nums[index]) - result = max(result, currSum) - - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return 0 - var_2 , var_3 = var_0 [ 0 ] , var_0 [ 0 ] - for var_7 in range ( 1 , len ( var_0 ) ) : - var_2 = max ( var_0 [ var_7 ] , var_2 + var_0 [ var_7 ] ) - var_3 = max ( var_3 , var_2 ) - return var_3 -",10,2 -587,1186_1.py,"def maximumSum( arr): - forward = [0] * len(arr) - backward = [0] * len(arr) - - curr_max, max_so_far = arr[0], arr[0] - forward[0] = arr[0] - for index in range(1, len(arr)): - curr_max = max(arr[index], curr_max + arr[index]) - max_so_far = max(max_so_far, curr_max) - - forward[index] = curr_max - - curr_max = arr[len(arr) - 1] - max_so_far = arr[len(arr) - 1] - backward[len(arr) - 1] = arr[len(arr) - 1] - - index = len(arr) - 2 - while index >= 0: - curr_max = max(arr[index], curr_max + arr[index]) - max_so_far = max(max_so_far, curr_max) - - backward[index] = curr_max - index -= 1 - - result = max_so_far - for index in range(1, len(arr)-1): - result = max(result, forward[index-1] + backward[index + 1]) - return result","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * len ( var_0 ) - var_4 = [ 0 ] * len ( var_0 ) - var_5 , var_6 = var_0 [ 0 ] , var_0 [ 0 ] - var_3 [ 0 ] = var_0 [ 0 ] - for var_9 in range ( 1 , len ( var_0 ) ) : - var_5 = max ( var_0 [ var_9 ] , var_5 + var_0 [ var_9 ] ) - var_6 = max ( var_6 , var_5 ) - var_3 [ var_9 ] = var_5 - var_5 = var_0 [ len ( var_0 ) - 1 ] - var_6 = var_0 [ len ( var_0 ) - 1 ] - var_4 [ len ( var_0 ) - 1 ] = var_0 [ len ( var_0 ) - 1 ] - var_9 = len ( var_0 ) - 2 - while var_9 >= 0 : - var_5 = max ( var_0 [ var_9 ] , var_5 + var_0 [ var_9 ] ) - var_6 = max ( var_6 , var_5 ) - var_4 [ var_9 ] = var_5 - var_9 -= 1 - var_12 = var_6 - for var_9 in range ( 1 , len ( var_0 ) - 1 ) : - var_12 = max ( var_12 , var_3 [ var_9 - 1 ] + var_4 [ var_9 + 1 ] ) - return var_12 -",102,3 -588,448_1.py,"def findDisappearedNumbers( nums): - if not nums: - return [] - result = [] - for num in nums: - index = abs(num)-1 - if nums[index] > 0: - nums[index]*=-1 - for index, num in enumerate(nums): - if num >0: - result.append(index+1) - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - var_1 = [ ] - for var_2 in var_0 : - var_5 = abs ( var_2 ) - 1 - if var_0 [ var_5 ] > 0 : - var_0 [ var_5 ] *= - 1 - for var_5 , var_2 in enumerate ( var_0 ) : - if var_2 > 0 : - var_1.append ( var_5 + 1 ) - return var_1 -",10,2 -589,05_1.py,"def longestPalindrome( s): - dp = [[0 for _ in range(len(s))] for _ in range(len(s))] - maxLength, result = 1, """" - for index in range(len(s)): - dp[index][index] = 1 - result = s[index] - - length = 2 - - while length <= len(s): - index_i = 0 - while index_i < len(s) - length + 1: - index_j = index_i + length -1 - - if length == 2 and s[index_i] == s[index_j]: - dp[index_i][index_j] = 1 - maxLength = max(maxLength, 2) - result = s[index_i:index_j+1] - elif s[index_i] == s[index_j] and dp[index_i+1][index_j-1]: - dp[index_i][index_j] = 1 - if length > maxLength: - maxLength = length - result = s[index_i:index_j+1] - - index_i += 1 - length += 1 - - return result","def sample_funcname ( var_0 ) : - var_5 = [ [ 0 for var_2 in range ( len ( var_0 ) ) ] for var_2 in range ( len ( var_0 ) ) ] - var_7 , var_9 = 1 , """" - for var_10 in range ( len ( var_0 ) ) : - var_5 [ var_10 ] [ var_10 ] = 1 - var_9 = var_0 [ var_10 ] - var_12 = 2 - while var_12 <= len ( var_0 ) : - var_13 = 0 - while var_13 < len ( var_0 ) - var_12 + 1 : - var_14 = var_13 + var_12 - 1 - if var_12 == 2 and var_0 [ var_13 ] == var_0 [ var_14 ] : - var_5 [ var_13 ] [ var_14 ] = 1 - var_7 = max ( var_7 , 2 ) - var_9 = var_0 [ var_13 : var_14 + 1 ] - elif var_0 [ var_13 ] == var_0 [ var_14 ] and var_5 [ var_13 + 1 ] [ var_14 - 1 ] : - var_5 [ var_13 ] [ var_14 ] = 1 - if var_12 > var_7 : - var_7 = var_12 - var_9 = var_0 [ var_13 : var_14 + 1 ] - var_13 += 1 - var_12 += 1 - return var_9 -",102,4 -590,673_1.py,"def findNumberOfLIS( nums): - length = [1]*len(nums) - count = [1]*len(nums) - result = 0 - for end, num in enumerate(nums): - for start in range(end): - if num > nums[start]: - if length[start] >= length[end]: - length[end] = 1+length[start] - count[end] = count[start] - elif length[start] + 1 == length[end]: - count[end] += count[start] - for index, max_subs in enumerate(count): - if length[index] == max(length): - result += max_subs - return result","def sample_funcname ( var_0 ) : - var_3 = [ 1 ] * len ( var_0 ) - var_4 = [ 1 ] * len ( var_0 ) - var_6 = 0 - for var_8 , var_9 in enumerate ( var_0 ) : - for var_11 in range ( var_8 ) : - if var_9 > var_0 [ var_11 ] : - if var_3 [ var_11 ] >= var_3 [ var_8 ] : - var_3 [ var_8 ] = 1 + var_3 [ var_11 ] - var_4 [ var_8 ] = var_4 [ var_11 ] - elif var_3 [ var_11 ] + 1 == var_3 [ var_8 ] : - var_4 [ var_8 ] += var_4 [ var_11 ] - for var_12 , var_13 in enumerate ( var_4 ) : - if var_3 [ var_12 ] == max ( var_3 ) : - var_6 += var_13 - return var_6 -",10,2 -591,44_1.py,"def isMatch( s, p): - if len(p) == 0: - return len(s) == 0 - - dp = [[False for _ in range(len(p) + 1)] for _ in range(len(s) + 1)] - dp[0][0] = True - - for index in range(1,len(dp[0])): - if p[index-1] == '*': - dp[0][index] = dp[0][index-1] - - for index_i in range(1, len(dp)): - for index_j in range(1, len(dp[0])): - if s[index_i - 1] == p[index_j - 1] or p[index_j - 1] == '?': - dp[index_i][index_j] = dp[index_i-1][index_j-1] - elif p[index_j-1] == '*': - dp[index_i][index_j] = dp[index_i][index_j-1] or dp[index_i-1][index_j] - else: - dp[index_i][index_j] = False - return dp[len(s)][len(p)]","def sample_funcname ( var_0 , var_1 ) : - if len ( var_1 ) == 0 : - return len ( var_0 ) == 0 - var_8 = [ [ False for var_5 in range ( len ( var_1 ) + 1 ) ] for var_5 in range ( len ( var_0 ) + 1 ) ] - var_8 [ 0 ] [ 0 ] = True - for var_10 in range ( 1 , len ( var_8 [ 0 ] ) ) : - if var_1 [ var_10 - 1 ] == '*' : - var_8 [ 0 ] [ var_10 ] = var_8 [ 0 ] [ var_10 - 1 ] - for var_12 in range ( 1 , len ( var_8 ) ) : - for var_13 in range ( 1 , len ( var_8 [ 0 ] ) ) : - if var_0 [ var_12 - 1 ] == var_1 [ var_13 - 1 ] or var_1 [ var_13 - 1 ] == '?' : - var_8 [ var_12 ] [ var_13 ] = var_8 [ var_12 - 1 ] [ var_13 - 1 ] - elif var_1 [ var_13 - 1 ] == '*' : - var_8 [ var_12 ] [ var_13 ] = var_8 [ var_12 ] [ var_13 - 1 ] or var_8 [ var_12 - 1 ] [ var_13 ] - else : - var_8 [ var_12 ] [ var_13 ] = False - return var_8 [ len ( var_0 ) ] [ len ( var_1 ) ] -",10?*,4 -592,1200_1.py,"def minimumAbsDifference( arr): - if not arr: - return [] - - arr.sort() - mindiff = arr[1] - arr[0] - for index in range(2, len(arr)): - mindiff = min(mindiff, (arr[index] - arr[index-1])) - - result = [] - for index in range(1, len(arr)): - if arr[index] - arr[index-1] == mindiff: - result.append([arr[index-1], arr[index]]) - return result","def sample_funcname ( var_0 ) : - if not var_0 : - return [ ] - var_0.sort ( ) - var_4 = var_0 [ 1 ] - var_0 [ 0 ] - for var_8 in range ( 2 , len ( var_0 ) ) : - var_4 = min ( var_4 , ( var_0 [ var_8 ] - var_0 [ var_8 - 1 ] ) ) - var_10 = [ ] - for var_8 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_8 ] - var_0 [ var_8 - 1 ] == var_4 : - var_10.append ( [ var_0 [ var_8 - 1 ] , var_0 [ var_8 ] ] ) - return var_10 -",102,3 -593,1191_1.py,"def suffix(arr): - curr_sum, max_val = 0, float('-inf') - for index in range(len(arr)-1, -1, -1): - curr_sum += arr[index] - max_val = max(max_val, curr_sum) - return max_val","def sample_funcname ( var_0 ) : - var_2 , var_5 = 0 , float ( '-inf' ) - for var_9 in range ( len ( var_0 ) - 1 , - 1 , - 1 ) : - var_2 += var_0 [ var_9 ] - var_5 = max ( var_5 , var_2 ) - return var_5 -",10-inf,3 -594,144_2.py,"def recursive(root, result): - if not root: - return - result.append(root.val) - recursive(root.left, result) - recursive(root.right, result)","def sample_funcname ( var_1 , var_2 ) : - if not var_1 : - return - var_2.append ( var_1.val ) - var_0 ( var_1.left , var_2 ) - var_0 ( var_1.right , var_2 ) -",,0 -595,999_1.py,"def numRookCaptures( board): - result = 0 - rook_index = (0, 0) - for row in range(len(board)): - for col in range(len(board[0])): - if board[row][col] == 'R': - rook_index = (row, col) - break - - flag = True - col = rook_index[1]-1 - pawn = 0 - while col >= 0: - if board[rook_index[0]][col] == 'B': - flag = False - break - if board[rook_index[0]][col] == 'p': - pawn += 1 - break - col -= 1 - if flag and pawn != 0: - result += 1 - - flag = True - col = rook_index[1]+1 - pawn = 0 - while col < len(board[0]): - if board[rook_index[0]][col] == 'B': - flag = False - break - if board[rook_index[0]][col] == 'p': - pawn += 1 - break - col += 1 - - if flag and pawn != 0: - result += 1 - - flag = True - row = rook_index[0]+1 - pawn = 0 - while row < len(board): - if board[row][rook_index[1]] == 'B': - flag = False - break - - if board[row][rook_index[1]] == 'p': - pawn += 1 - break - row += 1 - - if flag and pawn != 0: - result += 1 - - pawn = 0 - flag = True - row = rook_index[0]-1 - while row >= 0: - if board[row][rook_index[1]] == 'B': - flag = False - break - if board[row][rook_index[1]] == 'p': - pawn += 1 - break - row -= 1 - if flag and pawn != 0: - result += 1 - - return result","def sample_funcname ( var_0 ) : - var_2 = 0 - var_3 = ( 0 , 0 ) - for var_6 in range ( len ( var_0 ) ) : - for var_7 in range ( len ( var_0 [ 0 ] ) ) : - if var_0 [ var_6 ] [ var_7 ] == 'R' : - var_3 = ( var_6 , var_7 ) - break - var_10 = True - var_7 = var_3 [ 1 ] - 1 - var_12 = 0 - while var_7 >= 0 : - if var_0 [ var_3 [ 0 ] ] [ var_7 ] == 'B' : - var_10 = False - break - if var_0 [ var_3 [ 0 ] ] [ var_7 ] == 'p' : - var_12 += 1 - break - var_7 -= 1 - if var_10 and var_12 != 0 : - var_2 += 1 - var_10 = True - var_7 = var_3 [ 1 ] + 1 - var_12 = 0 - while var_7 < len ( var_0 [ 0 ] ) : - if var_0 [ var_3 [ 0 ] ] [ var_7 ] == 'B' : - var_10 = False - break - if var_0 [ var_3 [ 0 ] ] [ var_7 ] == 'p' : - var_12 += 1 - break - var_7 += 1 - if var_10 and var_12 != 0 : - var_2 += 1 - var_10 = True - var_6 = var_3 [ 0 ] + 1 - var_12 = 0 - while var_6 < len ( var_0 ) : - if var_0 [ var_6 ] [ var_3 [ 1 ] ] == 'B' : - var_10 = False - break - if var_0 [ var_6 ] [ var_3 [ 1 ] ] == 'p' : - var_12 += 1 - break - var_6 += 1 - if var_10 and var_12 != 0 : - var_2 += 1 - var_12 = 0 - var_10 = True - var_6 = var_3 [ 0 ] - 1 - while var_6 >= 0 : - if var_0 [ var_6 ] [ var_3 [ 1 ] ] == 'B' : - var_10 = False - break - if var_0 [ var_6 ] [ var_3 [ 1 ] ] == 'p' : - var_12 += 1 - break - var_6 -= 1 - if var_10 and var_12 != 0 : - var_2 += 1 - return var_2 -",0BR1p,5 -596,1017_1.py,"def baseNeg2( N): - if N == 0: - digits = ['0'] - else: - digits = [] - while N != 0: - N, remainder = divmod(N, -2) - if remainder < 0: - N, remainder = N+1, remainder + 2 - digits.append(str(remainder)) - return ''.join(digits[::-1])","def sample_funcname ( var_0 ) : - if var_0 == 0 : - var_3 = [ '0' ] - else : - var_3 = [ ] - while var_0 != 0 : - var_0 , var_6 = divmod ( var_0 , - 2 ) - if var_6 < 0 : - var_0 , var_6 = var_0 + 1 , var_6 + 2 - var_3.append ( str ( var_6 ) ) - return ''.join ( var_3 [ : : - 1 ] ) -",0021,5 -597,91_1.py,"def numDecodings( s): - if not s or s[0] == '0': - return 0 - if len(s) == 1: - return 1 - - dp = [0]*len(s) - dp[0] = 1 - - if int(s[:2]) > 26: - if s[1] != '0': - dp[1] = 1 - else: - dp[0] = 0 - else: - if s[1] != '0': - dp[1] = 2 - else: - dp[1] = 1 - - for index in range(2, len(s)): - if s[index] != '0': - dp[index] += dp[index-1] - - val = int(s[index-1:index+1]) - if val >= 10 and val <= 26: - dp[index] += dp[index-2] - return dp[len(s)-1]","def sample_funcname ( var_0 ) : - if not var_0 or var_0 [ 0 ] == '0' : - return 0 - if len ( var_0 ) == 1 : - return 1 - var_5 = [ 0 ] * len ( var_0 ) - var_5 [ 0 ] = 1 - if int ( var_0 [ : 2 ] ) > 26 : - if var_0 [ 1 ] != '0' : - var_5 [ 1 ] = 1 - else : - var_5 [ 0 ] = 0 - else : - if var_0 [ 1 ] != '0' : - var_5 [ 1 ] = 2 - else : - var_5 [ 1 ] = 1 - for var_10 in range ( 2 , len ( var_0 ) ) : - if var_0 [ var_10 ] != '0' : - var_5 [ var_10 ] += var_5 [ var_10 - 1 ] - var_11 = int ( var_0 [ var_10 - 1 : var_10 + 1 ] ) - if var_11 >= 10 and var_11 <= 26 : - var_5 [ var_10 ] += var_5 [ var_10 - 2 ] - return var_5 [ len ( var_0 ) - 1 ] -",10002126,6 -598,1021_1.py,"def removeOuterParentheses( S): - temp, result = """", """" - start_bracket = 0 - for char in S: - temp += char - if char == '(': - start_bracket += 1 - else: - start_bracket -= 1 - if start_bracket == 0: - result += temp[1:-1] - temp = """" - return result","def sample_funcname ( var_0 ) : - var_2 , var_3 = """" , """" - var_5 = 0 - for var_6 in var_0 : - var_2 += var_6 - if var_6 == '(' : - var_5 += 1 - else : - var_5 -= 1 - if var_5 == 0 : - var_3 += var_2 [ 1 : - 1 ] - var_2 = """" - return var_3 -",1(0,4 -599,393_1.py,"def validUtf8( data): - seveneth_mask = 1 << 7 - sixth_mask = 1 << 6 - no_bytes = 0 - - if len(data) == 1: - return not(data[0] & seveneth_mask) - - for num in data: - if no_bytes == 0: - mask = 1 << 7 - - while num & mask: - no_bytes += 1 - mask >>= 1 - - if no_bytes == 0: - continue - - if no_bytes == 1 or no_bytes > 4: - return False - else: - if not(num & seveneth_mask and not(num & sixth_mask)): - return False - no_bytes -= 1 - return no_bytes == 0","def sample_funcname ( var_0 ) : - var_3 = 1 << 7 - var_5 = 1 << 6 - var_7 = 0 - if len ( var_0 ) == 1 : - return not ( var_0 [ 0 ] & var_3 ) - for var_9 in var_0 : - if var_7 == 0 : - var_10 = 1 << 7 - while var_9 & var_10 : - var_7 += 1 - var_10 >>= 1 - if var_7 == 0 : - continue - if var_7 == 1 or var_7 > 4 : - return False - else : - if not ( var_9 & var_3 and not ( var_9 & var_5 ) ) : - return False - var_7 -= 1 - return var_7 == 0 -",06174,5 -600,48_1.py,"def rotate( matrix): - n = len(matrix) - if n%2 == 0: - m = n/2 - else: - m = n/2 + 1 - - for i in range(n/2): - for j in range(m): - temp = matrix[i][j] - matrix[i][j] = matrix[n-j-1][i] - matrix[n-j-1][i] = matrix[n-i-1][n-j-1] - matrix[n-i-1][n-j-1] = matrix[j][n-i-1] - matrix[j][n-i-1] = temp","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - if var_2 % 2 == 0 : - var_5 = var_2 / 2 - else : - var_5 = var_2 / 2 + 1 - for var_8 in range ( var_2 / 2 ) : - for var_9 in range ( var_5 ) : - var_10 = var_0 [ var_8 ] [ var_9 ] - var_0 [ var_8 ] [ var_9 ] = var_0 [ var_2 - var_9 - 1 ] [ var_8 ] - var_0 [ var_2 - var_9 - 1 ] [ var_8 ] = var_0 [ var_2 - var_8 - 1 ] [ var_2 - var_9 - 1 ] - var_0 [ var_2 - var_8 - 1 ] [ var_2 - var_9 - 1 ] = var_0 [ var_9 ] [ var_2 - var_8 - 1 ] - var_0 [ var_9 ] [ var_2 - var_8 - 1 ] = var_10 -",102,3 -601,1037_1.py,"def isBoomerang( points): - x1, x2, x3, y1, y2, y3 = points[0][0], points[1][0], points[2][0], points[0][1], points[1][1] ,points[2][1] - if ((y3 - y2)*(x2 - x1) == (y2 - y1)*(x3 - x2)): - return False - return True","def sample_funcname ( var_0 ) : - var_2 , var_4 , var_6 , var_7 , var_8 , var_9 = var_0 [ 0 ] [ 0 ] , var_0 [ 1 ] [ 0 ] , var_0 [ 2 ] [ 0 ] , var_0 [ 0 ] [ 1 ] , var_0 [ 1 ] [ 1 ] , var_0 [ 2 ] [ 1 ] - if ( ( var_9 - var_8 ) * ( var_4 - var_2 ) == ( var_8 - var_7 ) * ( var_6 - var_4 ) ) : - return False - return True -",102,3 -602,147_1.py,"def insertionSortList( head): - if not head: - return None - - sortedList = head - head = head.next - sortedList.next = None - - while head: - curr = head - head = head.next - if curr.val <= sortedList.val: - curr.next = sortedList - sortedList = curr - else: - temp = sortedList - while temp.next and temp.next.val < curr.val: - temp = temp.next - curr.next = temp.next - temp.next = curr - return sortedList","def sample_funcname ( var_0 ) : - if not var_0 : - return None - var_2 = var_0 - var_0 = var_0.next - var_2.next = None - while var_0 : - var_4 = var_0 - var_0 = var_0.next - if var_4.val <= var_2.val : - var_4.next = var_2 - var_2 = var_4 - else : - var_6 = var_2 - while var_6.next and var_6.next.val < var_4.val : - var_6 = var_6.next - var_4.next = var_6.next - var_6.next = var_4 - return var_2 -",None,1 -603,350_1.py,"def intersect( nums1, nums2): - nums1.sort() - nums2.sort() - - index_i, index_j = 0, 0 - result = [] - while index_i < len(nums1) and index_j < len(nums2): - if nums1[index_i] == nums2[index_j]: - result.append(nums1[index_i]) - index_i += 1 - index_j += 1 - elif nums1[index_i] > nums2[index_j]: - index_j += 1 - else: - index_i += 1 - return result","def sample_funcname ( var_0 , var_1 ) : - var_0.sort ( ) - var_1.sort ( ) - var_4 , var_5 = 0 , 0 - var_6 = [ ] - while var_4 < len ( var_0 ) and var_5 < len ( var_1 ) : - if var_0 [ var_4 ] == var_1 [ var_5 ] : - var_6.append ( var_0 [ var_4 ] ) - var_4 += 1 - var_5 += 1 - elif var_0 [ var_4 ] > var_1 [ var_5 ] : - var_5 += 1 - else : - var_4 += 1 - return var_6 -",10,2 -604,215_1.py,"def findKthLargest( nums, k): - heap = [] - import heapq - for num in nums: - heapq.heappush(heap, -(num)) - - result = 0 - for _ in range(k): - result = heapq.heappop(heap) - - return -(result)","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - import var_3 - for var_4 in var_0 : - var_3.heappush ( var_2 , - ( var_4 ) ) - var_7 = 0 - for var_9 in range ( var_1 ) : - var_7 = var_3.heappop ( var_2 ) - return - ( var_7 ) -",0,1 -605,995_1.py,"def minKBitFlips( a: 'List[int]', k: 'int') -> 'int': - from collections import deque - q = deque() - res = 0 - for i in range(len(a)): - if len(q) % 2 != 0: - if a[i] == 1: - res += 1 - q.append(i+k-1) - else: - if a[i] == 0: - res += 1 - q.append(i+k-1) - if q and q[0] == i: q.popleft() - if q and q[-1] >= len(a): return -1 - return res","def sample_funcname ( var_0 : 'List[int]' , var_2 : 'int' ) -> 'int' : - from var_4 import var_5 - var_6 = var_5 ( ) - var_8 = 0 - for var_11 in range ( len ( var_0 ) ) : - if len ( var_6 ) % 2 != 0 : - if var_0 [ var_11 ] == 1 : - var_8 += 1 - var_6.append ( var_11 + var_2 - 1 ) - else : - if var_0 [ var_11 ] == 0 : - var_8 += 1 - var_6.append ( var_11 + var_2 - 1 ) - if var_6 and var_6 [ 0 ] == var_11 : var_6.popleft ( ) - if var_6 and var_6 [ - 1 ] >= len ( var_0 ) : return - 1 - return var_8 -",0int21List[int],5 -606,1277_1.py,"def countSquares( matrix): - p_arr = [[0 for i in range(len(matrix[0]))] for j in range(len(matrix))] - result = 0 - - for index_i in range(1, len(matrix)): - for index_j in range(1, len(matrix[0])): - if matrix[index_i][index_j] == 1: - matrix[index_i][index_j] = min(matrix[index_i-1][index_j-1], min(matrix[index_i-1][index_j], matrix[index_i][index_j-1]))+1 - return sum([ sum(x) for x in matrix])","def sample_funcname ( var_0 ) : - var_6 = [ [ 0 for var_2 in range ( len ( var_0 [ 0 ] ) ) ] for var_5 in range ( len ( var_0 ) ) ] - var_7 = 0 - for var_9 in range ( 1 , len ( var_0 ) ) : - for var_10 in range ( 1 , len ( var_0 [ 0 ] ) ) : - if var_0 [ var_9 ] [ var_10 ] == 1 : - var_0 [ var_9 ] [ var_10 ] = min ( var_0 [ var_9 - 1 ] [ var_10 - 1 ] , min ( var_0 [ var_9 - 1 ] [ var_10 ] , var_0 [ var_9 ] [ var_10 - 1 ] ) ) + 1 - return sum ( [ sum ( var_13 ) for var_13 in var_0 ] ) -",10,2 -607,33_1.py,"def search( nums, target): - if not nums: - return -1 - - left, right = 0, len(nums) - 1 - - while left <= right: - mid = (left + right) / 2 - if nums[mid] == target: - return mid - - if nums[left] <= nums[mid]: - if target >= nums[left] and target <= nums[mid]: - right = mid - 1 - else: - left = mid + 1 - else: - if target >= nums[mid] and target <= nums[right]: - left = mid + 1 - else: - right = mid - 1 - - return -1","def sample_funcname ( var_0 , var_1 ) : - if not var_0 : - return - 1 - var_4 , var_6 = 0 , len ( var_0 ) - 1 - while var_4 <= var_6 : - var_8 = ( var_4 + var_6 ) / 2 - if var_0 [ var_8 ] == var_1 : - return var_8 - if var_0 [ var_4 ] <= var_0 [ var_8 ] : - if var_1 >= var_0 [ var_4 ] and var_1 <= var_0 [ var_8 ] : - var_6 = var_8 - 1 - else : - var_4 = var_8 + 1 - else : - if var_1 >= var_0 [ var_8 ] and var_1 <= var_0 [ var_6 ] : - var_4 = var_8 + 1 - else : - var_6 = var_8 - 1 - return - 1 -",102,3 -608,203_1.py,"def countPrimes( n): - if n < 2: - return 0 - - A = [0] * (n + 1) - count = 0 - - for pointer1 in range(2, n): - if A[pointer1] == 0: - count += 1 - pointer2 = pointer1 - while (pointer2 + pointer1 < n): - pointer2 += pointer1 - A[pointer2] = 1 - - return count","def sample_funcname ( var_0 ) : - if var_0 < 2 : - return 0 - var_4 = [ 0 ] * ( var_0 + 1 ) - var_5 = 0 - for var_7 in range ( 2 , var_0 ) : - if var_4 [ var_7 ] == 0 : - var_5 += 1 - var_8 = var_7 - while ( var_8 + var_7 < var_0 ) : - var_8 += var_7 - var_4 [ var_8 ] = 1 - return var_5 -",102,3 -609,72_1.py,"def minDistance( word1, word2): - m , n = len(word1), len(word2) - - dp = [[0 for _ in range(n+1)] for _ in range(m+1)] - for index_i in range(m+1): - for index_j in range(n+1): - if index_i == 0: - dp[index_i][index_j] = index_j - elif index_j == 0: - dp[index_i][index_j] = index_i - elif word1[index_i-1] == word2[index_j-1]: - dp[index_i][index_j] = dp[index_i-1][index_j-1] - else: - dp[index_i][index_j] = 1 + min(dp[index_i-1][index_j], dp[index_i-1][index_j-1], dp[index_i][index_j-1]) - - return dp[m][n]","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = len ( var_0 ) , len ( var_1 ) - var_9 = [ [ 0 for var_6 in range ( var_4 + 1 ) ] for var_6 in range ( var_3 + 1 ) ] - for var_10 in range ( var_3 + 1 ) : - for var_11 in range ( var_4 + 1 ) : - if var_10 == 0 : - var_9 [ var_10 ] [ var_11 ] = var_11 - elif var_11 == 0 : - var_9 [ var_10 ] [ var_11 ] = var_10 - elif var_0 [ var_10 - 1 ] == var_1 [ var_11 - 1 ] : - var_9 [ var_10 ] [ var_11 ] = var_9 [ var_10 - 1 ] [ var_11 - 1 ] - else : - var_9 [ var_10 ] [ var_11 ] = 1 + min ( var_9 [ var_10 - 1 ] [ var_11 ] , var_9 [ var_10 - 1 ] [ var_11 - 1 ] , var_9 [ var_10 ] [ var_11 - 1 ] ) - return var_9 [ var_3 ] [ var_4 ] -",10,2 -611,1124.Longest Well-Performing Interval_1.py,"def longestWPI( hours: List[int]) -> int: - ans = s = 0 - seen = {} - for i, h in enumerate(hours): - s += 1 if h > 8 else -1 - if s > 0: - ans = i + 1 - else: - if s not in seen: - seen[s] = i - if s - 1 in seen: - ans = max(ans, i - seen[s - 1]) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - var_6 = { } - for var_8 , var_9 in enumerate ( var_0 ) : - var_3 += 1 if var_9 > 8 else - 1 - if var_3 > 0 : - var_5 = var_8 + 1 - else : - if var_3 not in var_6 : - var_6 [ var_3 ] = var_8 - if var_3 - 1 in var_6 : - var_5 = max ( var_5 , var_8 - var_6 [ var_3 - 1 ] ) - return var_5 -",108,3 -612,0696.Count Binary Substrings_1.py,"def countBinarySubstrings( s: str) -> int: - i, n = 0, len(s) - t = [] - while i < n: - cnt = 1 - while i + 1 < n and s[i + 1] == s[i]: - cnt += 1 - i += 1 - t.append(cnt) - i += 1 - ans = 0 - for i in range(1, len(t)): - ans += min(t[i - 1], t[i]) - return ans","def sample_funcname ( var_0 : str ) -> int : - var_4 , var_6 = 0 , len ( var_0 ) - var_7 = [ ] - while var_4 < var_6 : - var_9 = 1 - while var_4 + 1 < var_6 and var_0 [ var_4 + 1 ] == var_0 [ var_4 ] : - var_9 += 1 - var_4 += 1 - var_7.append ( var_9 ) - var_4 += 1 - var_11 = 0 - for var_4 in range ( 1 , len ( var_7 ) ) : - var_11 += min ( var_7 [ var_4 - 1 ] , var_7 [ var_4 ] ) - return var_11 -",10,2 -613,0704.Binary Search_1.py,"def search( nums: List[int], target: int) -> int: - left, right = 0, len(nums) - 1 - while left < right: - mid = (left + right) >> 1 - if nums[mid] >= target: - right = mid - else: - left = mid + 1 - return left if nums[left] == target else -1","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_8 = 0 , len ( var_0 ) - 1 - while var_5 < var_8 : - var_9 = ( var_5 + var_8 ) >> 1 - if var_0 [ var_9 ] >= var_3 : - var_8 = var_9 - else : - var_5 = var_9 + 1 - return var_5 if var_0 [ var_5 ] == var_3 else - 1 -",10,2 -614,0678.Valid Parenthesis String_1.py,"def checkValidString( s: str) -> bool: - n = len(s) - left, asterisk = 0, 0 - for i in range(n): - if s[i] == ""("": - left += 1 - elif s[i] == "")"": - if left > 0: - left -= 1 - elif asterisk > 0: - asterisk -= 1 - else: - return False - else: - asterisk += 1 - right, asterisk = 0, 0 - for i in range(n - 1, -1, -1): - if s[i] == "")"": - right += 1 - elif s[i] == ""("": - if right > 0: - right -= 1 - elif asterisk > 0: - asterisk -= 1 - else: - return False - else: - asterisk += 1 - return True","def sample_funcname ( var_0 : str ) -> bool : - var_4 = len ( var_0 ) - var_6 , var_7 = 0 , 0 - for var_9 in range ( var_4 ) : - if var_0 [ var_9 ] == ""("" : - var_6 += 1 - elif var_0 [ var_9 ] == "")"" : - if var_6 > 0 : - var_6 -= 1 - elif var_7 > 0 : - var_7 -= 1 - else : - return False - else : - var_7 += 1 - var_14 , var_7 = 0 , 0 - for var_9 in range ( var_4 - 1 , - 1 , - 1 ) : - if var_0 [ var_9 ] == "")"" : - var_14 += 1 - elif var_0 [ var_9 ] == ""("" : - if var_14 > 0 : - var_14 -= 1 - elif var_7 > 0 : - var_7 -= 1 - else : - return False - else : - var_7 += 1 - return True -",(01),4 -615,0057.Insert Interval_1.py,"def merge(intervals): - intervals.sort() - ans = [] - st, ed = intervals[0] - for s, e in intervals[1:]: - if ed < s: - ans.append([st, ed]) - st, ed = s, e - else: - ed = max(ed, e) - ans.append([st, ed]) - return ans","def sample_funcname ( var_0 ) : - var_0.sort ( ) - var_2 = [ ] - var_4 , var_5 = var_0 [ 0 ] - for var_7 , var_8 in var_0 [ 1 : ] : - if var_5 < var_7 : - var_2.append ( [ var_4 , var_5 ] ) - var_4 , var_5 = var_7 , var_8 - else : - var_5 = max ( var_5 , var_8 ) - var_2.append ( [ var_4 , var_5 ] ) - return var_2 -",10,2 -616,0739.Daily Temperatures_1.py,"def dailyTemperatures( temperatures: List[int]) -> List[int]: - ans = [0] * len(temperatures) - stk = [] - for i, t in enumerate(temperatures): - while stk and temperatures[stk[-1]] < t: - j = stk.pop() - ans[j] = i - j - stk.append(i) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_5 = [ 0 ] * len ( var_0 ) - var_6 = [ ] - for var_8 , var_9 in enumerate ( var_0 ) : - while var_6 and var_0 [ var_6 [ - 1 ] ] < var_9 : - var_12 = var_6.pop ( ) - var_5 [ var_12 ] = var_8 - var_12 - var_6.append ( var_8 ) - return var_5 -",10,2 -617,0543.Diameter of Binary Tree_1.py,"def dfs(root): - if root is None: - return 0 - nonlocal ans - left, right = dfs(root.left), dfs(root.right) - ans = max(ans, left + right) - return 1 + max(left, right)","def sample_funcname ( var_1 ) : - if var_1 is None : - return 0 - nonlocal var_4 - left , right = var_0 ( var_1.left ) , var_0 ( var_1.right ) - var_4 = max ( var_4 , left + right ) - return 1 + max ( left , right ) -",10None,3 -618,1105.Filling Bookcase Shelves_1.py,"def minHeightShelves( books: List[List[int]], shelfWidth: int) -> int: - n = len(books) - dp = [0] * (n + 1) - dp[1] = books[0][1] - for i in range(2, n + 1): - dp[i] = books[i - 1][1] + dp[i - 1] - w, h = books[i - 1][0], books[i - 1][1] - for j in range(i - 1, 0, -1): - w += books[j - 1][0] - if w > shelfWidth: - break - h = max(books[j - 1][1], h) - dp[i] = min(dp[i], dp[j - 1] + h) - return dp[n]","def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : int ) -> int : - var_5 = len ( var_0 ) - var_8 = [ 0 ] * ( var_5 + 1 ) - var_8 [ 1 ] = var_0 [ 0 ] [ 1 ] - for var_11 in range ( 2 , var_5 + 1 ) : - var_8 [ var_11 ] = var_0 [ var_11 - 1 ] [ 1 ] + var_8 [ var_11 - 1 ] - var_12 , var_13 = var_0 [ var_11 - 1 ] [ 0 ] , var_0 [ var_11 - 1 ] [ 1 ] - for var_14 in range ( var_11 - 1 , 0 , - 1 ) : - var_12 += var_0 [ var_14 - 1 ] [ 0 ] - if var_12 > var_3 : - break - var_13 = max ( var_0 [ var_14 - 1 ] [ 1 ] , var_13 ) - var_8 [ var_11 ] = min ( var_8 [ var_11 ] , var_8 [ var_14 - 1 ] + var_13 ) - return var_8 [ var_5 ] -",102,3 -619,0961.N-Repeated Element in Size 2N Array_1.py,"def repeatedNTimes( nums: List[int]) -> int: - s = set() - for num in nums: - if num in s: - return num - s.add(num)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = set ( ) - for var_5 in var_0 : - if var_5 in var_4 : - return var_5 - var_4.add ( var_5 ) -",,0 -620,0509.Fibonacci Number_1.py,"def fib( n: int) -> int: - a, b = 0, 1 - for _ in range(n): - a, b = b, a + b - return a","def sample_funcname ( var_0 : int ) -> int : - var_3 , var_5 = 0 , 1 - for var_7 in range ( var_0 ) : - var_3 , var_5 = var_5 , var_3 + var_5 - return var_3 -",10,2 -621,0572.Subtree of Another Tree_1.py,"def dfs(root1, root2): - if root1 is None and root2 is None: - return True - if root1 is None or root2 is None: - return False - return ( - root1.val == root2.val - and dfs(root1.left, root2.left) - and dfs(root1.right, root2.right) - )","def sample_funcname ( var_1 , var_2 ) : - if var_1 is None and var_2 is None : - return True - if var_1 is None or var_2 is None : - return False - return ( var_1.val == var_2.val and var_0 ( var_1.left , var_2.left ) and var_0 ( var_1.right , var_2.right ) ) -",None,1 -622,1221.Split a String in Balanced Strings_1.py,"def balancedStringSplit( s: str) -> int: - ans = l = 0 - for c in s: - if c == 'L': - l += 1 - else: - l -= 1 - if l == 0: - ans += 1 - return ans","def sample_funcname ( var_0 : str ) -> int : - var_5 = var_3 = 0 - for var_6 in var_0 : - if var_6 == 'L' : - var_3 += 1 - else : - var_3 -= 1 - if var_3 == 0 : - var_5 += 1 - return var_5 -",10L,3 -623,0461.Hamming Distance_1.py,"def hammingDistance( x: int, y: int) -> int: - num, count = x ^ y, 0 - while num != 0: - num &= num - 1 - count += 1 - return count","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_3 , var_5 = var_0 ^ var_2 , 0 - while var_3 != 0 : - var_3 &= var_3 - 1 - var_5 += 1 - return var_5 -",10,2 -624,1523.Count Odd Numbers in an Interval Range_1.py,"def countOdds( low: int, high: int) -> int: - return ((high + 1) >> 1) - (low >> 1)","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - return ( ( var_2 + 1 ) >> 1 ) - ( var_0 >> 1 ) -",1,1 -625,1685.Sum of Absolute Differences in a Sorted Array_1.py,"def getSumAbsoluteDifferences( nums: List[int]) -> List[int]: - n = len(nums) - presum = [0] * (n + 1) - for i in range(n): - presum[i + 1] = presum[i] + nums[i] - res = [] - for i, num in enumerate(nums): - t = num * i - presum[i] + presum[n] - presum[i + 1] - num * (n - i - 1) - res.append(t) - return res","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 = len ( var_0 ) - var_7 = [ 0 ] * ( var_4 + 1 ) - for var_9 in range ( var_4 ) : - var_7 [ var_9 + 1 ] = var_7 [ var_9 ] + var_0 [ var_9 ] - var_10 = [ ] - for var_9 , var_12 in enumerate ( var_0 ) : - var_13 = var_12 * var_9 - var_7 [ var_9 ] + var_7 [ var_4 ] - var_7 [ var_9 + 1 ] - var_12 * ( var_4 - var_9 - 1 ) - var_10.append ( var_13 ) - return var_10 -",10,2 -626,2016.Maximum Difference Between Increasing Elements_1.py,"def maximumDifference( nums: List[int]) -> int: - mi = nums[0] - ans, n = -1, len(nums) - for i in range(1, n): - if nums[i] > mi: - ans = max(ans, nums[i] - mi) - else: - mi = nums[i] - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = var_0 [ 0 ] - var_6 , var_8 = - 1 , len ( var_0 ) - for var_10 in range ( 1 , var_8 ) : - if var_0 [ var_10 ] > var_4 : - var_6 = max ( var_6 , var_0 [ var_10 ] - var_4 ) - else : - var_4 = var_0 [ var_10 ] - return var_6 -",10,2 -627,1375.Number of Times Binary String Is Prefix-Aligned_1.py,"def numTimesAllBlue( flips: List[int]) -> int: - ans = mx = 0 - for i, v in enumerate(flips, 1): - mx = max(mx, v) - if mx == i: - ans += 1 - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - for var_7 , var_9 in enumerate ( var_0 , 1 ) : - var_3 = max ( var_3 , var_9 ) - if var_3 == var_7 : - var_5 += 1 - return var_5 -",10,2 -628,1427.Perform String Shifts_1.py,"def stringShift( s: str, shift: List[List[int]]) -> str: - x = 0 - for a, b in shift: - if a == 0: - b = -b - x += b - x %= len(s) - return s[-x:] + s[:-x]","def sample_funcname ( var_0 : str , var_2 : List [ List [ int ] ] ) -> str : - var_6 = 0 - for var_7 , var_8 in var_2 : - if var_7 == 0 : - var_8 = - var_8 - var_6 += var_8 - var_6 %= len ( var_0 ) - return var_0 [ - var_6 : ] + var_0 [ : - var_6 ] -",0,1 -629,0400.Nth Digit_1.py,"def findNthDigit( n: int) -> int: - bits, t = 1, 9 - while n > bits * t: - n -= bits * t - bits += 1 - t *= 10 - - start = 10 ** (bits - 1) + (n // bits) - 1 - if n % bits == 0: - return start % 10 - return int(str((start + 1))[(n % bits) - 1])","def sample_funcname ( var_0 : int ) -> int : - var_3 , var_5 = 1 , 9 - while var_0 > var_3 * var_5 : - var_0 -= var_3 * var_5 - var_3 += 1 - var_5 *= 10 - var_7 = 10 ** ( var_3 - 1 ) + ( var_0 // var_3 ) - 1 - if var_0 % var_3 == 0 : - return var_7 % 10 - return int ( str ( ( var_7 + 1 ) ) [ ( var_0 % var_3 ) - 1 ] ) -",91100,4 -630,1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target_1.py,"def maxNonOverlapping( nums: List[int], target: int) -> int: - i, n = 0, len(nums) - ans = 0 - while i < n: - s = 0 - seen = {0} - while i < n: - s += nums[i] - if s - target in seen: - ans += 1 - break - i += 1 - seen.add(s) - i += 1 - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_7 = 0 , len ( var_0 ) - var_8 = 0 - while var_5 < var_7 : - var_9 = 0 - var_10 = { 0 } - while var_5 < var_7 : - var_9 += var_0 [ var_5 ] - if var_9 - var_3 in var_10 : - var_8 += 1 - break - var_5 += 1 - var_10.add ( var_9 ) - var_5 += 1 - return var_8 -",10,2 -631,0552.Student Attendance Record II_1.py,"def checkRecord( n: int) -> int: - mod = int(1e9 + 7) - dp = [[[0, 0, 0], [0, 0, 0]] for _ in range(n)] - - dp[0][0][0] = dp[0][0][1] = dp[0][1][0] = 1 - - for i in range(1, n): - dp[i][1][0] = (dp[i - 1][0][0] + dp[i - 1][0][1] + dp[i - 1][0][2]) % mod - dp[i][0][1] = dp[i - 1][0][0] - dp[i][0][2] = dp[i - 1][0][1] - dp[i][1][1] = dp[i - 1][1][0] - dp[i][1][2] = dp[i - 1][1][1] - dp[i][0][0] = (dp[i - 1][0][0] + dp[i - 1][0][1] + dp[i - 1][0][2]) % mod - dp[i][1][0] = ( - dp[i][1][0] + dp[i - 1][1][0] + dp[i - 1][1][1] + dp[i - 1][1][2] - ) % mod - - ans = 0 - for j in range(2): - for k in range(3): - ans = (ans + dp[n - 1][j][k]) % mod - return ans","def sample_funcname ( var_0 : int ) -> int : - var_4 = int ( 1e9 + 7 ) - var_8 = [ [ [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] ] for var_6 in range ( var_0 ) ] - var_8 [ 0 ] [ 0 ] [ 0 ] = var_8 [ 0 ] [ 0 ] [ 1 ] = var_8 [ 0 ] [ 1 ] [ 0 ] = 1 - for var_10 in range ( 1 , var_0 ) : - var_8 [ var_10 ] [ 1 ] [ 0 ] = ( var_8 [ var_10 - 1 ] [ 0 ] [ 0 ] + var_8 [ var_10 - 1 ] [ 0 ] [ 1 ] + var_8 [ var_10 - 1 ] [ 0 ] [ 2 ] ) % var_4 - var_8 [ var_10 ] [ 0 ] [ 1 ] = var_8 [ var_10 - 1 ] [ 0 ] [ 0 ] - var_8 [ var_10 ] [ 0 ] [ 2 ] = var_8 [ var_10 - 1 ] [ 0 ] [ 1 ] - var_8 [ var_10 ] [ 1 ] [ 1 ] = var_8 [ var_10 - 1 ] [ 1 ] [ 0 ] - var_8 [ var_10 ] [ 1 ] [ 2 ] = var_8 [ var_10 - 1 ] [ 1 ] [ 1 ] - var_8 [ var_10 ] [ 0 ] [ 0 ] = ( var_8 [ var_10 - 1 ] [ 0 ] [ 0 ] + var_8 [ var_10 - 1 ] [ 0 ] [ 1 ] + var_8 [ var_10 - 1 ] [ 0 ] [ 2 ] ) % var_4 - var_8 [ var_10 ] [ 1 ] [ 0 ] = ( var_8 [ var_10 ] [ 1 ] [ 0 ] + var_8 [ var_10 - 1 ] [ 1 ] [ 0 ] + var_8 [ var_10 - 1 ] [ 1 ] [ 1 ] + var_8 [ var_10 - 1 ] [ 1 ] [ 2 ] ) % var_4 - var_12 = 0 - for var_13 in range ( 2 ) : - for var_15 in range ( 3 ) : - var_12 = ( var_12 + var_8 [ var_0 - 1 ] [ var_13 ] [ var_15 ] ) % var_4 - return var_12 -",1e902173,6 -632,0408.Valid Word Abbreviation_1.py,"def validWordAbbreviation( word: str, abbr: str) -> bool: - i = j = 0 - m, n = len(word), len(abbr) - while i < m: - if j >= n: - return False - if word[i] == abbr[j]: - i, j = i + 1, j + 1 - continue - k = j - while k < n and abbr[k].isdigit(): - k += 1 - t = abbr[j:k] - if not t.isdigit() or t[0] == '0' or int(t) == 0: - return False - i += int(t) - j = k - return i == m and j == n","def sample_funcname ( var_0 : str , var_2 : str ) -> bool : - var_6 = var_4 = 0 - var_8 , var_9 = len ( var_0 ) , len ( var_2 ) - while var_6 < var_8 : - if var_4 >= var_9 : - return False - if var_0 [ var_6 ] == var_2 [ var_4 ] : - var_6 , var_4 = var_6 + 1 , var_4 + 1 - continue - var_12 = var_4 - while var_12 < var_9 and var_2 [ var_12 ].isdigit ( ) : - var_12 += 1 - var_14 = var_2 [ var_4 : var_12 ] - if not var_14.isdigit ( ) or var_14 [ 0 ] == '0' or int ( var_14 ) == 0 : - return False - var_6 += int ( var_14 ) - var_4 = var_12 - return var_6 == var_8 and var_4 == var_9 -",100,3 -633,1497.Check If Array Pairs Are Divisible by k_1.py,"def canArrange( arr: List[int], k: int) -> bool: - mod = [0] * k - for v in arr: - mod[v % k] += 1 - return all(mod[i] == mod[k - i] for i in range(1, k)) and mod[0] % 2 == 0","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> bool : - var_6 = [ 0 ] * var_3 - for var_7 in var_0 : - var_6 [ var_7 % var_3 ] += 1 - return all ( var_6 [ var_10 ] == var_6 [ var_3 - var_10 ] for var_10 in range ( 1 , var_3 ) ) and var_6 [ 0 ] % 2 == 0 -",102,3 -634,1346.Check If N and Its Double Exist_1.py,"def checkIfExist( arr: List[int]) -> bool: - m = {v: i for i, v in enumerate(arr)} - return any(v << 1 in m and m[v << 1] != i for i, v in enumerate(arr))","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_7 = { var_4 : var_5 for var_5 , var_4 in enumerate ( var_0 ) } - return any ( var_4 << 1 in var_7 and var_7 [ var_4 << 1 ] != var_5 for var_5 , var_4 in enumerate ( var_0 ) ) -",1,1 -635,1550.Three Consecutive Odds_1.py,"def threeConsecutiveOdds( arr: List[int]) -> bool: - for i in range(len(arr) - 2): - if arr[i] % 2 + arr[i + 1] % 2 + arr[i + 2] % 2 == 3: - return True - return False","def sample_funcname ( var_0 : List [ int ] ) -> bool : - for var_7 in range ( len ( var_0 ) - 2 ) : - if var_0 [ var_7 ] % 2 + var_0 [ var_7 + 1 ] % 2 + var_0 [ var_7 + 2 ] % 2 == 3 : - return True - return False -",312,3 -636,0898.Bitwise ORs of Subarrays_1.py,"def subarrayBitwiseORs( arr: List[int]) -> int: - s = set() - prev = 0 - for i, v in enumerate(arr): - prev |= v - curr = 0 - for j in range(i, -1, -1): - curr |= arr[j] - s.add(curr) - if curr == prev: - break - return len(s)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = set ( ) - var_6 = 0 - for var_8 , var_9 in enumerate ( var_0 ) : - var_6 |= var_9 - var_10 = 0 - for var_13 in range ( var_8 , - 1 , - 1 ) : - var_10 |= var_0 [ var_13 ] - var_4.add ( var_10 ) - if var_10 == var_6 : - break - return len ( var_4 ) -",10,2 -637,0951.Flip Equivalent Binary Trees_1.py,"def dfs(root1, root2): - if root1 == root2 or (root1 is None and root2 is None): - return True - if root1 is None or root2 is None or root1.val != root2.val: - return False - return (dfs(root1.left, root2.left) and dfs(root1.right, root2.right)) or ( - dfs(root1.left, root2.right) and dfs(root1.right, root2.left) - )","def sample_funcname ( var_1 , var_2 ) : - if var_1 == var_2 or ( var_1 is None and var_2 is None ) : - return True - if var_1 is None or var_2 is None or var_1.val != var_2.val : - return False - return ( var_0 ( var_1.left , var_2.left ) and var_0 ( var_1.right , var_2.right ) ) or ( var_0 ( var_1.left , var_2.right ) and var_0 ( var_1.right , var_2.left ) ) -",None,1 -638,0392.Is Subsequence_1.py,"def isSubsequence( s: str, t: str) -> bool: - i, j, m, n = 0, 0, len(s), len(t) - while i < m and j < n: - if s[i] == t[j]: - i += 1 - j += 1 - return i == m","def sample_funcname ( var_0 : str , var_2 : str ) -> bool : - var_5 , var_6 , var_8 , var_9 = 0 , 0 , len ( var_0 ) , len ( var_2 ) - while var_5 < var_8 and var_6 < var_9 : - if var_0 [ var_5 ] == var_2 [ var_6 ] : - var_5 += 1 - var_6 += 1 - return var_5 == var_8 -",10,2 -639,0997.Find the Town Judge_1.py,"def findJudge( n: int, trust: List[List[int]]) -> int: - N = 1001 - c1, c2 = [0] * N, [0] * N - for a, b in trust: - c1[a] += 1 - c2[b] += 1 - for i in range(1, N): - if c1[i] == 0 and c2[i] == n - 1: - return i - return -1","def sample_funcname ( var_0 : int , var_2 : List [ List [ int ] ] ) -> int : - var_5 = 1001 - var_7 , var_8 = [ 0 ] * var_5 , [ 0 ] * var_5 - for var_9 , var_10 in var_2 : - var_7 [ var_9 ] += 1 - var_8 [ var_10 ] += 1 - for var_13 in range ( 1 , var_5 ) : - if var_7 [ var_13 ] == 0 and var_8 [ var_13 ] == var_0 - 1 : - return var_13 - return - 1 -",101001,3 -640,0035.Search Insert Position_1.py,"def searchInsert( nums: List[int], target: int) -> int: - left, right = 0, len(nums) - while left < right: - mid = (left + right) >> 1 - if nums[mid] >= target: - right = mid - else: - left = mid + 1 - return left","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_7 = 0 , len ( var_0 ) - while var_5 < var_7 : - var_9 = ( var_5 + var_7 ) >> 1 - if var_0 [ var_9 ] >= var_3 : - var_7 = var_9 - else : - var_5 = var_9 + 1 - return var_5 -",10,2 -641,1260.Shift 2D Grid_1.py,"def shiftGrid( grid: List[List[int]], k: int) -> List[List[int]]: - m, n = len(grid), len(grid[0]) - k %= m * n - t = [grid[i][j] for i in range(m) for j in range(n)] - t = t[-k:] + t[:-k] - for i in range(m): - for j in range(n): - grid[i][j] = t[i * n + j] - return grid","def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : int ) -> List [ List [ int ] ] : - var_5 , var_7 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_3 %= var_5 * var_7 - var_11 = [ var_0 [ var_8 ] [ var_9 ] for var_8 in range ( var_5 ) for var_9 in range ( var_7 ) ] - var_11 = var_11 [ - var_3 : ] + var_11 [ : - var_3 ] - for var_8 in range ( var_5 ) : - for var_9 in range ( var_7 ) : - var_0 [ var_8 ] [ var_9 ] = var_11 [ var_8 * var_7 + var_9 ] - return var_0 -",0,1 -642,2285.Maximum Total Importance of Roads_1.py,"def maximumImportance( n: int, roads: List[List[int]]) -> int: - deg = [0] * n - for a, b in roads: - deg[a] += 1 - deg[b] += 1 - deg.sort() - return sum(i * v for i, v in enumerate(deg, 1))","def sample_funcname ( var_0 : int , var_2 : List [ List [ int ] ] ) -> int : - var_5 = [ 0 ] * var_0 - for var_6 , var_7 in var_2 : - var_5 [ var_6 ] += 1 - var_5 [ var_7 ] += 1 - var_5.sort ( ) - return sum ( var_11 * var_12 for var_11 , var_12 in enumerate ( var_5 , 1 ) ) -",10,2 -643,0312.Burst Balloons_1.py,"def maxCoins( nums: List[int]) -> int: - nums = [1] + nums + [1] - n = len(nums) - dp = [[0] * n for _ in range(n)] - for l in range(2, n): - for i in range(n - l): - j = i + l - for k in range(i + 1, j): - dp[i][j] = max( - dp[i][j], dp[i][k] + dp[k][j] + nums[i] * nums[k] * nums[j] - ) - return dp[0][-1]","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0 = [ 1 ] + var_0 + [ 1 ] - var_5 = len ( var_0 ) - var_9 = [ [ 0 ] * var_5 for var_7 in range ( var_5 ) ] - for var_11 in range ( 2 , var_5 ) : - for var_12 in range ( var_5 - var_11 ) : - var_13 = var_12 + var_11 - for var_14 in range ( var_12 + 1 , var_13 ) : - var_9 [ var_12 ] [ var_13 ] = max ( var_9 [ var_12 ] [ var_13 ] , var_9 [ var_12 ] [ var_14 ] + var_9 [ var_14 ] [ var_13 ] + var_0 [ var_12 ] * var_0 [ var_14 ] * var_0 [ var_13 ] ) - return var_9 [ 0 ] [ - 1 ] -",102,3 -644,0845.Longest Mountain in Array_1.py,"def longestMountain( arr: List[int]) -> int: - left, right = 0, 1 - status = -1 - ans = 0 - while right < len(arr): - if status == -1 or status == 1: - if arr[right] == arr[right - 1]: - status = -1 - if status == -1: - if arr[right] > arr[right - 1]: - status = 1 - else: - left = right - if status == 1 and arr[right] < arr[right - 1]: - status = 2 - else: - if arr[right] == arr[right - 1]: - status = -1 - ans = max(ans, right - left) - left = right - elif arr[right] > arr[right - 1]: - status = 1 - ans = max(ans, right - left) - left = right - 1 - right += 1 - if status == 2: - ans = max(right - left, ans) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_6 = 0 , 1 - var_7 = - 1 - var_8 = 0 - while var_6 < len ( var_0 ) : - if var_7 == - 1 or var_7 == 1 : - if var_0 [ var_6 ] == var_0 [ var_6 - 1 ] : - var_7 = - 1 - if var_7 == - 1 : - if var_0 [ var_6 ] > var_0 [ var_6 - 1 ] : - var_7 = 1 - else : - var_4 = var_6 - if var_7 == 1 and var_0 [ var_6 ] < var_0 [ var_6 - 1 ] : - var_7 = 2 - else : - if var_0 [ var_6 ] == var_0 [ var_6 - 1 ] : - var_7 = - 1 - var_8 = max ( var_8 , var_6 - var_4 ) - var_4 = var_6 - elif var_0 [ var_6 ] > var_0 [ var_6 - 1 ] : - var_7 = 1 - var_8 = max ( var_8 , var_6 - var_4 ) - var_4 = var_6 - 1 - var_6 += 1 - if var_7 == 2 : - var_8 = max ( var_6 - var_4 , var_8 ) - return var_8 -",102,3 -645,0501.Find Mode in Binary Search Tree_1.py,"def dfs(root): - if root is None: - return - nonlocal mx, prev, ans, cnt - dfs(root.left) - cnt = cnt + 1 if prev == root.val else 1 - if cnt > mx: - ans = [root.val] - mx = cnt - elif cnt == mx: - ans.append(root.val) - prev = root.val - dfs(root.right)","def sample_funcname ( var_1 ) : - if var_1 is None : - return - nonlocal var_3 , var_4 , var_5 , var_6 - var_0 ( var_1.left ) - var_6 = var_6 + 1 if var_4 == var_1.val else 1 - if var_6 > var_3 : - var_5 = [ var_1.val ] - var_3 = var_6 - elif var_6 == var_3 : - var_5.append ( var_1.val ) - var_4 = var_1.val - var_0 ( var_1.right ) -",1None,2 -646,1827.Minimum Operations to Make the Array Increasing_1.py,"def minOperations( nums: List[int]) -> int: - mx = ans = 0 - for v in nums: - ans += max(0, mx + 1 - v) - mx = max(mx + 1, v) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - for var_6 in var_0 : - var_3 += max ( 0 , var_5 + 1 - var_6 ) - var_5 = max ( var_5 + 1 , var_6 ) - return var_3 -",10,2 -647,1881.Maximum Value after Insertion_1.py,"def maxValue( n: str, x: int) -> str: - if n[0] != '-': - for i, c in enumerate(n): - if int(c) < x: - return n[:i] + str(x) + n[i:] - return n + str(x) - else: - for i, c in enumerate(n[1:]): - if int(c) > x: - return n[: i + 1] + str(x) + n[i + 1 :] - return n + str(x)","def sample_funcname ( var_0 : str , var_2 : int ) -> str : - if var_0 [ 0 ] != '-' : - for var_7 , var_8 in enumerate ( var_0 ) : - if int ( var_8 ) < var_2 : - return var_0 [ : var_7 ] + str ( var_2 ) + var_0 [ var_7 : ] - return var_0 + str ( var_2 ) - else : - for var_7 , var_8 in enumerate ( var_0 [ 1 : ] ) : - if int ( var_8 ) > var_2 : - return var_0 [ : var_7 + 1 ] + str ( var_2 ) + var_0 [ var_7 + 1 : ] - return var_0 + str ( var_2 ) -",10-,3 -648,0640.Solve the Equation_1.py,"def f(s): - x = y = 0 - if s[0] != '-': - s = '+' + s - i, n = 0, len(s) - while i < n: - sign = 1 if s[i] == '+' else -1 - i += 1 - j = i - while j < n and s[j] not in '+-': - j += 1 - v = s[i:j] - if v[-1] == 'x': - x += sign * (int(v[:-1]) if len(v) > 1 else 1) - else: - y += sign * int(v) - i = j - return x, y","def sample_funcname ( var_0 ) : - var_3 = var_1 = 0 - if var_0 [ 0 ] != '-' : - var_0 = '+' + var_0 - var_6 , var_8 = 0 , len ( var_0 ) - while var_6 < var_8 : - var_10 = 1 if var_0 [ var_6 ] == '+' else - 1 - var_6 += 1 - var_11 = var_6 - while var_11 < var_8 and var_0 [ var_11 ] not in '+-' : - var_11 += 1 - var_13 = var_0 [ var_6 : var_11 ] - if var_13 [ - 1 ] == 'x' : - var_3 += var_10 * ( int ( var_13 [ : - 1 ] ) if len ( var_13 ) > 1 else 1 ) - else : - var_1 += var_10 * int ( var_13 ) - var_6 = var_11 - return var_3 , var_1 -",0+-1x+-,6 -649,0014.Longest Common Prefix_1.py,"def longestCommonPrefix( strs: List[str]) -> str: - n = len(strs) - if n == 0: - return '' - for i in range(len(strs[0])): - for j in range(1, n): - if len(strs[j]) <= i or strs[j][i] != strs[0][i]: - return strs[0][:i] - return strs[0]","def sample_funcname ( var_0 : List [ str ] ) -> str : - var_4 = len ( var_0 ) - if var_4 == 0 : - return '' - for var_8 in range ( len ( var_0 [ 0 ] ) ) : - for var_10 in range ( 1 , var_4 ) : - if len ( var_0 [ var_10 ] ) <= var_8 or var_0 [ var_10 ] [ var_8 ] != var_0 [ 0 ] [ var_8 ] : - return var_0 [ 0 ] [ : var_8 ] - return var_0 [ 0 ] -",10,3 -650,1679.Max Number of K-Sum Pairs_1.py,"def maxOperations( nums: List[int], k: int) -> int: - nums.sort() - l, r, ans = 0, len(nums) - 1, 0 - while l < r: - s = nums[l] + nums[r] - if s == k: - ans += 1 - l, r = l + 1, r - 1 - elif s > k: - r -= 1 - else: - l += 1 - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_0.sort ( ) - var_6 , var_9 , var_10 = 0 , len ( var_0 ) - 1 , 0 - while var_6 < var_9 : - var_11 = var_0 [ var_6 ] + var_0 [ var_9 ] - if var_11 == var_3 : - var_10 += 1 - var_6 , var_9 = var_6 + 1 , var_9 - 1 - elif var_11 > var_3 : - var_9 -= 1 - else : - var_6 += 1 - return var_10 -",10,2 -651,2376.Count Special Integers_1.py,"def A(m, n): - return 1 if n == 0 else A(m, n - 1) * (m - n + 1)","def sample_funcname ( var_1 , var_2 ) : - return 1 if var_2 == 0 else var_0 ( var_1 , var_2 - 1 ) * ( var_1 - var_2 + 1 ) -",10,2 -652,1051.Height Checker_1.py,"def heightChecker( heights: List[int]) -> int: - expected = sorted(heights) - return sum(a != b for a, b in zip(heights, expected))","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = sorted ( var_0 ) - return sum ( var_6 != var_7 for var_6 , var_7 in zip ( var_0 , var_4 ) ) -",,0 -654,0912.Sort an Array_1.py,"def quick_sort(nums, left, right): - if left >= right: - return - i, j = left - 1, right + 1 - x = nums[(left + right) >> 1] - while i < j: - while 1: - i += 1 - if nums[i] >= x: - break - while 1: - j -= 1 - if nums[j] <= x: - break - if i < j: - nums[i], nums[j] = nums[j], nums[i] - quick_sort(nums, left, j) - quick_sort(nums, j + 1, right)","def sample_funcname ( var_1 , var_2 , var_3 ) : - if var_2 >= var_3 : - return - var_5 , var_6 = var_2 - 1 , var_3 + 1 - var_7 = var_1 [ ( var_2 + var_3 ) >> 1 ] - while var_5 < var_6 : - while 1 : - var_5 += 1 - if var_1 [ var_5 ] >= var_7 : - break - while 1 : - var_6 -= 1 - if var_1 [ var_6 ] <= var_7 : - break - if var_5 < var_6 : - var_1 [ var_5 ] , var_1 [ var_6 ] = var_1 [ var_6 ] , var_1 [ var_5 ] - var_0 ( var_1 , var_2 , var_6 ) - var_0 ( var_1 , var_6 + 1 , var_3 ) -",1,1 -655,0171.Excel Sheet Column Number_1.py,"def titleToNumber( columnTitle: str) -> int: - res = 0 - for c in columnTitle: - res = res * 26 + (ord(c) - ord('A') + 1) - return res","def sample_funcname ( var_0 : str ) -> int : - var_4 = 0 - for var_5 in var_0 : - var_4 = var_4 * 26 + ( ord ( var_5 ) - ord ( 'A' ) + 1 ) - return var_4 -",A0126,4 -656,2078.Two Furthest Houses With Different Colors_1.py,"def maxDistance( colors: List[int]) -> int: - n = len(colors) - if colors[0] != colors[-1]: - return n - 1 - i, j = 1, n - 2 - while colors[i] == colors[0]: - i += 1 - while colors[j] == colors[0]: - j -= 1 - return max(n - i - 1, j)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - if var_0 [ 0 ] != var_0 [ - 1 ] : - return var_4 - 1 - var_7 , var_9 = 1 , var_4 - 2 - while var_0 [ var_7 ] == var_0 [ 0 ] : - var_7 += 1 - while var_0 [ var_9 ] == var_0 [ 0 ] : - var_9 -= 1 - return max ( var_4 - var_7 - 1 , var_9 ) -",102,3 -657,1800.Maximum Ascending Subarray Sum_1.py,"def maxAscendingSum( nums: List[int]) -> int: - res, cur = 0, nums[0] - for i in range(1, len(nums)): - if nums[i] > nums[i - 1]: - cur += nums[i] - else: - res = max(res, cur) - cur = nums[i] - res = max(res, cur) - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_5 = 0 , var_0 [ 0 ] - for var_9 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_9 ] > var_0 [ var_9 - 1 ] : - var_5 += var_0 [ var_9 ] - else : - var_4 = max ( var_4 , var_5 ) - var_5 = var_0 [ var_9 ] - var_4 = max ( var_4 , var_5 ) - return var_4 -",10,2 -658,0926.Flip String to Monotone Increasing_1.py,"def minFlipsMonoIncr( s: str) -> int: - n = len(s) - left, right = [0] * (n + 1), [0] * (n + 1) - ans = 0x3F3F3F3F - for i in range(1, n + 1): - left[i] = left[i - 1] + (1 if s[i - 1] == '1' else 0) - for i in range(n - 1, -1, -1): - right[i] = right[i + 1] + (1 if s[i] == '0' else 0) - for i in range(0, n + 1): - ans = min(ans, left[i] + right[i]) - return ans","def sample_funcname ( var_0 : str ) -> int : - var_4 = len ( var_0 ) - var_7 , var_8 = [ 0 ] * ( var_4 + 1 ) , [ 0 ] * ( var_4 + 1 ) - var_10 = 0x3F3F3F3F - for var_12 in range ( 1 , var_4 + 1 ) : - var_7 [ var_12 ] = var_7 [ var_12 - 1 ] + ( 1 if var_0 [ var_12 - 1 ] == '1' else 0 ) - for var_12 in range ( var_4 - 1 , - 1 , - 1 ) : - var_8 [ var_12 ] = var_8 [ var_12 + 1 ] + ( 1 if var_0 [ var_12 ] == '0' else 0 ) - for var_12 in range ( 0 , var_4 + 1 ) : - var_10 = min ( var_10 , var_7 [ var_12 ] + var_8 [ var_12 ] ) - return var_10 -",00110x3F3F3F3F,5 -659,1742.Maximum Number of Balls in a Box_1.py,"def countBalls( lowLimit: int, highLimit: int) -> int: - counter = [0] * 60 - for i in range(lowLimit, highLimit + 1): - s = 0 - while i: - s += i % 10 - i //= 10 - counter[s] += 1 - return max(counter)","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_5 = [ 0 ] * 60 - for var_8 in range ( var_0 , var_2 + 1 ) : - var_9 = 0 - while var_8 : - var_9 += var_8 % 10 - var_8 //= 10 - var_5 [ var_9 ] += 1 - return max ( var_5 ) -",600101,4 -660,0921.Minimum Add to Make Parentheses Valid_1.py,"def minAddToMakeValid( s: str) -> int: - stk = [] - for c in s: - if c == '(': - stk.append(c) - else: - if stk and stk[-1] == '(': - stk.pop() - else: - stk.append(c) - return len(stk)","def sample_funcname ( var_0 : str ) -> int : - var_3 = [ ] - for var_4 in var_0 : - if var_4 == '(' : - var_3.append ( var_4 ) - else : - if var_3 and var_3 [ - 1 ] == '(' : - var_3.pop ( ) - else : - var_3.append ( var_4 ) - return len ( var_3 ) -",(1,2 -661,1232.Check If It Is a Straight Line_1.py,"def checkStraightLine( coordinates: List[List[int]]) -> bool: - x1, y1 = coordinates[0] - x2, y2 = coordinates[1] - for x, y in coordinates[2:]: - if (x - x1) * (y2 - y1) != (y - y1) * (x2 - x1): - return False - return True","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> bool : - var_5 , var_6 = var_0 [ 0 ] - var_8 , var_9 = var_0 [ 1 ] - for var_11 , var_12 in var_0 [ 2 : ] : - if ( var_11 - var_5 ) * ( var_9 - var_6 ) != ( var_12 - var_6 ) * ( var_8 - var_5 ) : - return False - return True -",102,3 -662,0441.Arranging Coins_1.py,"def arrangeCoins( n: int) -> int: - return int(math.sqrt(2) * math.sqrt(n + 0.125) - 0.5)","def sample_funcname ( var_0 : int ) -> int : - return int ( math.sqrt ( 2 ) * math.sqrt ( var_0 + 0.125 ) - 0.5 ) -",0.1250.52,3 -663,0869.Reordered Power of 2_1.py,"def convert(n): - cnt = [0] * 10 - while n: - n, v = divmod(n, 10) - cnt[v] += 1 - return cnt","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * 10 - while var_0 : - var_0 , var_5 = divmod ( var_0 , 10 ) - var_3 [ var_5 ] += 1 - return var_3 -",1001,3 -664,1395.Count Number of Teams_1.py,"def numTeams( rating: List[int]) -> int: - n, ans = len(rating), 0 - for j in range(1, n - 1): - ia = ib = ka = kb = 0 - for i in range(j): - if rating[i] < rating[j]: - ia += 1 - elif rating[i] > rating[j]: - ib += 1 - for k in range(j + 1, n): - if rating[j] < rating[k]: - ka += 1 - elif rating[j] > rating[k]: - kb += 1 - ans += ia * ka + ib * kb - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_6 = len ( var_0 ) , 0 - for var_9 in range ( 1 , var_4 - 1 ) : - var_13 = var_10 = var_11 = var_12 = 0 - for var_14 in range ( var_9 ) : - if var_0 [ var_14 ] < var_0 [ var_9 ] : - var_13 += 1 - elif var_0 [ var_14 ] > var_0 [ var_9 ] : - var_10 += 1 - for var_15 in range ( var_9 + 1 , var_4 ) : - if var_0 [ var_9 ] < var_0 [ var_15 ] : - var_11 += 1 - elif var_0 [ var_9 ] > var_0 [ var_15 ] : - var_12 += 1 - var_6 += var_13 * var_11 + var_10 * var_12 - return var_6 -",10,2 -665,0096.Unique Binary Search Trees_1.py,"def numTrees( n: int) -> int: - dp = [0] * (n + 1) - dp[0] = 1 - for i in range(1, n + 1): - for j in range(i): - dp[i] += dp[j] * dp[i - j - 1] - return dp[-1]","def sample_funcname ( var_0 : int ) -> int : - var_4 = [ 0 ] * ( var_0 + 1 ) - var_4 [ 0 ] = 1 - for var_6 in range ( 1 , var_0 + 1 ) : - for var_7 in range ( var_6 ) : - var_4 [ var_6 ] += var_4 [ var_7 ] * var_4 [ var_6 - var_7 - 1 ] - return var_4 [ - 1 ] -",10,2 -666,2331.Evaluate Boolean Binary Tree_1.py,"def dfs(root): - if root.left is None and root.right is None: - return bool(root.val) - l, r = dfs(root.left), dfs(root.right) - return (l or r) if root.val == 2 else (l and r)","def sample_funcname ( var_1 ) : - if var_1.left is None and var_1.right is None : - return bool ( var_1.val ) - var_7 , var_8 = var_0 ( var_1.left ) , var_0 ( var_1.right ) - return ( var_7 or var_8 ) if var_1.val == 2 else ( var_7 and var_8 ) -",None2,2 -668,0421.Maximum XOR of Two Numbers in an Array_1.py,"def findMaximumXOR( nums: List[int]) -> int: - max = 0 - mask = 0 - for i in range(30, -1, -1): - current = 1 << i - mask = mask ^ current - s = set() - for num in nums: - s.add(num & mask) - flag = max | current - for prefix in s: - if prefix ^ flag in s: - max = flag - break - return max","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 0 - var_5 = 0 - for var_9 in range ( 30 , - 1 , - 1 ) : - var_10 = 1 << var_9 - var_5 = var_5 ^ var_10 - var_12 = set ( ) - for var_13 in var_0 : - var_12.add ( var_13 & var_5 ) - var_15 = var_4 | var_10 - for var_16 in var_12 : - if var_16 ^ var_15 in var_12 : - var_4 = var_15 - break - return var_4 -",1030,3 -669,1351.Count Negative Numbers in a Sorted Matrix_1.py,"def countNegatives( grid: List[List[int]]) -> int: - m, n = len(grid), len(grid[0]) - i, j = m - 1, 0 - ans = 0 - while i >= 0 and j < n: - if grid[i][j] < 0: - ans += n - j - i -= 1 - else: - j += 1 - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_8 , var_9 = var_4 - 1 , 0 - var_10 = 0 - while var_8 >= 0 and var_9 < var_6 : - if var_0 [ var_8 ] [ var_9 ] < 0 : - var_10 += var_6 - var_9 - var_8 -= 1 - else : - var_9 += 1 - return var_10 -",10,2 -670,2171.Removing Minimum Number of Magic Beans_1.py,"def minimumRemoval( beans: List[int]) -> int: - beans.sort() - ans = s = sum(beans) - n = len(beans) - for i, v in enumerate(beans): - ans = min(ans, s - v * (n - i)) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( ) - var_6 = var_4 = sum ( var_0 ) - var_8 = len ( var_0 ) - for var_10 , var_11 in enumerate ( var_0 ) : - var_6 = min ( var_6 , var_4 - var_11 * ( var_8 - var_10 ) ) - return var_6 -",,0 -671,0768.Max Chunks To Make Sorted II_1.py,"def maxChunksToSorted( arr: List[int]) -> int: - stk = [] - for v in arr: - if not stk or v >= stk[-1]: - stk.append(v) - else: - mx = stk.pop() - while stk and stk[-1] > v: - stk.pop() - stk.append(mx) - return len(stk)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_3 = [ ] - for var_4 in var_0 : - if not var_3 or var_4 >= var_3 [ - 1 ] : - var_3.append ( var_4 ) - else : - var_8 = var_3.pop ( ) - while var_3 and var_3 [ - 1 ] > var_4 : - var_3.pop ( ) - var_3.append ( var_8 ) - return len ( var_3 ) -",1,1 -672,1064.Fixed Point_1.py,"def fixedPoint( arr: List[int]) -> int: - left, right = 0, len(arr) - 1 - while left < right: - mid = (left + right) >> 1 - if arr[mid] >= mid: - right = mid - else: - left = mid + 1 - return left if arr[left] == left else -1","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_7 = 0 , len ( var_0 ) - 1 - while var_4 < var_7 : - var_8 = ( var_4 + var_7 ) >> 1 - if var_0 [ var_8 ] >= var_8 : - var_7 = var_8 - else : - var_4 = var_8 + 1 - return var_4 if var_0 [ var_4 ] == var_4 else - 1 -",10,2 -673,1331.Rank Transform of an Array_1.py,"def arrayRankTransform( arr: List[int]) -> List[int]: - m = {v: i for i, v in enumerate(sorted(set(arr)), 1)} - return [m[v] for v in arr]","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_9 = { var_3 : var_4 for var_4 , var_3 in enumerate ( sorted ( set ( var_0 ) ) , 1 ) } - return [ var_9 [ var_3 ] for var_3 in var_0 ] -",1,1 -674,0123.Best Time to Buy and Sell Stock III_1.py,"def maxProfit( prices: List[int]) -> int: - f1, f2, f3, f4 = -prices[0], 0, -prices[0], 0 - for price in prices[1:]: - f1 = max(f1, -price) - f2 = max(f2, f1 + price) - f3 = max(f3, f2 - price) - f4 = max(f4, f3 + price) - return f4","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_5 , var_6 , var_7 = - var_0 [ 0 ] , 0 , - var_0 [ 0 ] , 0 - for var_9 in var_0 [ 1 : ] : - var_4 = max ( var_4 , - var_9 ) - var_5 = max ( var_5 , var_4 + var_9 ) - var_6 = max ( var_6 , var_5 - var_9 ) - var_7 = max ( var_7 , var_6 + var_9 ) - return var_7 -",10,2 -675,2200.Find All K-Distant Indices in an Array_1.py,"def findKDistantIndices( nums: List[int], key: int, k: int) -> List[int]: - ans = [] - n = len(nums) - for i in range(n): - for j in range(n): - if abs(i - j) <= k and nums[j] == key: - ans.append(i) - break - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int , var_4 : int ) -> List [ int ] : - var_5 = [ ] - var_7 = len ( var_0 ) - for var_9 in range ( var_7 ) : - for var_10 in range ( var_7 ) : - if abs ( var_9 - var_10 ) <= var_4 and var_0 [ var_10 ] == var_3 : - var_5.append ( var_9 ) - break - return var_5 -",,0 -676,0668.Kth Smallest Number in Multiplication Table_1.py,"def findKthNumber( m: int, n: int, k: int) -> int: - left, right = 1, m * n - while left < right: - mid = (left + right) >> 1 - cnt = 0 - for i in range(1, m + 1): - cnt += min(mid // i, n) - if cnt >= k: - right = mid - else: - left = mid + 1 - return left","def sample_funcname ( var_0 : int , var_2 : int , var_3 : int ) -> int : - var_5 , var_6 = 1 , var_0 * var_2 - while var_5 < var_6 : - var_7 = ( var_5 + var_6 ) >> 1 - var_9 = 0 - for var_11 in range ( 1 , var_0 + 1 ) : - var_9 += min ( var_7 // var_11 , var_2 ) - if var_9 >= var_3 : - var_6 = var_7 - else : - var_5 = var_7 + 1 - return var_5 -",10,2 -677,1120.Maximum Average Subtree_1.py,"def dfs(root): - if root is None: - return 0, 0 - ls, ln = dfs(root.left) - rs, rn = dfs(root.right) - s = ls + root.val + rs - n = ln + 1 + rn - nonlocal ans - ans = max(ans, s / n) - return s, n","def sample_funcname ( var_1 ) : - if var_1 is None : - return 0 , 0 - var_4 , var_6 = var_0 ( var_1.left ) - var_7 , var_9 = var_0 ( var_1.right ) - var_11 = var_4 + var_1.val + var_7 - var_13 = var_6 + 1 + var_9 - nonlocal var_14 - var_14 = max ( var_14 , var_11 / var_13 ) - return var_11 , var_13 -",10None,3 -678,1031.Maximum Sum of Two Non-Overlapping Subarrays_1.py,"def maxSumTwoNoOverlap( nums: List[int], firstLen: int, secondLen: int) -> int: - n = len(nums) - s = [0] * (n + 1) - for i in range(1, n + 1): - s[i] = s[i - 1] + nums[i - 1] - ans1, ans2, fm, sm = 0, 0, 0, 0 - for i in range(n - firstLen - secondLen + 1): - fm = max(fm, s[i + firstLen] - s[i]) - ans1 = max(fm + s[i + firstLen + secondLen] - s[i + firstLen], ans1) - for i in range(n - firstLen - secondLen + 1): - sm = max(sm, s[i + secondLen] - s[i]) - ans2 = max(sm + s[i + firstLen + secondLen] - s[i + secondLen], ans2) - return max(ans1, ans2)","def sample_funcname ( var_0 : List [ int ] , var_3 : int , var_4 : int ) -> int : - var_6 = len ( var_0 ) - var_9 = [ 0 ] * ( var_6 + 1 ) - for var_11 in range ( 1 , var_6 + 1 ) : - var_9 [ var_11 ] = var_9 [ var_11 - 1 ] + var_0 [ var_11 - 1 ] - var_12 , var_13 , var_14 , var_15 = 0 , 0 , 0 , 0 - for var_11 in range ( var_6 - var_3 - var_4 + 1 ) : - var_14 = max ( var_14 , var_9 [ var_11 + var_3 ] - var_9 [ var_11 ] ) - var_12 = max ( var_14 + var_9 [ var_11 + var_3 + var_4 ] - var_9 [ var_11 + var_3 ] , var_12 ) - for var_11 in range ( var_6 - var_3 - var_4 + 1 ) : - var_15 = max ( var_15 , var_9 [ var_11 + var_4 ] - var_9 [ var_11 ] ) - var_13 = max ( var_15 + var_9 [ var_11 + var_3 + var_4 ] - var_9 [ var_11 + var_4 ] , var_13 ) - return max ( var_12 , var_13 ) -",10,2 -679,0713.Subarray Product Less Than K_1.py,"def numSubarrayProductLessThanK( nums: List[int], k: int) -> int: - ans, s, j = 0, 1, 0 - for i, v in enumerate(nums): - s *= v - while j <= i and s >= k: - s //= nums[j] - j += 1 - ans += i - j + 1 - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_7 , var_8 = 0 , 1 , 0 - for var_10 , var_11 in enumerate ( var_0 ) : - var_7 *= var_11 - while var_8 <= var_10 and var_7 >= var_3 : - var_7 //= var_0 [ var_8 ] - var_8 += 1 - var_5 += var_10 - var_8 + 1 - return var_5 -",10,2 -680,0307.Range Sum Query - Mutable_1.py,"def lowbit(x): - return x & -x","def sample_funcname ( var_0 ) : - return var_0 & - var_0 -",,0 -681,1672.Richest Customer Wealth_1.py,"def maximumWealth( accounts: List[List[int]]) -> int: - return max(sum(account) for account in accounts)","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - return max ( sum ( var_5 ) for var_5 in var_0 ) -",,0 -682,0887.Super Egg Drop_1.py,"def superEggDrop( K: int, N: int) -> int: - dp = [1] * (K) - while dp[K - 1] < N: - for i in range(K - 1, 0, -1): - dp[i] = dp[i] + dp[i - 1] + 1 - dp[0] = dp[0] + 1 - return dp[0]","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_4 = [ 1 ] * ( var_0 ) - while var_4 [ var_0 - 1 ] < var_2 : - for var_7 in range ( var_0 - 1 , 0 , - 1 ) : - var_4 [ var_7 ] = var_4 [ var_7 ] + var_4 [ var_7 - 1 ] + 1 - var_4 [ 0 ] = var_4 [ 0 ] + 1 - return var_4 [ 0 ] -",10,2 -683,0670.Maximum Swap_1.py,"def maximumSwap( num: int) -> int: - chars = list(str(num)) - n = len(chars) - for i in range(n - 1): - mx = i + 1 - for j in range(i + 1, n): - if ord(chars[j]) >= ord(chars[mx]): - mx = j - if ord(chars[i]) < ord(chars[mx]): - chars[i], chars[mx] = chars[mx], chars[i] - break - return int(''.join(chars))","def sample_funcname ( var_0 : int ) -> int : - var_4 = list ( str ( var_0 ) ) - var_6 = len ( var_4 ) - for var_9 in range ( var_6 - 1 ) : - var_10 = var_9 + 1 - for var_11 in range ( var_9 + 1 , var_6 ) : - if ord ( var_4 [ var_11 ] ) >= ord ( var_4 [ var_10 ] ) : - var_10 = var_11 - if ord ( var_4 [ var_9 ] ) < ord ( var_4 [ var_10 ] ) : - var_4 [ var_9 ] , var_4 [ var_10 ] = var_4 [ var_10 ] , var_4 [ var_9 ] - break - return int ( ''.join ( var_4 ) ) -",1,2 -684,0524.Longest Word in Dictionary through Deleting_1.py,"def check(a, b): - m, n = len(a), len(b) - i = j = 0 - while i < m and j < n: - if a[i] == b[j]: - j += 1 - i += 1 - return j == n","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = len ( var_0 ) , len ( var_1 ) - var_7 = var_5 = 0 - while var_7 < var_3 and var_5 < var_4 : - if var_0 [ var_7 ] == var_1 [ var_5 ] : - var_5 += 1 - var_7 += 1 - return var_5 == var_4 -",10,2 -685,1367.Linked List in Binary Tree_1.py,"def dfs(head, root): - if head is None: - return True - if root is None: - return False - if root.val != head.val: - return False - return dfs(head.next, root.left) or dfs(head.next, root.right)","def sample_funcname ( var_1 , var_2 ) : - if var_1 is None : - return True - if var_2 is None : - return False - if var_2.val != var_1.val : - return False - return var_0 ( var_1.next , var_2.left ) or var_0 ( var_1.next , var_2.right ) -",None,1 -686,0424.Longest Repeating Character Replacement_1.py,"def characterReplacement( s: str, k: int) -> int: - counter = [0] * 26 - i = j = maxCnt = 0 - while i < len(s): - counter[ord(s[i]) - ord('A')] += 1 - maxCnt = max(maxCnt, counter[ord(s[i]) - ord('A')]) - if i - j + 1 > maxCnt + k: - counter[ord(s[j]) - ord('A')] -= 1 - j += 1 - i += 1 - return i - j","def sample_funcname ( var_0 : str , var_2 : int ) -> int : - var_6 = [ 0 ] * 26 - var_9 = var_7 = var_8 = 0 - while var_9 < len ( var_0 ) : - var_6 [ ord ( var_0 [ var_9 ] ) - ord ( 'A' ) ] += 1 - var_8 = max ( var_8 , var_6 [ ord ( var_0 [ var_9 ] ) - ord ( 'A' ) ] ) - if var_9 - var_7 + 1 > var_8 + var_2 : - var_6 [ ord ( var_0 [ var_7 ] ) - ord ( 'A' ) ] -= 1 - var_7 += 1 - var_9 += 1 - return var_9 - var_7 -",A0126,4 -687,0430.Flatten a Multilevel Doubly Linked List_1.py,"def preorder(pre, cur): - if cur is None: - return pre - cur.prev = pre - pre.next = cur - - t = cur.next - tail = preorder(cur, cur.child) - cur.child = None - return preorder(tail, t)","def sample_funcname ( var_1 , var_2 ) : - if var_2 is None : - return var_1 - var_2.prev = var_1 - var_1.next = var_2 - var_6 = var_2.next - var_8 = var_0 ( var_2 , var_2.child ) - var_2.child = None - return var_0 ( var_8 , var_6 ) -",None,1 -688,0299.Bulls and Cows_1.py,"def getHint( secret: str, guess: str) -> str: - x = y = 0 - cnt1 = [0] * 10 - cnt2 = [0] * 10 - for i in range(len(secret)): - if secret[i] == guess[i]: - x += 1 - else: - cnt1[int(secret[i])] += 1 - cnt2[int(guess[i])] += 1 - - for i in range(10): - y += min(cnt1[i], cnt2[i]) - return f'{x}A{y}B'","def sample_funcname ( var_0 : str , var_2 : str ) -> str : - var_5 = var_3 = 0 - var_7 = [ 0 ] * 10 - var_8 = [ 0 ] * 10 - for var_11 in range ( len ( var_0 ) ) : - if var_0 [ var_11 ] == var_2 [ var_11 ] : - var_5 += 1 - else : - var_7 [ int ( var_0 [ var_11 ] ) ] += 1 - var_8 [ int ( var_2 [ var_11 ] ) ] += 1 - for var_11 in range ( 10 ) : - var_3 += min ( var_7 [ var_11 ] , var_8 [ var_11 ] ) - return f'{var_5}A{var_3}B' -",1001f{var_5}A{var_3}B,4 -689,2119.A Number After a Double Reversal_1.py,"def isSameAfterReversals( num: int) -> bool: - return num == 0 or num % 10 != 0","def sample_funcname ( var_0 : int ) -> bool : - return var_0 == 0 or var_0 % 10 != 0 -",100,2 -690,2393.Count Strictly Increasing Subarrays_1.py,"def countSubarrays( nums: List[int]) -> int: - ans = i = 0 - while i < len(nums): - j = i + 1 - while j < len(nums) and nums[j] > nums[j - 1]: - j += 1 - cnt = j - i - ans += (1 + cnt) * cnt // 2 - i = j - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - while var_3 < len ( var_0 ) : - var_8 = var_3 + 1 - while var_8 < len ( var_0 ) and var_0 [ var_8 ] > var_0 [ var_8 - 1 ] : - var_8 += 1 - var_9 = var_8 - var_3 - var_5 += ( 1 + var_9 ) * var_9 // 2 - var_3 = var_8 - return var_5 -",102,3 -691,0545.Boundary of Binary Tree_1.py,"def is_leaf( node) -> bool: - return node and node.left is None and node.right is None","def sample_funcname ( var_0 ) -> bool : - return var_0 and var_0.left is None and var_0.right is None -",None,1 -692,1936.Add Minimum Number of Rungs_1.py,"def addRungs( rungs: List[int], dist: int) -> int: - prev = res = 0 - for rung in rungs: - res += (rung - prev - 1) // dist - prev = rung - return res","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_6 = var_4 = 0 - for var_7 in var_0 : - var_4 += ( var_7 - var_6 - 1 ) // var_3 - var_6 = var_7 - return var_4 -",10,2 -693,0908.Smallest Range I_1.py,"def smallestRangeI( nums: List[int], k: int) -> int: - mx, mi = max(nums), min(nums) - return max(0, mx - mi - k * 2)","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_7 = max ( var_0 ) , min ( var_0 ) - return max ( 0 , var_5 - var_7 - var_3 * 2 ) -",02,2 -694,0260.Single Number III_1.py,"def singleNumber( nums: List[int]) -> List[int]: - eor = 0 - for x in nums: - eor ^= x - lowbit = eor & (-eor) - ans = [0, 0] - for x in nums: - if (x & lowbit) == 0: - ans[0] ^= x - ans[1] = eor ^ ans[0] - return ans","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 = 0 - for var_5 in var_0 : - var_4 ^= var_5 - var_6 = var_4 & ( - var_4 ) - var_7 = [ 0 , 0 ] - for var_5 in var_0 : - if ( var_5 & var_6 ) == 0 : - var_7 [ 0 ] ^= var_5 - var_7 [ 1 ] = var_4 ^ var_7 [ 0 ] - return var_7 -",10,2 -695,1985.Find the Kth Largest Integer in the Array_1.py,"def cmp(a, b): - if len(a) != len(b): - return len(b) - len(a) - return 1 if b > a else -1","def sample_funcname ( var_0 , var_1 ) : - if len ( var_0 ) != len ( var_1 ) : - return len ( var_1 ) - len ( var_0 ) - return 1 if var_1 > var_0 else - 1 -",1,1 -696,0309.Best Time to Buy and Sell Stock with Cooldown_1.py,"def maxProfit( prices: List[int]) -> int: - f1, f2, f3 = -prices[0], 0, 0 - for price in prices[1:]: - pf1, pf2, pf3 = f1, f2, f3 - f1 = max(pf1, pf3 - price) - f2 = max(pf2, pf1 + price) - f3 = max(pf3, pf2) - return f2","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_5 , var_6 = - var_0 [ 0 ] , 0 , 0 - for var_8 in var_0 [ 1 : ] : - var_9 , var_10 , var_11 = var_4 , var_5 , var_6 - var_4 = max ( var_9 , var_11 - var_8 ) - var_5 = max ( var_10 , var_9 + var_8 ) - var_6 = max ( var_11 , var_10 ) - return var_5 -",10,2 -697,2110.Number of Smooth Descent Periods of a Stock_1.py,"def getDescentPeriods( prices: List[int]) -> int: - i, n = 0, len(prices) - ans = 0 - while i < n: - j = i - while j + 1 < n and prices[j] - prices[j + 1] == 1: - j += 1 - t = j - i + 1 - ans += t * (t + 1) // 2 - i = j + 1 - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_6 = 0 , len ( var_0 ) - var_7 = 0 - while var_4 < var_6 : - var_8 = var_4 - while var_8 + 1 < var_6 and var_0 [ var_8 ] - var_0 [ var_8 + 1 ] == 1 : - var_8 += 1 - var_10 = var_8 - var_4 + 1 - var_7 += var_10 * ( var_10 + 1 ) // 2 - var_4 = var_8 + 1 - return var_7 -",102,3 -698,2229.Check if an Array Is Consecutive_1.py,"def isConsecutive( nums: List[int]) -> bool: - mi, mx = min(nums), max(nums) - n = len(nums) - return len(set(nums)) == n and mx == mi + n - 1","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_5 , var_7 = min ( var_0 ) , max ( var_0 ) - var_9 = len ( var_0 ) - return len ( set ( var_0 ) ) == var_9 and var_7 == var_5 + var_9 - 1 -",1,1 -699,2226.Maximum Candies Allocated to K Children_1.py,"def maximumCandies( candies: List[int], k: int) -> int: - left, right = 0, max(candies) - while left < right: - mid = (left + right + 1) >> 1 - cnt = sum(v // mid for v in candies) - if cnt >= k: - left = mid - else: - right = mid - 1 - return left","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_7 = 0 , max ( var_0 ) - while var_5 < var_7 : - var_9 = ( var_5 + var_7 + 1 ) >> 1 - var_12 = sum ( var_10 // var_9 for var_10 in var_0 ) - if var_12 >= var_3 : - var_5 = var_9 - else : - var_7 = var_9 - 1 - return var_5 -",10,2 -700,1684.Count the Number of Consistent Strings_1.py,"def countConsistentStrings( allowed: str, words: List[str]) -> int: - res = 0 - chars = set(allowed) - for word in words: - find = True - for c in word: - if c not in chars: - find = False - break - if find: - res += 1 - return res","def sample_funcname ( var_0 : str , var_2 : List [ str ] ) -> int : - var_6 = 0 - var_8 = set ( var_0 ) - for var_9 in var_2 : - var_11 = True - for var_12 in var_9 : - if var_12 not in var_8 : - var_11 = False - break - if var_11 : - var_6 += 1 - return var_6 -",10,2 -701,0010.Regular Expression Matching_1.py,"def isMatch( s: str, p: str) -> bool: - m, n = len(s), len(p) - if n == 0: - return m == 0 - dp = [[False] * (n + 1) for _ in range(m + 1)] - dp[0][0] = True - for j in range(2, n + 1): - if p[j - 1] == '*': - dp[0][j] = dp[0][j - 2] - for i in range(1, m + 1): - for j in range(1, n + 1): - if s[i - 1] == p[j - 1] or p[j - 1] == '.': - dp[i][j] = dp[i - 1][j - 1] - elif p[j - 1] == '*': - if p[j - 2] == '.' or p[j - 2] == s[i - 1]: - dp[i][j] = dp[i][j - 2] or dp[i - 1][j] - else: - dp[i][j] = dp[i][j - 2] - return dp[-1][-1]","def sample_funcname ( var_0 : str , var_2 : str ) -> bool : - var_5 , var_6 = len ( var_0 ) , len ( var_2 ) - if var_6 == 0 : - return var_5 == 0 - var_12 = [ [ False ] * ( var_6 + 1 ) for var_10 in range ( var_5 + 1 ) ] - var_12 [ 0 ] [ 0 ] = True - for var_15 in range ( 2 , var_6 + 1 ) : - if var_2 [ var_15 - 1 ] == '*' : - var_12 [ 0 ] [ var_15 ] = var_12 [ 0 ] [ var_15 - 2 ] - for var_17 in range ( 1 , var_5 + 1 ) : - for var_15 in range ( 1 , var_6 + 1 ) : - if var_0 [ var_17 - 1 ] == var_2 [ var_15 - 1 ] or var_2 [ var_15 - 1 ] == '.' : - var_12 [ var_17 ] [ var_15 ] = var_12 [ var_17 - 1 ] [ var_15 - 1 ] - elif var_2 [ var_15 - 1 ] == '*' : - if var_2 [ var_15 - 2 ] == '.' or var_2 [ var_15 - 2 ] == var_0 [ var_17 - 1 ] : - var_12 [ var_17 ] [ var_15 ] = var_12 [ var_17 ] [ var_15 - 2 ] or var_12 [ var_17 - 1 ] [ var_15 ] - else : - var_12 [ var_17 ] [ var_15 ] = var_12 [ var_17 ] [ var_15 - 2 ] - return var_12 [ - 1 ] [ - 1 ] -",0*.21,5 -702,2401.Longest Nice Subarray_1.py,"def longestNiceSubarray( nums: List[int]) -> int: - ans = j = t = 0 - for i, v in enumerate(nums): - while t & v: - t ^= nums[j] - j += 1 - t |= v - ans = max(ans, i - j + 1) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_6 = var_3 = var_4 = 0 - for var_8 , var_9 in enumerate ( var_0 ) : - while var_4 & var_9 : - var_4 ^= var_0 [ var_3 ] - var_3 += 1 - var_4 |= var_9 - var_6 = max ( var_6 , var_8 - var_3 + 1 ) - return var_6 -",10,2 -703,0221.Maximal Square_1.py,"def maximalSquare( matrix: List[List[str]]) -> int: - m, n = len(matrix), len(matrix[0]) - dp = [[0] * (n + 1) for _ in range(m + 1)] - mx = 0 - for i in range(m): - for j in range(n): - if matrix[i][j] == '1': - dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i + 1][j], dp[i][j]) + 1 - mx = max(mx, dp[i + 1][j + 1]) - return mx * mx","def sample_funcname ( var_0 : List [ List [ str ] ] ) -> int : - var_5 , var_7 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_11 = [ [ 0 ] * ( var_7 + 1 ) for var_9 in range ( var_5 + 1 ) ] - var_12 = 0 - for var_13 in range ( var_5 ) : - for var_14 in range ( var_7 ) : - if var_0 [ var_13 ] [ var_14 ] == '1' : - var_11 [ var_13 + 1 ] [ var_14 + 1 ] = min ( var_11 [ var_13 ] [ var_14 + 1 ] , var_11 [ var_13 + 1 ] [ var_14 ] , var_11 [ var_13 ] [ var_14 ] ) + 1 - var_12 = max ( var_12 , var_11 [ var_13 + 1 ] [ var_14 + 1 ] ) - return var_12 * var_12 -",101,3 -704,1688.Count of Matches in Tournament_1.py,"def numberOfMatches( n: int) -> int: - return n - 1","def sample_funcname ( var_0 : int ) -> int : - return var_0 - 1 -",1,1 -705,0452.Minimum Number of Arrows to Burst Balloons_1.py,"def findMinArrowShots( points: List[List[int]]) -> int: - points.sort(key=lambda x: x[1]) - ans = 1 - x = points[0][1] - for a, b in points: - if a > x: - ans += 1 - x = b - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_0.sort ( var_4 = lambda var_5 : var_5 [ 1 ] ) - var_7 = 1 - var_5 = var_0 [ 0 ] [ 1 ] - for var_9 , var_10 in var_0 : - if var_9 > var_5 : - var_7 += 1 - var_5 = var_10 - return var_7 -",10,2 -706,0256.Paint House_1.py,"def minCost( costs: List[List[int]]) -> int: - a = b = c = 0 - for ca, cb, cc in costs: - a, b, c = min(b, c) + ca, min(a, c) + cb, min(a, b) + cc - return min(a, b, c)","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_6 = var_3 = var_4 = 0 - for var_7 , var_8 , var_9 in var_0 : - var_6 , var_3 , var_4 = min ( var_3 , var_4 ) + var_7 , min ( var_6 , var_4 ) + var_8 , min ( var_6 , var_3 ) + var_9 - return min ( var_6 , var_3 , var_4 ) -",0,1 -707,1047.Remove All Adjacent Duplicates In String_1.py,"def removeDuplicates( s: str) -> str: - stk = [] - for c in s: - if stk and stk[-1] == c: - stk.pop() - else: - stk.append(c) - return ''.join(stk)","def sample_funcname ( var_0 : str ) -> str : - var_2 = [ ] - for var_3 in var_0 : - if var_2 and var_2 [ - 1 ] == var_3 : - var_2.pop ( ) - else : - var_2.append ( var_3 ) - return ''.join ( var_2 ) -",1,2 -708,0289.Game of Life_1.py,"def gameOfLife( board: List[List[int]]) -> None: - m, n = len(board), len(board[0]) - dirs = [[-1, 0], [1, 0], [0, -1], [0, 1], [-1, -1], [-1, 1], [1, -1], [1, 1]] - for i in range(m): - for j in range(n): - cnt = sum( - 1 - for a, b in dirs - if 0 <= i + a < m - and 0 <= j + b < n - and board[i + a][j + b] in (1, 2) - ) - if board[i][j] == 1 and (cnt < 2 or cnt > 3): - board[i][j] = 2 - elif board[i][j] == 0 and (cnt == 3): - board[i][j] = 3 - for i in range(m): - for j in range(n): - board[i][j] %= 2","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> None : - var_5 , var_7 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_9 = [ [ - 1 , 0 ] , [ 1 , 0 ] , [ 0 , - 1 ] , [ 0 , 1 ] , [ - 1 , - 1 ] , [ - 1 , 1 ] , [ 1 , - 1 ] , [ 1 , 1 ] ] - for var_11 in range ( var_5 ) : - for var_12 in range ( var_7 ) : - var_17 = sum ( 1 for var_16 , var_13 in var_9 if 0 <= var_11 + var_16 < var_5 and 0 <= var_12 + var_13 < var_7 and var_0 [ var_11 + var_16 ] [ var_12 + var_13 ] in ( 1 , 2 ) ) - if var_0 [ var_11 ] [ var_12 ] == 1 and ( var_17 < 2 or var_17 > 3 ) : - var_0 [ var_11 ] [ var_12 ] = 2 - elif var_0 [ var_11 ] [ var_12 ] == 0 and ( var_17 == 3 ) : - var_0 [ var_11 ] [ var_12 ] = 3 - for var_11 in range ( var_5 ) : - for var_12 in range ( var_7 ) : - var_0 [ var_11 ] [ var_12 ] %= 2 -",0None213,5 -709,0226.Invert Binary Tree_1.py,"def dfs(root): - if root is None: - return - root.left, root.right = root.right, root.left - dfs(root.left) - dfs(root.right)","def sample_funcname ( var_1 ) : - if var_1 is None : - return - var_1.left , var_1.right = var_1.right , var_1.left - var_0 ( var_1.left ) - var_0 ( var_1.right ) -",None,1 -710,0507.Perfect Number_1.py,"def checkPerfectNumber( num: int) -> bool: - if num == 1: - return False - s, i = 1, 2 - while i * i <= num: - if num % i == 0: - s += i - if i != num // i: - s += num // i - i += 1 - return s == num","def sample_funcname ( var_0 : int ) -> bool : - if var_0 == 1 : - return False - var_5 , var_7 = 1 , 2 - while var_7 * var_7 <= var_0 : - if var_0 % var_7 == 0 : - var_5 += var_7 - if var_7 != var_0 // var_7 : - var_5 += var_0 // var_7 - var_7 += 1 - return var_5 == var_0 -",102,3 -711,1769.Minimum Number of Operations to Move All Balls to Each Box_1.py,"def minOperations( boxes: str) -> List[int]: - n = len(boxes) - res = [0] * n - total = 0 - for i, b in enumerate(boxes): - if b == '1': - res[0] += i - total += 1 - left, right = 0, total - for i in range(1, n): - if boxes[i - 1] == '1': - left += 1 - right -= 1 - res[i] = res[i - 1] + left - right - return res","def sample_funcname ( var_0 : str ) -> List [ int ] : - var_5 = len ( var_0 ) - var_7 = [ 0 ] * var_5 - var_8 = 0 - for var_10 , var_11 in enumerate ( var_0 ) : - if var_11 == '1' : - var_7 [ 0 ] += var_10 - var_8 += 1 - var_14 , var_15 = 0 , var_8 - for var_10 in range ( 1 , var_5 ) : - if var_0 [ var_10 - 1 ] == '1' : - var_14 += 1 - var_15 -= 1 - var_7 [ var_10 ] = var_7 [ var_10 - 1 ] + var_14 - var_15 - return var_7 -",101,3 -712,0442.Find All Duplicates in an Array_1.py,"def findDuplicates( nums: List[int]) -> List[int]: - for i in range(len(nums)): - while nums[i] != nums[nums[i] - 1]: - nums[nums[i] - 1], nums[i] = nums[i], nums[nums[i] - 1] - return [v for i, v in enumerate(nums) if v != i + 1]","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - for var_5 in range ( len ( var_0 ) ) : - while var_0 [ var_5 ] != var_0 [ var_0 [ var_5 ] - 1 ] : - var_0 [ var_0 [ var_5 ] - 1 ] , var_0 [ var_5 ] = var_0 [ var_5 ] , var_0 [ var_0 [ var_5 ] - 1 ] - return [ var_7 for var_5 , var_7 in enumerate ( var_0 ) if var_7 != var_5 + 1 ] -",1,1 -713,0110.Balanced Binary Tree_1.py,"def height(root): - if root is None: - return 0 - l, r = height(root.left), height(root.right) - if l == -1 or r == -1 or abs(l - r) > 1: - return -1 - return 1 + max(l, r)","def sample_funcname ( var_1 ) : - if var_1 is None : - return 0 - var_5 , var_7 = var_0 ( var_1.left ) , var_0 ( var_1.right ) - if var_5 == - 1 or var_7 == - 1 or abs ( var_5 - var_7 ) > 1 : - return - 1 - return 1 + max ( var_5 , var_7 ) -",10None,3 -714,0129.Sum Root to Leaf Numbers_1.py,"def dfs(root, presum): - if root is None: - return 0 - s = 10 * presum + root.val - if root.left is None and root.right is None: - return s - return dfs(root.left, s) + dfs(root.right, s)","def sample_funcname ( var_1 , var_2 ) : - if var_1 is None : - return 0 - var_7 = 10 * var_2 + var_1.val - if var_1.left is None and var_1.right is None : - return var_7 - return var_0 ( var_1.left , var_7 ) + var_0 ( var_1.right , var_7 ) -",100None,3 -715,0041.First Missing Positive_1.py,"def firstMissingPositive( nums): - i = 1 - while i in nums: - i += 1 - return i","def sample_funcname ( var_0 ) : - var_2 = 1 - while var_2 in var_0 : - var_2 += 1 - return var_2 -",1,1 -716,1446.Consecutive Characters_1.py,"def maxPower( s: str) -> int: - ans = t = 0 - for i, c in enumerate(s): - if i == 0 or c == s[i - 1]: - t += 1 - else: - t = 1 - ans = max(ans, t) - return ans","def sample_funcname ( var_0 : str ) -> int : - var_5 = var_3 = 0 - for var_7 , var_8 in enumerate ( var_0 ) : - if var_7 == 0 or var_8 == var_0 [ var_7 - 1 ] : - var_3 += 1 - else : - var_3 = 1 - var_5 = max ( var_5 , var_3 ) - return var_5 -",10,2 -718,1944.Number of Visible People in a Queue_1.py,"def canSeePersonsCount( heights: List[int]) -> List[int]: - n = len(heights) - ans = [0] * n - stack = list() - - for i in range(n - 1, -1, -1): - while stack: - ans[i] += 1 - if heights[i] > stack[-1]: - stack.pop() - else: - break - stack.append(heights[i]) - - return ans","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 = len ( var_0 ) - var_6 = [ 0 ] * var_4 - var_8 = list ( ) - for var_11 in range ( var_4 - 1 , - 1 , - 1 ) : - while var_8 : - var_6 [ var_11 ] += 1 - if var_0 [ var_11 ] > var_8 [ - 1 ] : - var_8.pop ( ) - else : - break - var_8.append ( var_0 [ var_11 ] ) - return var_6 -",10,2 -719,0495.Teemo Attacking_1.py,"def findPoisonedDuration( timeSeries: List[int], duration: int) -> int: - n, res = len(timeSeries), duration - for i in range(n - 1): - res += min(duration, timeSeries[i + 1] - timeSeries[i]) - return res","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_6 = len ( var_0 ) , var_3 - for var_9 in range ( var_5 - 1 ) : - var_6 += min ( var_3 , var_0 [ var_9 + 1 ] - var_0 [ var_9 ] ) - return var_6 -",1,1 -720,1078.Occurrences After Bigram_1.py,"def findOcurrences( text: str, first: str, second: str) -> List[str]: - words = text.split(' ') - return [ - words[i + 2] - for i in range(len(words) - 2) - if words[i] == first and words[i + 1] == second - ]","def sample_funcname ( var_0 : str , var_2 : str , var_3 : str ) -> List [ str ] : - var_7 = var_0.split ( ' ' ) - return [ var_7 [ var_8 + 2 ] for var_8 in range ( len ( var_7 ) - 2 ) if var_7 [ var_8 ] == var_2 and var_7 [ var_8 + 1 ] == var_3 ] -",1 2,3 -721,0242.Valid Anagram_1.py,"def isAnagram( s: str, t: str) -> bool: - if len(s) != len(t): - return False - chars = [0] * 26 - for i in range(len(s)): - chars[ord(s[i]) - ord('a')] += 1 - chars[ord(t[i]) - ord('a')] -= 1 - return all(c == 0 for c in chars)","def sample_funcname ( var_0 : str , var_2 : str ) -> bool : - if len ( var_0 ) != len ( var_2 ) : - return False - var_8 = [ 0 ] * 26 - for var_10 in range ( len ( var_0 ) ) : - var_8 [ ord ( var_0 [ var_10 ] ) - ord ( 'a' ) ] += 1 - var_8 [ ord ( var_2 [ var_10 ] ) - ord ( 'a' ) ] -= 1 - return all ( var_15 == 0 for var_15 in var_8 ) -",a0126,4 -722,2202.Maximize the Topmost Element After K Moves_1.py,"def maximumTop( nums: List[int], k: int) -> int: - if k == 0: - return nums[0] - n = len(nums) - if n == 1: - if k % 2: - return -1 - return nums[0] - ans = max(nums[: k - 1], default=-1) - if k < n: - ans = max(ans, nums[k]) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - if var_3 == 0 : - return var_0 [ 0 ] - var_6 = len ( var_0 ) - if var_6 == 1 : - if var_3 % 2 : - return - 1 - return var_0 [ 0 ] - var_11 = max ( var_0 [ : var_3 - 1 ] , var_10 = - 1 ) - if var_3 < var_6 : - var_11 = max ( var_11 , var_0 [ var_3 ] ) - return var_11 -",102,3 -724,0551.Student Attendance Record I_1.py,"def checkRecord( s: str) -> bool: - return s.count('A') <= 1 and 'LLL' not in s","def sample_funcname ( var_0 : str ) -> bool : - return var_0.count ( 'A' ) <= 1 and 'LLL' not in var_0 -",1ALLL,3 -725,1408.String Matching in an Array_1.py,"def stringMatching( words: List[str]) -> List[str]: - ans = [] - for i, w1 in enumerate(words): - for j, w2 in enumerate(words): - if i != j and w1 in w2: - ans.append(w1) - break - return ans","def sample_funcname ( var_0 : List [ str ] ) -> List [ str ] : - var_3 = [ ] - for var_5 , var_6 in enumerate ( var_0 ) : - for var_7 , var_8 in enumerate ( var_0 ) : - if var_5 != var_7 and var_6 in var_8 : - var_3.append ( var_6 ) - break - return var_3 -",,0 -726,0645.Set Mismatch_1.py,"def findErrorNums( nums: List[int]) -> List[int]: - eor, n = 0, len(nums) - for i in range(1, n + 1): - eor ^= i ^ nums[i - 1] - diff = eor & (~eor + 1) - a = 0 - for i in range(1, n + 1): - if (nums[i - 1] & diff) == 0: - a ^= nums[i - 1] - if (i & diff) == 0: - a ^= i - b = eor ^ a - for num in nums: - if a == num: - return [a, b] - return [b, a]","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 , var_6 = 0 , len ( var_0 ) - for var_9 in range ( 1 , var_6 + 1 ) : - var_4 ^= var_9 ^ var_0 [ var_9 - 1 ] - var_10 = var_4 & ( ~ var_4 + 1 ) - var_11 = 0 - for var_9 in range ( 1 , var_6 + 1 ) : - if ( var_0 [ var_9 - 1 ] & var_10 ) == 0 : - var_11 ^= var_0 [ var_9 - 1 ] - if ( var_9 & var_10 ) == 0 : - var_11 ^= var_9 - var_12 = var_4 ^ var_11 - for var_13 in var_0 : - if var_11 == var_13 : - return [ var_11 , var_12 ] - return [ var_12 , var_11 ] -",10,2 -727,0581.Shortest Unsorted Continuous Subarray_1.py,"def findUnsortedSubarray( nums: List[int]) -> int: - arr = sorted(nums) - left, right = 0, len(nums) - 1 - while left <= right and nums[left] == arr[left]: - left += 1 - while left <= right and nums[right] == arr[right]: - right -= 1 - return right - left + 1","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = sorted ( var_0 ) - var_6 , var_9 = 0 , len ( var_0 ) - 1 - while var_6 <= var_9 and var_0 [ var_6 ] == var_4 [ var_6 ] : - var_6 += 1 - while var_6 <= var_9 and var_0 [ var_9 ] == var_4 [ var_9 ] : - var_9 -= 1 - return var_9 - var_6 + 1 -",10,2 -728,0689.Maximum Sum of 3 Non-Overlapping Subarrays_1.py,"def maxSumOfThreeSubarrays( nums: List[int], k: int) -> List[int]: - s = s1 = s2 = s3 = 0 - mx1 = mx12 = 0 - idx1, idx12 = 0, () - ans = [] - for i in range(k * 2, len(nums)): - s1 += nums[i - k * 2] - s2 += nums[i - k] - s3 += nums[i] - if i >= k * 3 - 1: - if s1 > mx1: - mx1 = s1 - idx1 = i - k * 3 + 1 - if mx1 + s2 > mx12: - mx12 = mx1 + s2 - idx12 = (idx1, i - k * 2 + 1) - if mx12 + s3 > s: - s = mx12 + s3 - ans = [*idx12, i - k + 1] - s1 -= nums[i - k * 3 + 1] - s2 -= nums[i - k * 2 + 1] - s3 -= nums[i - k + 1] - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_8 = var_4 = var_5 = var_6 = 0 - var_10 = var_9 = 0 - var_11 , var_12 = 0 , ( ) - var_13 = [ ] - for var_17 in range ( var_3 * 2 , len ( var_0 ) ) : - var_4 += var_0 [ var_17 - var_3 * 2 ] - var_5 += var_0 [ var_17 - var_3 ] - var_6 += var_0 [ var_17 ] - if var_17 >= var_3 * 3 - 1 : - if var_4 > var_10 : - var_10 = var_4 - var_11 = var_17 - var_3 * 3 + 1 - if var_10 + var_5 > var_9 : - var_9 = var_10 + var_5 - var_12 = ( var_11 , var_17 - var_3 * 2 + 1 ) - if var_9 + var_6 > var_8 : - var_8 = var_9 + var_6 - var_13 = [ * var_12 , var_17 - var_3 + 1 ] - var_4 -= var_0 [ var_17 - var_3 * 3 + 1 ] - var_5 -= var_0 [ var_17 - var_3 * 2 + 1 ] - var_6 -= var_0 [ var_17 - var_3 + 1 ] - return var_13 -",1302,4 -729,0054.Spiral Matrix_1.py,"def spiralOrder( matrix: List[List[int]]) -> List[int]: - m, n = len(matrix), len(matrix[0]) - ans = [] - top, bottom, left, right = 0, m - 1, 0, n - 1 - while left <= right and top <= bottom: - ans.extend([matrix[top][j] for j in range(left, right + 1)]) - ans.extend([matrix[i][right] for i in range(top + 1, bottom + 1)]) - if left < right and top < bottom: - ans.extend([matrix[bottom][j] for j in range(right - 1, left - 1, -1)]) - ans.extend([matrix[i][left] for i in range(bottom - 1, top, -1)]) - top, bottom, left, right = top + 1, bottom - 1, left + 1, right - 1 - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ int ] : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_7 = [ ] - var_8 , var_10 , var_11 , var_12 = 0 , var_4 - 1 , 0 , var_6 - 1 - while var_11 <= var_12 and var_8 <= var_10 : - var_7.extend ( [ var_0 [ var_8 ] [ var_14 ] for var_14 in range ( var_11 , var_12 + 1 ) ] ) - var_7.extend ( [ var_0 [ var_16 ] [ var_12 ] for var_16 in range ( var_8 + 1 , var_10 + 1 ) ] ) - if var_11 < var_12 and var_8 < var_10 : - var_7.extend ( [ var_0 [ var_10 ] [ var_14 ] for var_14 in range ( var_12 - 1 , var_11 - 1 , - 1 ) ] ) - var_7.extend ( [ var_0 [ var_16 ] [ var_11 ] for var_16 in range ( var_10 - 1 , var_8 , - 1 ) ] ) - var_8 , var_10 , var_11 , var_12 = var_8 + 1 , var_10 - 1 , var_11 + 1 , var_12 - 1 - return var_7 -",10,2 -730,0132.Palindrome Partitioning II_1.py,"def minCut( s: str) -> int: - n = len(s) - dp1 = [[False] * n for _ in range(n)] - for i in range(n - 1, -1, -1): - for j in range(i, n): - dp1[i][j] = s[i] == s[j] and (j - 1 < 3 or dp1[i + 1][j - 1]) - dp2 = [0] * n - for i in range(n): - if not dp1[0][i]: - dp2[i] = i - for j in range(1, i + 1): - if dp1[j][i]: - dp2[i] = min(dp2[i], dp2[j - 1] + 1) - return dp2[-1]","def sample_funcname ( var_0 : str ) -> int : - var_4 = len ( var_0 ) - var_8 = [ [ False ] * var_4 for var_6 in range ( var_4 ) ] - for var_10 in range ( var_4 - 1 , - 1 , - 1 ) : - for var_11 in range ( var_10 , var_4 ) : - var_8 [ var_10 ] [ var_11 ] = var_0 [ var_10 ] == var_0 [ var_11 ] and ( var_11 - 1 < 3 or var_8 [ var_10 + 1 ] [ var_11 - 1 ] ) - var_14 = [ 0 ] * var_4 - for var_10 in range ( var_4 ) : - if not var_8 [ 0 ] [ var_10 ] : - var_14 [ var_10 ] = var_10 - for var_11 in range ( 1 , var_10 + 1 ) : - if var_8 [ var_11 ] [ var_10 ] : - var_14 [ var_10 ] = min ( var_14 [ var_10 ] , var_14 [ var_11 - 1 ] + 1 ) - return var_14 [ - 1 ] -",310,3 -731,0832.Flipping an Image_1.py,"def flipAndInvertImage( A: List[List[int]]) -> List[List[int]]: - m, n = len(A), len(A[0]) - for i in range(m): - p, q = 0, n - 1 - while p < q: - t = A[i][p] ^ 1 - A[i][p] = A[i][q] ^ 1 - A[i][q] = t - p += 1 - q -= 1 - if p == q: - A[i][p] ^= 1 - return A","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ List [ int ] ] : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - for var_8 in range ( var_4 ) : - var_9 , var_11 = 0 , var_6 - 1 - while var_9 < var_11 : - var_12 = var_0 [ var_8 ] [ var_9 ] ^ 1 - var_0 [ var_8 ] [ var_9 ] = var_0 [ var_8 ] [ var_11 ] ^ 1 - var_0 [ var_8 ] [ var_11 ] = var_12 - var_9 += 1 - var_11 -= 1 - if var_9 == var_11 : - var_0 [ var_8 ] [ var_9 ] ^= 1 - return var_0 -",10,2 -732,2099.Find Subsequence of Length K With the Largest Sum_1.py,"def maxSubsequence( nums: List[int], k: int) -> List[int]: - idx = list(range(len(nums))) - idx.sort(key=lambda i: nums[i]) - return [nums[i] for i in sorted(idx[-k:])]","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_7 = list ( range ( len ( var_0 ) ) ) - var_7.sort ( var_9 = lambda var_10 : var_0 [ var_10 ] ) - return [ var_0 [ var_10 ] for var_10 in sorted ( var_7 [ - var_3 : ] ) ] -",,0 -733,0338.Counting Bits_1.py,"def countBits( n: int) -> List[int]: - ans = [0] * (n + 1) - for i in range(1, n + 1): - ans[i] = ans[i & (i - 1)] + 1 - return ans","def sample_funcname ( var_0 : int ) -> List [ int ] : - var_5 = [ 0 ] * ( var_0 + 1 ) - for var_7 in range ( 1 , var_0 + 1 ) : - var_5 [ var_7 ] = var_5 [ var_7 & ( var_7 - 1 ) ] + 1 - return var_5 -",10,2 -734,1773.Count Items Matching a Rule_1.py,"def countMatches( items: List[List[str]], ruleKey: str, ruleValue: str) -> int: - count = 0 - m = {'type': 0, 'color': 1, 'name': 2} - return sum([item[m[ruleKey]] == ruleValue for item in items])","def sample_funcname ( var_0 : List [ List [ str ] ] , var_3 : str , var_4 : str ) -> int : - var_7 = 0 - var_13 = { 'type' : 0 , 'color' : 1 , 'name' : 2 } - return sum ( [ var_15 [ var_13 [ var_3 ] ] == var_4 for var_15 in var_0 ] ) -",021typenamecolor,6 -735,2269.Find the K-Beauty of a Number_1.py,"def divisorSubstrings( num: int, k: int) -> int: - ans = 0 - s = str(num) - for i in range(len(s) - k + 1): - t = int(s[i : i + k]) - if t and num % t == 0: - ans += 1 - return ans","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_4 = 0 - var_6 = str ( var_0 ) - for var_10 in range ( len ( var_6 ) - var_2 + 1 ) : - var_11 = int ( var_6 [ var_10 : var_10 + var_2 ] ) - if var_11 and var_0 % var_11 == 0 : - var_4 += 1 - return var_4 -",10,2 -736,0769.Max Chunks To Make Sorted_1.py,"def maxChunksToSorted( arr: List[int]) -> int: - mx = ans = 0 - for i, v in enumerate(arr): - mx = max(mx, v) - if i == mx: - ans += 1 - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - for var_7 , var_8 in enumerate ( var_0 ) : - var_5 = max ( var_5 , var_8 ) - if var_7 == var_5 : - var_3 += 1 - return var_3 -",10,2 -737,1544.Make The String Great_1.py,"def makeGood( s: str) -> str: - stk = [] - for c in s: - if not stk or abs(ord(stk[-1]) - ord(c)) != 32: - stk.append(c) - else: - stk.pop() - return """".join(stk)","def sample_funcname ( var_0 : str ) -> str : - var_2 = [ ] - for var_3 in var_0 : - if not var_2 or abs ( ord ( var_2 [ - 1 ] ) - ord ( var_3 ) ) != 32 : - var_2.append ( var_3 ) - else : - var_2.pop ( ) - return """".join ( var_2 ) -",132,3 -738,0877.Stone Game_1.py,"def stoneGame( piles: List[int]) -> bool: - n = len(piles) - dp = [[0] * n for _ in range(n)] - for i, v in enumerate(piles): - dp[i][i] = v - for i in range(n - 2, -1, -1): - for j in range(i + 1, n): - dp[i][j] = max(piles[i] - dp[i + 1][j], piles[j] - dp[i][j - 1]) - return dp[0][-1] > 0","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_5 = len ( var_0 ) - var_9 = [ [ 0 ] * var_5 for var_7 in range ( var_5 ) ] - for var_11 , var_12 in enumerate ( var_0 ) : - var_9 [ var_11 ] [ var_11 ] = var_12 - for var_11 in range ( var_5 - 2 , - 1 , - 1 ) : - for var_15 in range ( var_11 + 1 , var_5 ) : - var_9 [ var_11 ] [ var_15 ] = max ( var_0 [ var_11 ] - var_9 [ var_11 + 1 ] [ var_15 ] , var_0 [ var_15 ] - var_9 [ var_11 ] [ var_15 - 1 ] ) - return var_9 [ 0 ] [ - 1 ] > 0 -",102,3 -739,0479.Largest Palindrome Product_1.py,"def largestPalindrome( n: int) -> int: - mx = 10**n - 1 - for a in range(mx, mx // 10, -1): - b = x = a - while b: - x = x * 10 + b % 10 - b //= 10 - t = mx - while t * t >= x: - if x % t == 0: - return x % 1337 - t -= 1 - return 9","def sample_funcname ( var_0 : int ) -> int : - var_4 = 10 ** var_0 - 1 - for var_6 in range ( var_4 , var_4 // 10 , - 1 ) : - var_8 = var_7 = var_6 - while var_8 : - var_7 = var_7 * 10 + var_8 % 10 - var_8 //= 10 - var_9 = var_4 - while var_9 * var_9 >= var_7 : - if var_7 % var_9 == 0 : - return var_7 % 1337 - var_9 -= 1 - return 9 -",100191337,5 -740,1734.Decode XORed Permutation_1.py,"def decode( encoded: List[int]) -> List[int]: - n = len(encoded) + 1 - a = b = 0 - for i in range(0, n - 1, 2): - a ^= encoded[i] - for i in range(n + 1): - b ^= i - ans = [a ^ b] - for e in encoded[::-1]: - ans.append(ans[-1] ^ e) - return ans[::-1]","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_5 = len ( var_0 ) + 1 - var_8 = var_6 = 0 - for var_11 in range ( 0 , var_5 - 1 , 2 ) : - var_8 ^= var_0 [ var_11 ] - for var_11 in range ( var_5 + 1 ) : - var_6 ^= var_11 - var_12 = [ var_8 ^ var_6 ] - for var_13 in var_0 [ : : - 1 ] : - var_12.append ( var_12 [ - 1 ] ^ var_13 ) - return var_12 [ : : - 1 ] -",102,3 -741,1239.Maximum Length of a Concatenated String with Unique Characters_1.py,"def ones_count(x): - c = 0 - while x: - x &= x - 1 - c += 1 - return c","def sample_funcname ( var_0 ) : - var_2 = 0 - while var_0 : - var_0 &= var_0 - 1 - var_2 += 1 - return var_2 -",10,2 -742,0977.Squares of a Sorted Array_1.py,"def sortedSquares( nums: List[int]) -> List[int]: - n = len(nums) - res = [0] * n - i, j, k = 0, n - 1, n - 1 - while i <= j: - if nums[i] * nums[i] > nums[j] * nums[j]: - res[k] = nums[i] * nums[i] - i += 1 - else: - res[k] = nums[j] * nums[j] - j -= 1 - k -= 1 - return res","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 = len ( var_0 ) - var_6 = [ 0 ] * var_4 - var_7 , var_9 , var_10 = 0 , var_4 - 1 , var_4 - 1 - while var_7 <= var_9 : - if var_0 [ var_7 ] * var_0 [ var_7 ] > var_0 [ var_9 ] * var_0 [ var_9 ] : - var_6 [ var_10 ] = var_0 [ var_7 ] * var_0 [ var_7 ] - var_7 += 1 - else : - var_6 [ var_10 ] = var_0 [ var_9 ] * var_0 [ var_9 ] - var_9 -= 1 - var_10 -= 1 - return var_6 -",10,2 -743,0070.Climbing Stairs_1.py,"def climbStairs( n: int) -> int: - a, b = 0, 1 - for _ in range(n): - a, b = b, a + b - return b","def sample_funcname ( var_0 : int ) -> int : - var_3 , var_5 = 0 , 1 - for var_7 in range ( var_0 ) : - var_3 , var_5 = var_5 , var_3 + var_5 - return var_5 -",10,2 -744,1026.Maximum Difference Between Node and Ancestor_1.py,"def dfs(root, mx, mi): - if root is None: - return - nonlocal ans - ans = max(ans, abs(root.val - mx), abs(root.val - mi)) - mx = max(mx, root.val) - mi = min(mi, root.val) - dfs(root.left, mx, mi) - dfs(root.right, mx, mi)","def sample_funcname ( var_1 , var_2 , var_3 ) : - if var_1 is None : - return - nonlocal var_5 - var_5 = max ( var_5 , abs ( var_1.val - var_2 ) , abs ( var_1.val - var_3 ) ) - var_2 = max ( var_2 , var_1.val ) - var_3 = min ( var_3 , var_1.val ) - var_0 ( var_1.left , var_2 , var_3 ) - var_0 ( var_1.right , var_2 , var_3 ) -",None,1 -745,0038.Count and Say_1.py,"def countAndSay( n: int) -> str: - s = '1' - for _ in range(n - 1): - i = 0 - t = [] - while i < len(s): - j = i - while j < len(s) and s[j] == s[i]: - j += 1 - t.append(str(j - i)) - t.append(str(s[i])) - i = j - s = ''.join(t) - return s","def sample_funcname ( var_0 : int ) -> str : - var_4 = '1' - for var_7 in range ( var_0 - 1 ) : - var_9 = 0 - var_10 = [ ] - while var_9 < len ( var_4 ) : - var_12 = var_9 - while var_12 < len ( var_4 ) and var_4 [ var_12 ] == var_4 [ var_9 ] : - var_12 += 1 - var_10.append ( str ( var_12 - var_9 ) ) - var_10.append ( str ( var_4 [ var_9 ] ) ) - var_9 = var_12 - var_4 = ''.join ( var_10 ) - return var_4 -",101,4 -746,0091.Decode Ways_1.py,"def numDecodings( s: str) -> int: - n = len(s) - a, b, c = 0, 1, 0 - for i in range(1, n + 1): - c = 0 - if s[i - 1] != '0': - c += b - if i > 1 and s[i - 2] != '0' and (int(s[i - 2]) * 10 + int(s[i - 1]) <= 26): - c += a - a, b = b, c - return c","def sample_funcname ( var_0 : str ) -> int : - var_4 = len ( var_0 ) - var_6 , var_8 , var_9 = 0 , 1 , 0 - for var_11 in range ( 1 , var_4 + 1 ) : - var_9 = 0 - if var_0 [ var_11 - 1 ] != '0' : - var_9 += var_8 - if var_11 > 1 and var_0 [ var_11 - 2 ] != '0' and ( int ( var_0 [ var_11 - 2 ] ) * 10 + int ( var_0 [ var_11 - 1 ] ) <= 26 ) : - var_9 += var_6 - var_6 , var_8 = var_8 , var_9 - return var_9 -",10002126,6 -747,2090.K Radius Subarray Averages_1.py,"def getAverages( nums: List[int], k: int) -> List[int]: - n = len(nums) - presum = [0] * (n + 1) - for i in range(n): - presum[i + 1] = presum[i] + nums[i] - return [ - -1 - if i - k < 0 or i + k >= n - else (presum[i + k + 1] - presum[i - k]) // (k * 2 + 1) - for i in range(n) - ]","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_5 = len ( var_0 ) - var_8 = [ 0 ] * ( var_5 + 1 ) - for var_10 in range ( var_5 ) : - var_8 [ var_10 + 1 ] = var_8 [ var_10 ] + var_0 [ var_10 ] - return [ - 1 if var_10 - var_3 < 0 or var_10 + var_3 >= var_5 else ( var_8 [ var_10 + var_3 + 1 ] - var_8 [ var_10 - var_3 ] ) // ( var_3 * 2 + 1 ) for var_10 in range ( var_5 ) ] -",102,3 -748,2317.Maximum XOR After Operations_1.py,"def maximumXOR( nums: List[int]) -> int: - ans = 0 - for v in nums: - ans |= v - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 0 - for var_5 in var_0 : - var_4 |= var_5 - return var_4 -",0,1 -749,2380.Time Needed to Rearrange a Binary String_1.py,"def secondsToRemoveOccurrences( s: str) -> int: - ans = cnt = 0 - for c in s: - if c == '0': - cnt += 1 - elif cnt: - ans = max(ans + 1, cnt) - return ans","def sample_funcname ( var_0 : str ) -> int : - var_5 = var_3 = 0 - for var_6 in var_0 : - if var_6 == '0' : - var_3 += 1 - elif var_3 : - var_5 = max ( var_5 + 1 , var_3 ) - return var_5 -",100,3 -750,0658.Find K Closest Elements_1.py,"def findClosestElements( arr: List[int], k: int, x: int) -> List[int]: - left, right = 0, len(arr) - k - while left < right: - mid = (left + right) >> 1 - if x - arr[mid] <= arr[mid + k] - x: - right = mid - else: - left = mid + 1 - return arr[left : left + k]","def sample_funcname ( var_0 : List [ int ] , var_3 : int , var_4 : int ) -> List [ int ] : - var_6 , var_8 = 0 , len ( var_0 ) - var_3 - while var_6 < var_8 : - var_10 = ( var_6 + var_8 ) >> 1 - if var_4 - var_0 [ var_10 ] <= var_0 [ var_10 + var_3 ] - var_4 : - var_8 = var_10 - else : - var_6 = var_10 + 1 - return var_0 [ var_6 : var_6 + var_3 ] -",10,2 -751,0378.Kth Smallest Element in a Sorted Matrix_1.py,"def check(matrix, mid, k, n): - count = 0 - i, j = n - 1, 0 - while i >= 0 and j < n: - if matrix[i][j] <= mid: - count += i + 1 - j += 1 - else: - i -= 1 - return count >= k","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - var_5 = 0 - var_7 , var_8 = var_3 - 1 , 0 - while var_7 >= 0 and var_8 < var_3 : - if var_0 [ var_7 ] [ var_8 ] <= var_1 : - var_5 += var_7 + 1 - var_8 += 1 - else : - var_7 -= 1 - return var_5 >= var_2 -",10,2 -752,0500.Keyboard Row_1.py,"def findWords( words: List[str]) -> List[str]: - s1 = set('qwertyuiop') - s2 = set('asdfghjkl') - s3 = set('zxcvbnm') - res = [] - for word in words: - t = set(word.lower()) - if t <= s1 or t <= s2 or t <= s3: - res.append(word) - return res","def sample_funcname ( var_0 : List [ str ] ) -> List [ str ] : - var_5 = set ( 'qwertyuiop' ) - var_7 = set ( 'asdfghjkl' ) - var_9 = set ( 'zxcvbnm' ) - var_10 = [ ] - for var_11 in var_0 : - var_13 = set ( var_11.lower ( ) ) - if var_13 <= var_5 or var_13 <= var_7 or var_13 <= var_9 : - var_10.append ( var_11 ) - return var_10 -",qwertyuiopzxcvbnmasdfghjkl,3 -753,0149.Max Points on a Line_1.py,"def gcd(a, b) -> int: - return a if b == 0 else gcd(b, a % b)","def sample_funcname ( var_1 , var_2 ) -> int : - return var_1 if var_2 == 0 else var_0 ( var_2 , var_1 % var_2 ) -",0,1 -754,1763.Longest Nice Substring_1.py,"def longestNiceSubstring( s: str) -> str: - n = len(s) - ans = '' - for i in range(n): - lower = upper = 0 - for j in range(i, n): - if s[j].islower(): - lower |= 1 << (ord(s[j]) - ord('a')) - else: - upper |= 1 << (ord(s[j]) - ord('A')) - if lower == upper and j - i + 1 > len(ans): - ans = s[i : j + 1] - return ans","def sample_funcname ( var_0 : str ) -> str : - var_3 = len ( var_0 ) - var_5 = '' - for var_7 in range ( var_3 ) : - var_10 = var_8 = 0 - for var_11 in range ( var_7 , var_3 ) : - if var_0 [ var_11 ].islower ( ) : - var_10 |= 1 << ( ord ( var_0 [ var_11 ] ) - ord ( 'a' ) ) - else : - var_8 |= 1 << ( ord ( var_0 [ var_11 ] ) - ord ( 'A' ) ) - if var_10 == var_8 and var_11 - var_7 + 1 > len ( var_5 ) : - var_5 = var_0 [ var_7 : var_11 + 1 ] - return var_5 -",0aA1,5 -755,1732.Find the Highest Altitude_1.py,"def largestAltitude( gain: List[int]) -> int: - res = t = 0 - for h in gain: - t += h - res = max(res, t) - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - for var_6 in var_0 : - var_3 += var_6 - var_5 = max ( var_5 , var_3 ) - return var_5 -",0,1 -756,2217.Find Palindrome With Fixed Length_1.py,"def kthPalindrome( queries: List[int], intLength: int) -> List[int]: - l = (intLength + 1) >> 1 - start, end = 10 ** (l - 1), 10**l - 1 - ans = [] - for q in queries: - v = start + q - 1 - if v > end: - ans.append(-1) - continue - s = str(v) - s += s[::-1][intLength % 2 :] - ans.append(int(s)) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_5 = ( var_3 + 1 ) >> 1 - var_7 , var_8 = 10 ** ( var_5 - 1 ) , 10 ** var_5 - 1 - var_9 = [ ] - for var_10 in var_0 : - var_11 = var_7 + var_10 - 1 - if var_11 > var_8 : - var_9.append ( - 1 ) - continue - var_14 = str ( var_11 ) - var_14 += var_14 [ : : - 1 ] [ var_3 % 2 : ] - var_9.append ( int ( var_14 ) ) - return var_9 -",1012,3 -757,0553.Optimal Division_1.py,"def optimalDivision( nums: List[int]) -> str: - n = len(nums) - if n == 1: - return str(nums[0]) - if n == 2: - return f'{nums[0]}/{nums[1]}' - return f'{nums[0]}/({""/"".join(map(str, nums[1:]))})'","def sample_funcname ( var_0 : List [ int ] ) -> str : - var_5 = len ( var_0 ) - if var_5 == 1 : - return str ( var_0 [ 0 ] ) - if var_5 == 2 : - return f'{var_0[0]}/{var_0[1]}' - return f'{var_0[0]}/({""/"".join(map(str, var_0[1:]))})' -","0f{var_0[0]}/{var_0[1]}21f{var_0[0]}/({/.join(map(str, var_0[1:]))})",5 -758,1299.Replace Elements with Greatest Element on Right Side_1.py,"def replaceElements( arr: List[int]) -> List[int]: - m = -1 - for i in range(len(arr) - 1, -1, -1): - t = arr[i] - arr[i] = m - m = max(m, t) - return arr","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 = - 1 - for var_7 in range ( len ( var_0 ) - 1 , - 1 , - 1 ) : - var_8 = var_0 [ var_7 ] - var_0 [ var_7 ] = var_4 - var_4 = max ( var_4 , var_8 ) - return var_0 -",1,1 -759,0190.Reverse Bits_1.py,"def reverseBits( n: int) -> int: - res = 0 - for i in range(32): - res |= (n & 1) << (31 - i) - n >>= 1 - return res","def sample_funcname ( var_0 : int ) -> int : - var_3 = 0 - for var_6 in range ( 32 ) : - var_3 |= ( var_0 & 1 ) << ( 31 - var_6 ) - var_0 >>= 1 - return var_3 -",103132,4 -760,2064.Minimized Maximum of Products Distributed to Any Store_1.py,"def minimizedMaximum( n: int, quantities: List[int]) -> int: - left, right = 1, int(1e5) - while left < right: - mid = (left + right) >> 1 - s = sum([(q + mid - 1) // mid for q in quantities]) - if s <= n: - right = mid - else: - left = mid + 1 - return left","def sample_funcname ( var_0 : int , var_2 : List [ int ] ) -> int : - var_5 , var_7 = 1 , int ( 1e5 ) - while var_5 < var_7 : - var_8 = ( var_5 + var_7 ) >> 1 - var_11 = sum ( [ ( var_10 + var_8 - 1 ) // var_8 for var_10 in var_2 ] ) - if var_11 <= var_0 : - var_7 = var_8 - else : - var_5 = var_8 + 1 - return var_5 -",11e5,2 -761,0477.Total Hamming Distance_1.py,"def totalHammingDistance( nums: List[int]) -> int: - ans = 0 - for i in range(31): - a = b = 0 - for v in nums: - t = (v >> i) & 1 - if t: - a += 1 - else: - b += 1 - ans += a * b - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 0 - for var_7 in range ( 31 ) : - var_9 = var_8 = 0 - for var_10 in var_0 : - var_12 = ( var_10 >> var_7 ) & 1 - if var_12 : - var_9 += 1 - else : - var_8 += 1 - var_4 += var_9 * var_8 - return var_4 -",1031,3 -762,0531.Lonely Pixel I_1.py,"def findLonelyPixel( picture: List[List[str]]) -> int: - m, n = len(picture), len(picture[0]) - rows, cols = [0] * m, [0] * n - for i in range(m): - for j in range(n): - if picture[i][j] == 'B': - rows[i] += 1 - cols[j] += 1 - res = 0 - for i in range(m): - if rows[i] == 1: - for j in range(n): - if picture[i][j] == 'B' and cols[j] == 1: - res += 1 - break - return res","def sample_funcname ( var_0 : List [ List [ str ] ] ) -> int : - var_5 , var_7 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_8 , var_9 = [ 0 ] * var_5 , [ 0 ] * var_7 - for var_11 in range ( var_5 ) : - for var_12 in range ( var_7 ) : - if var_0 [ var_11 ] [ var_12 ] == 'B' : - var_8 [ var_11 ] += 1 - var_9 [ var_12 ] += 1 - var_15 = 0 - for var_11 in range ( var_5 ) : - if var_8 [ var_11 ] == 1 : - for var_12 in range ( var_7 ) : - if var_0 [ var_11 ] [ var_12 ] == 'B' and var_9 [ var_12 ] == 1 : - var_15 += 1 - break - return var_15 -",10B,3 -763,0001.Two Sum_1.py,"def twoSum( nums: List[int], target: int) -> List[int]: - m = {} - for i, v in enumerate(nums): - x = target - v - if x in m: - return [m[x], i] - m[v] = i","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_4 = { } - for var_6 , var_7 in enumerate ( var_0 ) : - var_8 = var_3 - var_7 - if var_8 in var_4 : - return [ var_4 [ var_8 ] , var_6 ] - var_4 [ var_7 ] = var_6 -",,0 -764,1784.Check if Binary String Has at Most One Segment of Ones_1.py,"def checkOnesSegment( s: str) -> bool: - return '01' not in s","def sample_funcname ( var_0 : str ) -> bool : - return '01' not in var_0 -",01,1 -765,2306.Naming a Company_1.py,"def distinctNames( ideas: List[str]) -> int: - s = set(ideas) - f = [[0] * 26 for _ in range(26)] - for v in ideas: - i = ord(v[0]) - ord('a') - t = list(v) - for j in range(26): - t[0] = chr(ord('a') + j) - if ''.join(t) not in s: - f[i][j] += 1 - ans = 0 - for v in ideas: - i = ord(v[0]) - ord('a') - t = list(v) - for j in range(26): - t[0] = chr(ord('a') + j) - if ''.join(t) not in s: - ans += f[j][i] - return ans","def sample_funcname ( var_0 : List [ str ] ) -> int : - var_5 = set ( var_0 ) - var_10 = [ [ 0 ] * 26 for var_8 in range ( 26 ) ] - for var_11 in var_0 : - var_14 = ord ( var_11 [ 0 ] ) - ord ( 'a' ) - var_16 = list ( var_11 ) - for var_17 in range ( 26 ) : - var_16 [ 0 ] = chr ( ord ( 'a' ) + var_17 ) - if ''.join ( var_16 ) not in var_5 : - var_10 [ var_14 ] [ var_17 ] += 1 - var_22 = 0 - for var_11 in var_0 : - var_14 = ord ( var_11 [ 0 ] ) - ord ( 'a' ) - var_16 = list ( var_11 ) - for var_17 in range ( 26 ) : - var_16 [ 0 ] = chr ( ord ( 'a' ) + var_17 ) - if ''.join ( var_16 ) not in var_5 : - var_22 += var_10 [ var_17 ] [ var_14 ] - return var_22 -",0a126,5 -766,1572.Matrix Diagonal Sum_1.py,"def diagonalSum( mat: List[List[int]]) -> int: - n = len(mat) - res = 0 - for i in range(n): - res += mat[i][i] + (0 if n - i - 1 == i else mat[i][n - i - 1]) - return res","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 = len ( var_0 ) - var_6 = 0 - for var_8 in range ( var_4 ) : - var_6 += var_0 [ var_8 ] [ var_8 ] + ( 0 if var_4 - var_8 - 1 == var_8 else var_0 [ var_8 ] [ var_4 - var_8 - 1 ] ) - return var_6 -",10,2 -767,0999.Available Captures for Rook_1.py,"def numRookCaptures( board: List[List[str]]) -> int: - x, y, n = 0, 0, 8 - for i in range(n): - for j in range(n): - if board[i][j] == 'R': - x, y = i, j - break - ans = 0 - for a, b in [[0, -1], [0, 1], [-1, 0], [1, 0]]: - i, j = x, y - while 0 <= i + a < n and 0 <= j + b < n and board[i + a][j + b] != 'B': - i, j = i + a, j + b - if board[i][j] == 'p': - ans += 1 - break - return ans","def sample_funcname ( var_0 : List [ List [ str ] ] ) -> int : - var_5 , var_6 , var_8 = 0 , 0 , 8 - for var_10 in range ( var_8 ) : - for var_11 in range ( var_8 ) : - if var_0 [ var_10 ] [ var_11 ] == 'R' : - var_5 , var_6 = var_10 , var_11 - break - var_13 = 0 - for var_15 , var_16 in [ [ 0 , - 1 ] , [ 0 , 1 ] , [ - 1 , 0 ] , [ 1 , 0 ] ] : - var_10 , var_11 = var_5 , var_6 - while 0 <= var_10 + var_15 < var_8 and 0 <= var_11 + var_16 < var_8 and var_0 [ var_10 + var_15 ] [ var_11 + var_16 ] != 'B' : - var_10 , var_11 = var_10 + var_15 , var_11 + var_16 - if var_0 [ var_10 ] [ var_11 ] == 'p' : - var_13 += 1 - break - return var_13 -",0B8R1p,6 -768,0213.House Robber II_1.py,"def robRange(nums, l, r): - a, b = 0, nums[l] - for num in nums[l + 1 : r + 1]: - a, b = b, max(num + a, b) - return b","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_4 , var_5 = 0 , var_0 [ var_1 ] - for var_7 in var_0 [ var_1 + 1 : var_2 + 1 ] : - var_4 , var_5 = var_5 , max ( var_7 + var_4 , var_5 ) - return var_5 -",10,2 -769,1365.How Many Numbers Are Smaller Than the Current Number_1.py,"def smallerNumbersThanCurrent( nums: List[int]) -> List[int]: - cnt = [0] * 101 - for num in nums: - cnt[num] += 1 - for i in range(1, 101): - cnt[i] += cnt[i - 1] - res = [] - for num in nums: - res.append(0 if num == 0 else cnt[num - 1]) - return res","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_5 = [ 0 ] * 101 - for var_6 in var_0 : - var_5 [ var_6 ] += 1 - for var_9 in range ( 1 , 101 ) : - var_5 [ var_9 ] += var_5 [ var_9 - 1 ] - var_10 = [ ] - for var_6 in var_0 : - var_10.append ( 0 if var_6 == 0 else var_5 [ var_6 - 1 ] ) - return var_10 -",10101,3 -770,0746.Min Cost Climbing Stairs_1.py,"def minCostClimbingStairs( cost: List[int]) -> int: - a = b = 0 - for i in range(1, len(cost)): - a, b = b, min(a + cost[i - 1], b + cost[i]) - return b","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - for var_9 in range ( 1 , len ( var_0 ) ) : - var_5 , var_3 = var_3 , min ( var_5 + var_0 [ var_9 - 1 ] , var_3 + var_0 [ var_9 ] ) - return var_3 -",10,2 -771,1342.Number of Steps to Reduce a Number to Zero_1.py,"def numberOfSteps( num: int) -> int: - ans = 0 - while num: - if num & 1: - num -= 1 - else: - num >>= 1 - ans += 1 - return ans","def sample_funcname ( var_0 : int ) -> int : - var_3 = 0 - while var_0 : - if var_0 & 1 : - var_0 -= 1 - else : - var_0 >>= 1 - var_3 += 1 - return var_3 -",10,2 -772,1953.Maximum Number of Weeks for Which You Can Work_1.py,"def numberOfWeeks( milestones: List[int]) -> int: - mx, s = max(milestones), sum(milestones) - rest = s - mx - return rest * 2 + 1 if mx > rest + 1 else s","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_6 = max ( var_0 ) , sum ( var_0 ) - var_7 = var_6 - var_4 - return var_7 * 2 + 1 if var_4 > var_7 + 1 else var_6 -",12,2 -773,1283.Find the Smallest Divisor Given a Threshold_1.py,"def smallestDivisor( nums: List[int], threshold: int) -> int: - left, right = 1, 10**6 - while left < right: - mid = (left + right) >> 1 - s = sum((v + mid - 1) // mid for v in nums) - if s <= threshold: - right = mid - else: - left = mid + 1 - return left","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_8 = 1 , 10 ** 6 - while var_5 < var_8 : - var_9 = ( var_5 + var_8 ) >> 1 - var_12 = sum ( ( var_11 + var_9 - 1 ) // var_9 for var_11 in var_0 ) - if var_12 <= var_3 : - var_8 = var_9 - else : - var_5 = var_9 + 1 - return var_5 -",1016,3 -774,1551.Minimum Operations to Make Array Equal_1.py,"def minOperations( n: int) -> int: - ans = 0 - for i in range(n >> 1): - ans += n - (2 * i + 1) - return ans","def sample_funcname ( var_0 : int ) -> int : - var_3 = 0 - for var_6 in range ( var_0 >> 1 ) : - var_3 += var_0 - ( 2 * var_6 + 1 ) - return var_3 -",102,3 -775,1029.Two City Scheduling_1.py,"def twoCitySchedCost( costs: List[List[int]]) -> int: - costs.sort(key=lambda x: x[0] - x[1]) - n = len(costs) >> 1 - return sum(costs[i][0] + costs[i + n][1] for i in range(n))","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_0.sort ( var_4 = lambda var_5 : var_5 [ 0 ] - var_5 [ 1 ] ) - var_9 = len ( var_0 ) >> 1 - return sum ( var_0 [ var_11 ] [ 0 ] + var_0 [ var_11 + var_9 ] [ 1 ] for var_11 in range ( var_9 ) ) -",10,2 -776,0167.Two Sum II - Input Array Is Sorted_1.py,"def twoSum( numbers: List[int], target: int) -> List[int]: - i, j = 1, len(numbers) - while i < j: - x = numbers[i - 1] + numbers[j - 1] - if x == target: - return [i, j] - if x < target: - i += 1 - else: - j -= 1 - return [-1, -1]","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_5 , var_7 = 1 , len ( var_0 ) - while var_5 < var_7 : - var_8 = var_0 [ var_5 - 1 ] + var_0 [ var_7 - 1 ] - if var_8 == var_3 : - return [ var_5 , var_7 ] - if var_8 < var_3 : - var_5 += 1 - else : - var_7 -= 1 - return [ - 1 , - 1 ] -",1,1 -777,0738.Monotone Increasing Digits_1.py,"def monotoneIncreasingDigits( n: int) -> int: - s = list(str(n)) - i = 1 - while i < len(s) and s[i - 1] <= s[i]: - i += 1 - if i < len(s): - while i and s[i - 1] > s[i]: - s[i - 1] = str(int(s[i - 1]) - 1) - i -= 1 - i += 1 - while i < len(s): - s[i] = '9' - i += 1 - return int(''.join(s))","def sample_funcname ( var_0 : int ) -> int : - var_4 = list ( str ( var_0 ) ) - var_6 = 1 - while var_6 < len ( var_4 ) and var_4 [ var_6 - 1 ] <= var_4 [ var_6 ] : - var_6 += 1 - if var_6 < len ( var_4 ) : - while var_6 and var_4 [ var_6 - 1 ] > var_4 [ var_6 ] : - var_4 [ var_6 - 1 ] = str ( int ( var_4 [ var_6 - 1 ] ) - 1 ) - var_6 -= 1 - var_6 += 1 - while var_6 < len ( var_4 ) : - var_4 [ var_6 ] = '9' - var_6 += 1 - return int ( ''.join ( var_4 ) ) -",19,3 -778,0567.Permutation in String_1.py,"def checkInclusion( s1, s2): - if len(s1) > len(s2): - return False - flag1 = [0] * 26 - flag2 = [0] * 26 - for i, x in enumerate(s1): - flag1[ord(x) - ord('a')] += 1 - - for i, x in enumerate(s2): - flag2[ord(x) - ord('a')] += 1 - if i >= len(s1): - flag2[ord(s2[i - len(s1)]) - ord('a')] -= 1 - if flag1 == flag2: - return True - return False","def sample_funcname ( var_0 , var_1 ) : - if len ( var_0 ) > len ( var_1 ) : - return False - var_6 = [ 0 ] * 26 - var_7 = [ 0 ] * 26 - for var_9 , var_10 in enumerate ( var_0 ) : - var_6 [ ord ( var_10 ) - ord ( 'a' ) ] += 1 - for var_9 , var_10 in enumerate ( var_1 ) : - var_7 [ ord ( var_10 ) - ord ( 'a' ) ] += 1 - if var_9 >= len ( var_0 ) : - var_7 [ ord ( var_1 [ var_9 - len ( var_0 ) ] ) - ord ( 'a' ) ] -= 1 - if var_6 == var_7 : - return True - return False -",a0126,4 -779,1304.Find N Unique Integers Sum up to Zero_1.py,"def sumZero( n: int) -> List[int]: - presum = 0 - res = [] - for i in range(1, n): - res.append(i) - presum += i - res.append(-presum) - return res","def sample_funcname ( var_0 : int ) -> List [ int ] : - var_4 = 0 - var_5 = [ ] - for var_8 in range ( 1 , var_0 ) : - var_5.append ( var_8 ) - var_4 += var_8 - var_5.append ( - var_4 ) - return var_5 -",10,2 -780,0763.Partition Labels_1.py,"def partitionLabels( s: str) -> List[int]: - last = [0] * 26 - for i, c in enumerate(s): - last[ord(c) - ord('a')] = i - ans = [] - left = right = 0 - for i, c in enumerate(s): - right = max(right, last[ord(c) - ord('a')]) - if i == right: - ans.append(right - left + 1) - left = right + 1 - return ans","def sample_funcname ( var_0 : str ) -> List [ int ] : - var_6 = [ 0 ] * 26 - for var_8 , var_9 in enumerate ( var_0 ) : - var_6 [ ord ( var_9 ) - ord ( 'a' ) ] = var_8 - var_12 = [ ] - var_14 = var_13 = 0 - for var_8 , var_9 in enumerate ( var_0 ) : - var_13 = max ( var_13 , var_6 [ ord ( var_9 ) - ord ( 'a' ) ] ) - if var_8 == var_13 : - var_12.append ( var_13 - var_14 + 1 ) - var_14 = var_13 + 1 - return var_12 -",a0126,4 -781,0766.Toeplitz Matrix_1.py,"def isToeplitzMatrix( matrix: List[List[int]]) -> bool: - m, n = len(matrix), len(matrix[0]) - for i in range(1, m): - for j in range(1, n): - if matrix[i][j] != matrix[i - 1][j - 1]: - return False - return True","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> bool : - var_5 , var_7 = len ( var_0 ) , len ( var_0 [ 0 ] ) - for var_10 in range ( 1 , var_5 ) : - for var_11 in range ( 1 , var_7 ) : - if var_0 [ var_10 ] [ var_11 ] != var_0 [ var_10 - 1 ] [ var_11 - 1 ] : - return False - return True -",10,2 -782,0540.Single Element in a Sorted Array_1.py,"def singleNonDuplicate( nums: List[int]) -> int: - left, right = 0, len(nums) - 1 - while left < right: - mid = (left + right) >> 1 - if nums[mid] != nums[mid ^ 1]: - right = mid - else: - left = mid + 1 - return nums[left]","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_7 = 0 , len ( var_0 ) - 1 - while var_4 < var_7 : - var_8 = ( var_4 + var_7 ) >> 1 - if var_0 [ var_8 ] != var_0 [ var_8 ^ 1 ] : - var_7 = var_8 - else : - var_4 = var_8 + 1 - return var_0 [ var_4 ] -",10,2 -783,0150.Evaluate Reverse Polish Notation_1.py,"def evalRPN( tokens: List[str]) -> int: - nums = [] - for t in tokens: - if len(t) > 1 or t.isdigit(): - nums.append(int(t)) - else: - if t == ""+"": - nums[-2] += nums[-1] - elif t == ""-"": - nums[-2] -= nums[-1] - elif t == ""*"": - nums[-2] *= nums[-1] - else: - nums[-2] = int(nums[-2] / nums[-1]) - nums.pop() - return nums[0]","def sample_funcname ( var_0 : List [ str ] ) -> int : - var_4 = [ ] - for var_5 in var_0 : - if len ( var_5 ) > 1 or var_5.isdigit ( ) : - var_4.append ( int ( var_5 ) ) - else : - if var_5 == ""+"" : - var_4 [ - 2 ] += var_4 [ - 1 ] - elif var_5 == ""-"" : - var_4 [ - 2 ] -= var_4 [ - 1 ] - elif var_5 == ""*"" : - var_4 [ - 2 ] *= var_4 [ - 1 ] - else : - var_4 [ - 2 ] = int ( var_4 [ - 2 ] / var_4 [ - 1 ] ) - var_4.pop ( ) - return var_4 [ 0 ] -",+0*21-,6 -784,1618.Maximum Font to Fit a Sentence in a Screen_1.py,"def check(text, fontSize, w, h, fontInfo) -> bool: - if fontInfo.getHeight(fontSize) > h: - return False - width = 0 - for ch in text: - width += fontInfo.getWidth(fontSize, ch) - if width > w: - return False - return True","def sample_funcname ( var_0 , var_1 , var_2 , var_3 , var_4 ) -> bool : - if var_4.getHeight ( var_1 ) > var_3 : - return False - var_9 = 0 - for var_10 in var_0 : - var_9 += var_4.getWidth ( var_1 , var_10 ) - if var_9 > var_2 : - return False - return True -",0,1 -785,2145.Count the Hidden Sequences_1.py,"def numberOfArrays( differences: List[int], lower: int, upper: int) -> int: - num = mi = mx = 0 - for d in differences: - num += d - mi = min(mi, num) - mx = max(mx, num) - return max(0, upper - lower - (mx - mi) + 1)","def sample_funcname ( var_0 : List [ int ] , var_3 : int , var_4 : int ) -> int : - var_8 = var_5 = var_6 = 0 - for var_9 in var_0 : - var_8 += var_9 - var_5 = min ( var_5 , var_8 ) - var_6 = max ( var_6 , var_8 ) - return max ( 0 , var_4 - var_3 - ( var_6 - var_5 ) + 1 ) -",10,2 -786,1913.Maximum Product Difference Between Two Pairs_1.py,"def maxProductDifference( nums: List[int]) -> int: - nums.sort() - return nums[-1] * nums[-2] - nums[0] * nums[1]","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( ) - return var_0 [ - 1 ] * var_0 [ - 2 ] - var_0 [ 0 ] * var_0 [ 1 ] -",102,3 -787,2255.Count Prefixes of a Given String_1.py,"def countPrefixes( words: List[str], s: str) -> int: - return sum(word == s[: len(word)] for word in words)","def sample_funcname ( var_0 : List [ str ] , var_3 : str ) -> int : - return sum ( var_6 == var_3 [ : len ( var_6 ) ] for var_6 in var_0 ) -",,0 -788,2047.Number of Valid Words in a Sentence_1.py,"def check(token): - hyphen = False - for i, c in enumerate(token): - if c.isdigit() or (c in '!.,' and i < len(token) - 1): - return False - if c == '-': - if ( - hyphen - or i == 0 - or i == len(token) - 1 - or not token[i - 1].islower() - or not token[i + 1].islower() - ): - return False - hyphen = True - return True","def sample_funcname ( var_0 ) : - var_2 = False - for var_4 , var_5 in enumerate ( var_0 ) : - if var_5.isdigit ( ) or ( var_5 in '!.,' and var_4 < len ( var_0 ) - 1 ) : - return False - if var_5 == '-' : - if ( var_2 or var_4 == 0 or var_4 == len ( var_0 ) - 1 or not var_0 [ var_4 - 1 ].islower ( ) or not var_0 [ var_4 + 1 ].islower ( ) ) : - return False - var_2 = True - return True -","1!.,0-",4 -789,0075.Sort Colors_1.py,"def sortColors( nums: List[int]) -> None: - i, j = -1, len(nums) - cur = 0 - while cur < j: - if nums[cur] == 0: - i += 1 - nums[cur], nums[i] = nums[i], nums[cur] - cur += 1 - elif nums[cur] == 1: - cur += 1 - else: - j -= 1 - nums[cur], nums[j] = nums[j], nums[cur]","def sample_funcname ( var_0 : List [ int ] ) -> None : - var_5 , var_7 = - 1 , len ( var_0 ) - var_9 = 0 - while var_9 < var_7 : - if var_0 [ var_9 ] == 0 : - var_5 += 1 - var_0 [ var_9 ] , var_0 [ var_5 ] = var_0 [ var_5 ] , var_0 [ var_9 ] - var_9 += 1 - elif var_0 [ var_9 ] == 1 : - var_9 += 1 - else : - var_7 -= 1 - var_0 [ var_9 ] , var_0 [ var_7 ] = var_0 [ var_7 ] , var_0 [ var_9 ] -",1None0,3 -790,0071.Simplify Path_1.py,"def simplifyPath( path: str) -> str: - stk = [] - for s in path.split('/'): - if not s or s == '.': - continue - if s == '..': - if stk: - stk.pop() - else: - stk.append(s) - return '/' + '/'.join(stk)","def sample_funcname ( var_0 : str ) -> str : - var_2 = [ ] - for var_5 in var_0.split ( '/' ) : - if not var_5 or var_5 == '.' : - continue - if var_5 == '..' : - if var_2 : - var_2.pop ( ) - else : - var_2.append ( var_5 ) - return '/' + '/'.join ( var_2 ) -",../.,3 -791,0165.Compare Version Numbers_1.py,"def compareVersion( version1: str, version2: str) -> int: - i, j, m, n = 0, 0, len(version1), len(version2) - while i < m or j < n: - a = b = 0 - while i < m and version1[i] != '.': - a = a * 10 + int(version1[i]) - i += 1 - while j < n and version2[j] != '.': - b = b * 10 + int(version2[j]) - j += 1 - if a != b: - return -1 if a < b else 1 - i += 1 - j += 1 - return 0","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - var_5 , var_6 , var_8 , var_9 = 0 , 0 , len ( var_0 ) , len ( var_2 ) - while var_5 < var_8 or var_6 < var_9 : - var_11 = var_10 = 0 - while var_5 < var_8 and var_0 [ var_5 ] != '.' : - var_11 = var_11 * 10 + int ( var_0 [ var_5 ] ) - var_5 += 1 - while var_6 < var_9 and var_2 [ var_6 ] != '.' : - var_10 = var_10 * 10 + int ( var_2 [ var_6 ] ) - var_6 += 1 - if var_11 != var_10 : - return - 1 if var_11 < var_10 else 1 - var_5 += 1 - var_6 += 1 - return 0 -",1001.,4 -792,0137.Single Number II_1.py,"def singleNumber( nums: List[int]) -> int: - ans = 0 - for i in range(32): - cnt = sum(num >> i & 1 for num in nums) - if cnt % 3: - if i == 31: - ans -= 1 << i - else: - ans |= 1 << i - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 0 - for var_7 in range ( 32 ) : - var_11 = sum ( var_10 >> var_7 & 1 for var_10 in var_0 ) - if var_11 % 3 : - if var_7 == 31 : - var_4 -= 1 << var_7 - else : - var_4 |= 1 << var_7 - return var_4 -",0311332,5 -793,0093.Restore IP Addresses_1.py,"def check(s): - if not (0 <= int(s) <= 255): - return False - if s[0] == '0' and len(s) > 1: - return False - return True","def sample_funcname ( var_0 ) : - if not ( 0 <= int ( var_0 ) <= 255 ) : - return False - if var_0 [ 0 ] == '0' and len ( var_0 ) > 1 : - return False - return True -",100255,4 -794,0744.Find Smallest Letter Greater Than Target_1.py,"def nextGreatestLetter( letters: List[str], target: str) -> str: - left, right = 0, len(letters) - while left < right: - mid = (left + right) >> 1 - if ord(letters[mid]) > ord(target): - right = mid - else: - left = mid + 1 - return letters[left % len(letters)]","def sample_funcname ( var_0 : List [ str ] , var_3 : str ) -> str : - var_5 , var_7 = 0 , len ( var_0 ) - while var_5 < var_7 : - var_9 = ( var_5 + var_7 ) >> 1 - if ord ( var_0 [ var_9 ] ) > ord ( var_3 ) : - var_7 = var_9 - else : - var_5 = var_9 + 1 - return var_0 [ var_5 % len ( var_0 ) ] -",10,2 -795,1372.Longest ZigZag Path in a Binary Tree_1.py,"def dfs(root, l, r): - if root is None: - return - nonlocal ans - ans = max(ans, l, r) - dfs(root.left, r + 1, 0) - dfs(root.right, 0, l + 1)","def sample_funcname ( var_1 , var_2 , var_3 ) : - if var_1 is None : - return - nonlocal var_5 - var_5 = max ( var_5 , var_2 , var_3 ) - var_0 ( var_1.left , var_3 + 1 , 0 ) - var_0 ( var_1.right , 0 , var_2 + 1 ) -",1None0,3 -796,0522.Longest Uncommon Subsequence II_1.py,"def check(a, b): - i = j = 0 - while i < len(a) and j < len(b): - if a[i] == b[j]: - j += 1 - i += 1 - return j == len(b)","def sample_funcname ( var_0 , var_1 ) : - var_4 = var_2 = 0 - while var_4 < len ( var_0 ) and var_2 < len ( var_1 ) : - if var_0 [ var_4 ] == var_1 [ var_2 ] : - var_2 += 1 - var_4 += 1 - return var_2 == len ( var_1 ) -",10,2 -797,0681.Next Closest Time_1.py,"def check(t): - h, m = int(t[:2]), int(t[2:]) - return 0 <= h < 24 and 0 <= m < 60","def sample_funcname ( var_0 ) : - var_3 , var_4 = int ( var_0 [ : 2 ] ) , int ( var_0 [ 2 : ] ) - return 0 <= var_3 < 24 and 0 <= var_4 < 60 -",246002,4 -798,1049.Last Stone Weight II_1.py,"def lastStoneWeightII( stones: List[int]) -> int: - s = sum(stones) - m, n = len(stones), s >> 1 - dp = [0] * (n + 1) - for v in stones: - for j in range(n, v - 1, -1): - dp[j] = max(dp[j], dp[j - v] + v) - return s - dp[-1] * 2","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = sum ( var_0 ) - var_6 , var_8 = len ( var_0 ) , var_4 >> 1 - var_10 = [ 0 ] * ( var_8 + 1 ) - for var_11 in var_0 : - for var_13 in range ( var_8 , var_11 - 1 , - 1 ) : - var_10 [ var_13 ] = max ( var_10 [ var_13 ] , var_10 [ var_13 - var_11 ] + var_11 ) - return var_4 - var_10 [ - 1 ] * 2 -",102,3 -799,1281.Subtract the Product and Sum of Digits of an Integer_1.py,"def subtractProductAndSum( n: int) -> int: - s, p = 0, 1 - while n: - t = n % 10 - n //= 10 - s += t - p *= t - return p - s","def sample_funcname ( var_0 : int ) -> int : - var_3 , var_5 = 0 , 1 - while var_0 : - var_7 = var_0 % 10 - var_0 //= 10 - var_3 += var_7 - var_5 *= var_7 - return var_5 - var_3 -",1010,3 -800,0539.Minimum Time Difference_1.py,"def findMinDifference( timePoints: List[str]) -> int: - if len(timePoints) > 24 * 60: - return 0 - mins = sorted(int(t[:2]) * 60 + int(t[3:]) for t in timePoints) - mins.append(mins[0] + 24 * 60) - res = mins[-1] - for i in range(1, len(mins)): - res = min(res, mins[i] - mins[i - 1]) - return res","def sample_funcname ( var_0 : List [ str ] ) -> int : - if len ( var_0 ) > 24 * 60 : - return 0 - var_12 = sorted ( int ( var_9 [ : 2 ] ) * 60 + int ( var_9 [ 3 : ] ) for var_9 in var_0 ) - var_12.append ( var_12 [ 0 ] + 24 * 60 ) - var_15 = var_12 [ - 1 ] - for var_17 in range ( 1 , len ( var_12 ) ) : - var_15 = min ( var_15 , var_12 [ var_17 ] - var_12 [ var_17 - 1 ] ) - return var_15 -",60240213,6 -801,0055.Jump Game_1.py,"def canJump( nums: List[int]) -> bool: - mx = 0 - for i, num in enumerate(nums): - if i > mx: - return False - mx = max(mx, i + num) - return True","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_5 = 0 - for var_7 , var_8 in enumerate ( var_0 ) : - if var_7 > var_5 : - return False - var_5 = max ( var_5 , var_7 + var_8 ) - return True -",0,1 -802,0757.Set Intersection Size At Least Two_1.py,"def intersectionSizeTwo( intervals: List[List[int]]) -> int: - intervals.sort(key=lambda x: (x[1], -x[0])) - s = e = -1 - ans = 0 - for a, b in intervals: - if a <= s: - continue - if a > e: - ans += 2 - s, e = b - 1, b - else: - ans += 1 - s, e = e, b - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_0.sort ( var_4 = lambda var_5 : ( var_5 [ 1 ] , - var_5 [ 0 ] ) ) - var_9 = var_8 = - 1 - var_10 = 0 - for var_11 , var_12 in var_0 : - if var_11 <= var_9 : - continue - if var_11 > var_8 : - var_10 += 2 - var_9 , var_8 = var_12 - 1 , var_12 - else : - var_10 += 1 - var_9 , var_8 = var_8 , var_12 - return var_10 -",102,3 -803,1089.Duplicate Zeros_1.py,"def duplicateZeros( arr: List[int]) -> None: - n = len(arr) - i, k = -1, 0 - while k < n: - i += 1 - k += 1 if arr[i] else 2 - j = n - 1 - if k == n + 1: - arr[j] = 0 - i, j = i - 1, j - 1 - while ~j: - if arr[i] == 0: - arr[j] = arr[j - 1] = arr[i] - j -= 1 - else: - arr[j] = arr[i] - i, j = i - 1, j - 1","def sample_funcname ( var_0 : List [ int ] ) -> None : - var_5 = len ( var_0 ) - var_7 , var_9 = - 1 , 0 - while var_9 < var_5 : - var_7 += 1 - var_9 += 1 if var_0 [ var_7 ] else 2 - var_11 = var_5 - 1 - if var_9 == var_5 + 1 : - var_0 [ var_11 ] = 0 - var_7 , var_11 = var_7 - 1 , var_11 - 1 - while ~ var_11 : - if var_0 [ var_7 ] == 0 : - var_0 [ var_11 ] = var_0 [ var_11 - 1 ] = var_0 [ var_7 ] - var_11 -= 1 - else : - var_0 [ var_11 ] = var_0 [ var_7 ] - var_7 , var_11 = var_7 - 1 , var_11 - 1 -",1None02,4 -805,1463.Cherry Pickup II_1.py,"def cherryPickup( grid: List[List[int]]) -> int: - m, n = len(grid), len(grid[0]) - dp = [[[0] * n for _ in range(n)] for _ in range(m)] - valid = [[[False] * n for _ in range(n)] for _ in range(m)] - dp[0][0][n - 1] = grid[0][0] + grid[0][n - 1] - valid[0][0][n - 1] = True - for i in range(1, m): - for j1 in range(n): - for j2 in range(n): - t = grid[i][j1] - if j1 != j2: - t += grid[i][j2] - ok = False - for y1 in range(j1 - 1, j1 + 2): - for y2 in range(j2 - 1, j2 + 2): - if 0 <= y1 < n and 0 <= y2 < n and valid[i - 1][y1][y2]: - dp[i][j1][j2] = max( - dp[i][j1][j2], dp[i - 1][y1][y2] + t - ) - ok = True - valid[i][j1][j2] = ok - return max(dp[m - 1][j1][j2] for j1 in range(n) for j2 in range(n))","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_9 = [ [ [ 0 ] * var_6 for var_7 in range ( var_6 ) ] for var_7 in range ( var_4 ) ] - var_11 = [ [ [ False ] * var_6 for var_7 in range ( var_6 ) ] for var_7 in range ( var_4 ) ] - var_9 [ 0 ] [ 0 ] [ var_6 - 1 ] = var_0 [ 0 ] [ 0 ] + var_0 [ 0 ] [ var_6 - 1 ] - var_11 [ 0 ] [ 0 ] [ var_6 - 1 ] = True - for var_14 in range ( 1 , var_4 ) : - for var_15 in range ( var_6 ) : - for var_16 in range ( var_6 ) : - var_17 = var_0 [ var_14 ] [ var_15 ] - if var_15 != var_16 : - var_17 += var_0 [ var_14 ] [ var_16 ] - var_18 = False - for var_20 in range ( var_15 - 1 , var_15 + 2 ) : - for var_21 in range ( var_16 - 1 , var_16 + 2 ) : - if 0 <= var_20 < var_6 and 0 <= var_21 < var_6 and var_11 [ var_14 - 1 ] [ var_20 ] [ var_21 ] : - var_9 [ var_14 ] [ var_15 ] [ var_16 ] = max ( var_9 [ var_14 ] [ var_15 ] [ var_16 ] , var_9 [ var_14 - 1 ] [ var_20 ] [ var_21 ] + var_17 ) - var_18 = True - var_11 [ var_14 ] [ var_15 ] [ var_16 ] = var_18 - return max ( var_9 [ var_4 - 1 ] [ var_15 ] [ var_16 ] for var_15 in range ( var_6 ) for var_16 in range ( var_6 ) ) -",102,3 -806,2007.Find Original Array From Doubled Array_1.py,"def findOriginalArray( changed: List[int]) -> List[int]: - if len(changed) % 2 != 0: - return [] - n = 100010 - counter = [0] * n - for x in changed: - counter[x] += 1 - if counter[0] % 2 != 0: - return [] - res = [0] * (counter[0] // 2) - for i in range(1, n): - if counter[i] == 0: - continue - if i * 2 > n or counter[i] > counter[i * 2]: - return [] - res.extend([i] * counter[i]) - counter[i * 2] -= counter[i] - return res","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - if len ( var_0 ) % 2 != 0 : - return [ ] - var_7 = 100010 - var_8 = [ 0 ] * var_7 - for var_9 in var_0 : - var_8 [ var_9 ] += 1 - if var_8 [ 0 ] % 2 != 0 : - return [ ] - var_11 = [ 0 ] * ( var_8 [ 0 ] // 2 ) - for var_13 in range ( 1 , var_7 ) : - if var_8 [ var_13 ] == 0 : - continue - if var_13 * 2 > var_7 or var_8 [ var_13 ] > var_8 [ var_13 * 2 ] : - return [ ] - var_11.extend ( [ var_13 ] * var_8 [ var_13 ] ) - var_8 [ var_13 * 2 ] -= var_8 [ var_13 ] - return var_11 -",110001002,4 -807,1920.Build Array from Permutation_1.py,"def buildArray( nums: List[int]) -> List[int]: - return [nums[num] for num in nums]","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - return [ var_0 [ var_3 ] for var_3 in var_0 ] -",,0 -808,0960.Delete Columns to Make Sorted III_1.py,"def minDeletionSize( strs: List[str]) -> int: - n = len(strs[0]) - dp = [1] * n - for i in range(1, n): - for j in range(i): - if all(s[j] <= s[i] for s in strs): - dp[i] = max(dp[i], dp[j] + 1) - return n - max(dp)","def sample_funcname ( var_0 : List [ str ] ) -> int : - var_6 = len ( var_0 [ 0 ] ) - var_8 = [ 1 ] * var_6 - for var_10 in range ( 1 , var_6 ) : - for var_11 in range ( var_10 ) : - if all ( var_13 [ var_11 ] <= var_13 [ var_10 ] for var_13 in var_0 ) : - var_8 [ var_10 ] = max ( var_8 [ var_10 ] , var_8 [ var_11 ] + 1 ) - return var_6 - max ( var_8 ) -",10,2 -809,2037.Minimum Number of Moves to Seat Everyone_1.py,"def minMovesToSeat( seats: List[int], students: List[int]) -> int: - seats.sort() - students.sort() - return sum(abs(seats[i] - students[i]) for i in range(len(seats)))","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_0.sort ( ) - var_3.sort ( ) - return sum ( abs ( var_0 [ var_7 ] - var_3 [ var_7 ] ) for var_7 in range ( len ( var_0 ) ) ) -",,0 -810,2100.Find Good Days to Rob the Bank_1.py,"def goodDaysToRobBank( security: List[int], time: int) -> List[int]: - n = len(security) - if n <= time * 2: - return [] - left, right = [0] * n, [0] * n - for i in range(1, n): - if security[i] <= security[i - 1]: - left[i] = left[i - 1] + 1 - for i in range(n - 2, -1, -1): - if security[i] <= security[i + 1]: - right[i] = right[i + 1] + 1 - return [i for i in range(n) if time <= min(left[i], right[i])]","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_5 = len ( var_0 ) - if var_5 <= var_3 * 2 : - return [ ] - var_8 , var_9 = [ 0 ] * var_5 , [ 0 ] * var_5 - for var_12 in range ( 1 , var_5 ) : - if var_0 [ var_12 ] <= var_0 [ var_12 - 1 ] : - var_8 [ var_12 ] = var_8 [ var_12 - 1 ] + 1 - for var_12 in range ( var_5 - 2 , - 1 , - 1 ) : - if var_0 [ var_12 ] <= var_0 [ var_12 + 1 ] : - var_9 [ var_12 ] = var_9 [ var_12 + 1 ] + 1 - return [ var_12 for var_12 in range ( var_5 ) if var_3 <= min ( var_8 [ var_12 ] , var_9 [ var_12 ] ) ] -",102,3 -811,1318.Minimum Flips to Make a OR b Equal to c_1.py,"def minFlips( a: int, b: int, c: int) -> int: - ans = 0 - for i in range(31): - x, y, z = (a >> i) & 1, (b >> i) & 1, (c >> i) & 1 - if (x | y) == z: - continue - if x == 1 and y == 1 and z == 0: - ans += 2 - else: - ans += 1 - return ans","def sample_funcname ( var_0 : int , var_2 : int , var_3 : int ) -> int : - var_5 = 0 - for var_8 in range ( 31 ) : - var_10 , var_11 , var_12 = ( var_0 >> var_8 ) & 1 , ( var_2 >> var_8 ) & 1 , ( var_3 >> var_8 ) & 1 - if ( var_10 | var_11 ) == var_12 : - continue - if var_10 == 1 and var_11 == 1 and var_12 == 0 : - var_5 += 2 - else : - var_5 += 1 - return var_5 -",10312,4 -812,0368.Largest Divisible Subset_1.py,"def largestDivisibleSubset( nums: List[int]) -> List[int]: - nums.sort() - n = len(nums) - f, p = [0] * n, [0] * n - for i in range(n): - l, pre = 1, i - for j in range(n): - if nums[i] % nums[j] == 0 and f[j] + 1 > l: - l = f[j] + 1 - pre = j - f[i] = l - p[i] = pre - max_len, max_index = 0, 0 - for i, v in enumerate(f): - if max_len < v: - max_len = v - max_index = i - ans = [] - while len(ans) < max_len: - ans.append(nums[max_index]) - max_index = p[max_index] - return ans[::-1]","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_0.sort ( ) - var_5 = len ( var_0 ) - var_7 , var_8 = [ 0 ] * var_5 , [ 0 ] * var_5 - for var_10 in range ( var_5 ) : - var_12 , var_13 = 1 , var_10 - for var_14 in range ( var_5 ) : - if var_0 [ var_10 ] % var_0 [ var_14 ] == 0 and var_7 [ var_14 ] + 1 > var_12 : - var_12 = var_7 [ var_14 ] + 1 - var_13 = var_14 - var_7 [ var_10 ] = var_12 - var_8 [ var_10 ] = var_13 - var_15 , var_16 = 0 , 0 - for var_10 , var_18 in enumerate ( var_7 ) : - if var_15 < var_18 : - var_15 = var_18 - var_16 = var_10 - var_19 = [ ] - while len ( var_19 ) < var_15 : - var_19.append ( var_0 [ var_16 ] ) - var_16 = var_8 [ var_16 ] - return var_19 [ : : - 1 ] -",10,2 -813,0638.Shopping Offers_1.py,"def total(price, needs): - return sum(price[i] * needs[i] for i in range(len(needs)))","def sample_funcname ( var_0 , var_1 ) : - return sum ( var_0 [ var_3 ] * var_1 [ var_3 ] for var_3 in range ( len ( var_1 ) ) ) -",,0 -814,0806.Number of Lines To Write String_1.py,"def numberOfLines( widths: List[int], s: str) -> List[int]: - last, row = 0, 1 - for c in s: - w = widths[ord(c) - ord('a')] - if last + w <= 100: - last += w - else: - row += 1 - last = w - return [row, last]","def sample_funcname ( var_0 : List [ int ] , var_3 : str ) -> List [ int ] : - var_6 , var_8 = 0 , 1 - for var_9 in var_3 : - var_12 = var_0 [ ord ( var_9 ) - ord ( 'a' ) ] - if var_6 + var_12 <= 100 : - var_6 += var_12 - else : - var_8 += 1 - var_6 = var_12 - return [ var_8 , var_6 ] -",10100a,4 -815,1014.Best Sightseeing Pair_1.py,"def maxScoreSightseeingPair( values: List[int]) -> int: - res, mx = 0, values[0] - for i in range(1, len(values)): - res = max(res, values[i] - i + mx) - mx = max(mx, values[i] + i) - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_5 = 0 , var_0 [ 0 ] - for var_9 in range ( 1 , len ( var_0 ) ) : - var_4 = max ( var_4 , var_0 [ var_9 ] - var_9 + var_5 ) - var_5 = max ( var_5 , var_0 [ var_9 ] + var_9 ) - return var_4 -",10,2 -816,1877.Minimize Maximum Pair Sum in Array_1.py,"def minPairSum( nums: List[int]) -> int: - nums.sort() - res, n = 0, len(nums) - for i in range(n >> 1): - res = max(res, nums[i] + nums[n - i - 1]) - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( ) - var_5 , var_7 = 0 , len ( var_0 ) - for var_10 in range ( var_7 >> 1 ) : - var_5 = max ( var_5 , var_0 [ var_10 ] + var_0 [ var_7 - var_10 - 1 ] ) - return var_5 -",10,2 -817,0271.Encode and Decode Strings_1.py,"def encode( strs: List[str]) -> str: - ans = [] - for s in strs: - ans.append('{:4}'.format(len(s)) + s) - return ''.join(ans)","def sample_funcname ( var_0 : List [ str ] ) -> str : - var_3 = [ ] - for var_4 in var_0 : - var_3.append ( '{:4}'.format ( len ( var_4 ) ) + var_4 ) - return ''.join ( var_3 ) -",{:4},2 -818,0807.Max Increase to Keep City Skyline_1.py,"def maxIncreaseKeepingSkyline( grid: List[List[int]]) -> int: - rmx = [max(row) for row in grid] - cmx = [max(col) for col in zip(*grid)] - return sum( - (min(rmx[i], cmx[j]) - grid[i][j]) - for i in range(len(grid)) - for j in range(len(grid[0])) - )","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_5 = [ max ( var_4 ) for var_4 in var_0 ] - var_8 = [ max ( var_6 ) for var_6 in zip ( * var_0 ) ] - return sum ( ( min ( var_5 [ var_11 ] , var_8 [ var_12 ] ) - var_0 [ var_11 ] [ var_12 ] ) for var_11 in range ( len ( var_0 ) ) for var_12 in range ( len ( var_0 [ 0 ] ) ) ) -",0,1 -819,1441.Build an Array With Stack Operations_1.py,"def buildArray( target: List[int], n: int) -> List[str]: - cur, ans = 1, [] - for t in target: - for i in range(cur, n + 1): - ans.append('Push') - if t == i: - cur = i + 1 - break - ans.append('Pop') - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ str ] : - var_6 , var_7 = 1 , [ ] - for var_8 in var_0 : - for var_10 in range ( var_6 , var_3 + 1 ) : - var_7.append ( 'Push' ) - if var_8 == var_10 : - var_6 = var_10 + 1 - break - var_7.append ( 'Pop' ) - return var_7 -",Push1Pop,3 -820,1816.Truncate Sentence_1.py,"def truncateSentence( s: str, k: int) -> str: - for i, c in enumerate(s): - if c == ' ': - k -= 1 - if k == 0: - return s[:i] - return s","def sample_funcname ( var_0 : str , var_2 : int ) -> str : - for var_5 , var_6 in enumerate ( var_0 ) : - if var_6 == ' ' : - var_2 -= 1 - if var_2 == 0 : - return var_0 [ : var_5 ] - return var_0 -",1 0,3 -821,2275.Largest Combination With Bitwise AND Greater Than Zero_1.py,"def largestCombination( candidates: List[int]) -> int: - ans = 0 - for i in range(32): - t = 0 - for x in candidates: - t += (x >> i) & 1 - ans = max(ans, t) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 0 - for var_7 in range ( 32 ) : - var_8 = 0 - for var_9 in var_0 : - var_8 += ( var_9 >> var_7 ) & 1 - var_4 = max ( var_4 , var_8 ) - return var_4 -",1032,3 -822,2198.Number of Single Divisor Triplets_1.py,"def check(a, b, c): - s = a + b + c - return sum(s % x == 0 for x in [a, b, c]) == 1","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_3 = var_0 + var_1 + var_2 - return sum ( var_3 % var_5 == 0 for var_5 in [ var_0 , var_1 , var_2 ] ) == 1 -",10,2 -823,1460.Make Two Arrays Equal by Reversing Sub-arrays_1.py,"def canBeEqual( target: List[int], arr: List[int]) -> bool: - target.sort() - arr.sort() - return target == arr","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> bool : - var_0.sort ( ) - var_3.sort ( ) - return var_0 == var_3 -",,0 -824,2259.Remove Digit From Number to Maximize Result_1.py,"def removeDigit( number: str, digit: str) -> str: - return max( - number[:i] + number[i + 1 :] for i, d in enumerate(number) if d == digit - )","def sample_funcname ( var_0 : str , var_2 : str ) -> str : - return max ( var_0 [ : var_4 ] + var_0 [ var_4 + 1 : ] for var_4 , var_7 in enumerate ( var_0 ) if var_7 == var_2 ) -",1,1 -825,0709.To Lower Case_1.py,"def toLowerCase( s: str) -> str: - return ''.join( - [chr(ord(c) | 32) if ord('A') <= ord(c) <= ord('Z') else c for c in s] - )","def sample_funcname ( var_0 : str ) -> str : - return ''.join ( [ chr ( ord ( var_6 ) | 32 ) if ord ( 'A' ) <= ord ( var_6 ) <= ord ( 'Z' ) else var_6 for var_6 in var_0 ] ) -",AZ32,4 -826,0946.Validate Stack Sequences_1.py,"def validateStackSequences( pushed: List[int], popped: List[int]) -> bool: - j, stk = 0, [] - for v in pushed: - stk.append(v) - while stk and stk[-1] == popped[j]: - stk.pop() - j += 1 - return j == len(pushed)","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> bool : - var_6 , var_7 = 0 , [ ] - for var_8 in var_0 : - var_7.append ( var_8 ) - while var_7 and var_7 [ - 1 ] == var_3 [ var_6 ] : - var_7.pop ( ) - var_6 += 1 - return var_6 == len ( var_0 ) -",10,2 -827,1522.Diameter of N-Ary Tree_1.py,"def dfs(root): - if root is None: - return 0 - nonlocal ans - m1 = m2 = 0 - for child in root.children: - t = dfs(child) - if t > m1: - m2, m1 = m1, t - elif t > m2: - m2 = t - ans = max(ans, m1 + m2) - return 1 + m1","def sample_funcname ( var_1 ) : - if var_1 is None : - return 0 - nonlocal var_4 - var_6 = var_5 = 0 - for var_8 in var_1.children : - var_9 = var_0 ( var_8 ) - if var_9 > var_6 : - var_5 , var_6 = var_6 , var_9 - elif var_9 > var_5 : - var_5 = var_9 - var_4 = max ( var_4 , var_6 + var_5 ) - return 1 + var_6 -",10None,3 -828,0853.Car Fleet_1.py,"def carFleet( target, position, speed): - car = [(pos, spe) for pos, spe in zip(position, speed)] - car.sort(reverse=True) - time = [(target - pos) / spe for pos, spe in car] - ls = [] - for i in time: - if not ls: - ls.append(i) - else: - if i > ls[-1]: - ls.append(i) - return len(ls)","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_6 = [ ( var_3 , var_4 ) for var_3 , var_4 in zip ( var_1 , var_2 ) ] - var_6.sort ( var_8 = True ) - var_10 = [ ( var_0 - var_3 ) / var_4 for var_3 , var_4 in var_6 ] - var_11 = [ ] - for var_12 in var_10 : - if not var_11 : - var_11.append ( var_12 ) - else : - if var_12 > var_11 [ - 1 ] : - var_11.append ( var_12 ) - return len ( var_11 ) -",1,1 -829,0868.Binary Gap_1.py,"def binaryGap( n: int) -> int: - ans, j = 0, -1 - for i in range(32): - if n & 1: - if j != -1: - ans = max(ans, i - j) - j = i - n >>= 1 - return ans","def sample_funcname ( var_0 : int ) -> int : - var_3 , var_5 = 0 , - 1 - for var_8 in range ( 32 ) : - if var_0 & 1 : - if var_5 != - 1 : - var_3 = max ( var_3 , var_8 - var_5 ) - var_5 = var_8 - var_0 >>= 1 - return var_3 -",1032,3 -830,1217.Minimum Cost to Move Chips to The Same Position_1.py,"def minCostToMoveChips( position: List[int]) -> int: - a = sum(p % 2 for p in position) - b = len(position) - a - return min(a, b)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_6 = sum ( var_4 % 2 for var_4 in var_0 ) - var_8 = len ( var_0 ) - var_6 - return min ( var_6 , var_8 ) -",2,1 -831,0925.Long Pressed Name_1.py,"def isLongPressedName( name: str, typed: str) -> bool: - m, n = len(name), len(typed) - i = j = 0 - while i < m and j < n: - if name[i] != typed[j]: - return False - cnt1 = cnt2 = 0 - c = name[i] - while i + 1 < m and name[i + 1] == c: - i += 1 - cnt1 += 1 - while j + 1 < n and typed[j + 1] == c: - j += 1 - cnt2 += 1 - if cnt1 > cnt2: - return False - i, j = i + 1, j + 1 - return i == m and j == n","def sample_funcname ( var_0 : str , var_2 : str ) -> bool : - var_5 , var_6 = len ( var_0 ) , len ( var_2 ) - var_9 = var_7 = 0 - while var_9 < var_5 and var_7 < var_6 : - if var_0 [ var_9 ] != var_2 [ var_7 ] : - return False - var_12 = var_11 = 0 - var_13 = var_0 [ var_9 ] - while var_9 + 1 < var_5 and var_0 [ var_9 + 1 ] == var_13 : - var_9 += 1 - var_12 += 1 - while var_7 + 1 < var_6 and var_2 [ var_7 + 1 ] == var_13 : - var_7 += 1 - var_11 += 1 - if var_12 > var_11 : - return False - var_9 , var_7 = var_9 + 1 , var_7 + 1 - return var_9 == var_5 and var_7 == var_6 -",10,2 -832,0067.Add Binary_1.py,"def addBinary( a: str, b: str) -> str: - return bin(int(a, 2) + int(b, 2))[2:]","def sample_funcname ( var_0 : str , var_2 : str ) -> str : - return bin ( int ( var_0 , 2 ) + int ( var_2 , 2 ) ) [ 2 : ] -",2,1 -833,1698.Number of Distinct Substrings in a String_1.py,"def countDistinct( s: str) -> int: - n = len(s) - return len({s[i:j] for i in range(n) for j in range(i + 1, n + 1)})","def sample_funcname ( var_0 : str ) -> int : - var_4 = len ( var_0 ) - return len ( { var_0 [ var_5 : var_6 ] for var_5 in range ( var_4 ) for var_6 in range ( var_5 + 1 , var_4 + 1 ) } ) -",1,1 -834,1007.Minimum Domino Rotations For Equal Row_1.py,"def minDominoRotations( A: List[int], B: List[int]) -> int: - a, b = A[0], B[0] - c, d = b, a - counta, countb = 0, 0 - countc, countd = 1, 1 - for ai, bi in zip(A[1:], B[1:]): - if ai == a: - pass - elif ai != a and bi == a: - counta += 1 - else: - counta = -30000 - if bi == b: - pass - elif bi != b and ai == b: - countb += 1 - else: - countb = -30000 - if ai == c: - pass - elif ai != c and bi == c: - countc += 1 - else: - countc = -30000 - if bi == d: - pass - elif bi != d and ai == d: - countd += 1 - else: - countd = -30000 - if counta < 0 and countb < 0 and countc < 0 and countd < 0: - return -1 - else: - ans = 30000 - for count in [counta, countb, countc, countd]: - if count >= 0: - ans = min(ans, count) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_5 , var_6 = var_0 [ 0 ] , var_3 [ 0 ] - var_7 , var_8 = var_6 , var_5 - var_9 , var_10 = 0 , 0 - var_12 , var_13 = 1 , 1 - for var_15 , var_16 in zip ( var_0 [ 1 : ] , var_3 [ 1 : ] ) : - if var_15 == var_5 : - pass - elif var_15 != var_5 and var_16 == var_5 : - var_9 += 1 - else : - var_9 = - 30000 - if var_16 == var_6 : - pass - elif var_16 != var_6 and var_15 == var_6 : - var_10 += 1 - else : - var_10 = - 30000 - if var_15 == var_7 : - pass - elif var_15 != var_7 and var_16 == var_7 : - var_12 += 1 - else : - var_12 = - 30000 - if var_16 == var_8 : - pass - elif var_16 != var_8 and var_15 == var_8 : - var_13 += 1 - else : - var_13 = - 30000 - if var_9 < 0 and var_10 < 0 and var_12 < 0 and var_13 < 0 : - return - 1 - else : - var_18 = 30000 - for var_19 in [ var_9 , var_10 , var_12 , var_13 ] : - if var_19 >= 0 : - var_18 = min ( var_18 , var_19 ) - return var_18 -",1030000,3 -835,0735.Asteroid Collision_1.py,"def asteroidCollision( asteroids: List[int]) -> List[int]: - ans = [] - for a in asteroids: - if a > 0: - ans.append(a) - else: - while ans and 0 < ans[-1] < -a: - ans.pop() - if ans and ans[-1] == -a: - ans.pop() - elif not ans or ans[-1] < -a: - ans.append(a) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_3 = [ ] - for var_4 in var_0 : - if var_4 > 0 : - var_3.append ( var_4 ) - else : - while var_3 and 0 < var_3 [ - 1 ] < - var_4 : - var_3.pop ( ) - if var_3 and var_3 [ - 1 ] == - var_4 : - var_3.pop ( ) - elif not var_3 or var_3 [ - 1 ] < - var_4 : - var_3.append ( var_4 ) - return var_3 -",10,2 -836,2134.Minimum Swaps to Group All 1's Together II_1.py,"def minSwaps( nums: List[int]) -> int: - cnt = nums.count(1) - n = len(nums) - s = [0] * ((n << 1) + 1) - for i in range(n << 1): - s[i + 1] = s[i] + nums[i % n] - mx = 0 - for i in range(n << 1): - j = i + cnt - 1 - if j < (n << 1): - mx = max(mx, s[j + 1] - s[i]) - return cnt - mx","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_0.count ( 1 ) - var_7 = len ( var_0 ) - var_9 = [ 0 ] * ( ( var_7 << 1 ) + 1 ) - for var_11 in range ( var_7 << 1 ) : - var_9 [ var_11 + 1 ] = var_9 [ var_11 ] + var_0 [ var_11 % var_7 ] - var_12 = 0 - for var_11 in range ( var_7 << 1 ) : - var_13 = var_11 + var_5 - 1 - if var_13 < ( var_7 << 1 ) : - var_12 = max ( var_12 , var_9 [ var_13 + 1 ] - var_9 [ var_11 ] ) - return var_5 - var_12 -",10,2 -838,1886.Determine Whether Matrix Can Be Obtained By Rotation_1.py,"def findRotation( mat: List[List[int]], target: List[List[int]]) -> bool: - for _ in range(4): - mat = [list(col) for col in zip(*mat[::-1])] - if mat == target: - return True - return False","def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : List [ List [ int ] ] ) -> bool : - for var_7 in range ( 4 ) : - var_0 = [ list ( var_8 ) for var_8 in zip ( * var_0 [ : : - 1 ] ) ] - if var_0 == var_3 : - return True - return False -",14,2 -839,2033.Minimum Operations to Make a Uni-Value Grid_1.py,"def minOperations( grid: List[List[int]], x: int) -> int: - nums = [] - m, n = len(grid), len(grid[0]) - base = grid[0][0] - for i in range(m): - for j in range(n): - if abs(grid[i][j] - base) % x != 0: - return -1 - nums.append(grid[i][j]) - nums.sort() - mid = nums[len(nums) >> 1] - ans = 0 - for num in nums: - ans += abs(num - mid) // x - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : int ) -> int : - var_4 = [ ] - var_6 , var_8 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_9 = var_0 [ 0 ] [ 0 ] - for var_11 in range ( var_6 ) : - for var_12 in range ( var_8 ) : - if abs ( var_0 [ var_11 ] [ var_12 ] - var_9 ) % var_3 != 0 : - return - 1 - var_4.append ( var_0 [ var_11 ] [ var_12 ] ) - var_4.sort ( ) - var_17 = var_4 [ len ( var_4 ) >> 1 ] - var_18 = 0 - for var_19 in var_4 : - var_18 += abs ( var_19 - var_17 ) // var_3 - return var_18 -",10,2 -840,0714.Best Time to Buy and Sell Stock with Transaction Fee_1.py,"def maxProfit( prices: List[int], fee: int) -> int: - f1, f2 = -prices[0], 0 - for price in prices[1:]: - f1 = max(f1, f2 - price) - f2 = max(f2, f1 + price - fee) - return f2","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_6 = - var_0 [ 0 ] , 0 - for var_8 in var_0 [ 1 : ] : - var_5 = max ( var_5 , var_6 - var_8 ) - var_6 = max ( var_6 , var_5 + var_8 - var_3 ) - return var_6 -",10,2 -841,1762.Buildings With an Ocean View_1.py,"def findBuildings( heights: List[int]) -> List[int]: - mx = 0 - ans = [] - for i in range(len(heights) - 1, -1, -1): - v = heights[i] - if mx < v: - ans.append(i) - mx = v - return ans[::-1]","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 = 0 - var_5 = [ ] - for var_9 in range ( len ( var_0 ) - 1 , - 1 , - 1 ) : - var_10 = var_0 [ var_9 ] - if var_4 < var_10 : - var_5.append ( var_9 ) - var_4 = var_10 - return var_5 [ : : - 1 ] -",10,2 -842,1605.Find Valid Matrix Given Row and Column Sums_1.py,"def restoreMatrix( rowSum: List[int], colSum: List[int]) -> List[List[int]]: - m, n = len(rowSum), len(colSum) - ans = [[0] * n for _ in range(m)] - for i in range(m): - for j in range(n): - x = min(rowSum[i], colSum[j]) - ans[i][j] = x - rowSum[i] -= x - colSum[j] -= x - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> List [ List [ int ] ] : - var_5 , var_6 = len ( var_0 ) , len ( var_3 ) - var_10 = [ [ 0 ] * var_6 for var_8 in range ( var_5 ) ] - for var_11 in range ( var_5 ) : - for var_12 in range ( var_6 ) : - var_14 = min ( var_0 [ var_11 ] , var_3 [ var_12 ] ) - var_10 [ var_11 ] [ var_12 ] = var_14 - var_0 [ var_11 ] -= var_14 - var_3 [ var_12 ] -= var_14 - return var_10 -",0,1 -843,1305.All Elements in Two Binary Search Trees_1.py,"def merge(t1, t2): - ans = [] - i = j = 0 - while i < len(t1) and j < len(t2): - if t1[i] <= t2[j]: - ans.append(t1[i]) - i += 1 - else: - ans.append(t2[j]) - j += 1 - while i < len(t1): - ans.append(t1[i]) - i += 1 - while j < len(t2): - ans.append(t2[j]) - j += 1 - return ans","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - var_5 = var_3 = 0 - while var_5 < len ( var_0 ) and var_3 < len ( var_1 ) : - if var_0 [ var_5 ] <= var_1 [ var_3 ] : - var_2.append ( var_0 [ var_5 ] ) - var_5 += 1 - else : - var_2.append ( var_1 [ var_3 ] ) - var_3 += 1 - while var_5 < len ( var_0 ) : - var_2.append ( var_0 [ var_5 ] ) - var_5 += 1 - while var_3 < len ( var_1 ) : - var_2.append ( var_1 [ var_3 ] ) - var_3 += 1 - return var_2 -",10,2 -844,1640.Check Array Formation Through Concatenation_1.py,"def canFormArray( arr: List[int], pieces: List[List[int]]) -> bool: - mapper = {piece[0]: piece for piece in pieces} - i, n = 0, len(arr) - while i < n: - if arr[i] not in mapper: - return False - vals = mapper[arr[i]] - for val in vals: - if arr[i] != val: - return False - i += 1 - return True","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ List [ int ] ] ) -> bool : - var_7 = { var_5 [ 0 ] : var_5 for var_5 in var_3 } - var_8 , var_10 = 0 , len ( var_0 ) - while var_8 < var_10 : - if var_0 [ var_8 ] not in var_7 : - return False - var_12 = var_7 [ var_0 [ var_8 ] ] - for var_13 in var_12 : - if var_0 [ var_8 ] != var_13 : - return False - var_8 += 1 - return True -",10,2 -845,2133.Check if Every Row and Column Contains All Numbers_1.py,"def checkValid( matrix: List[List[int]]) -> bool: - n = len(matrix) - for i in range(n): - seen = [False] * n - for j in range(n): - v = matrix[i][j] - 1 - if seen[v]: - return False - seen[v] = True - for j in range(n): - seen = [False] * n - for i in range(n): - v = matrix[i][j] - 1 - if seen[v]: - return False - seen[v] = True - return True","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> bool : - var_5 = len ( var_0 ) - for var_7 in range ( var_5 ) : - var_9 = [ False ] * var_5 - for var_10 in range ( var_5 ) : - var_12 = var_0 [ var_7 ] [ var_10 ] - 1 - if var_9 [ var_12 ] : - return False - var_9 [ var_12 ] = True - for var_10 in range ( var_5 ) : - var_9 = [ False ] * var_5 - for var_7 in range ( var_5 ) : - var_12 = var_0 [ var_7 ] [ var_10 ] - 1 - if var_9 [ var_12 ] : - return False - var_9 [ var_12 ] = True - return True -",1,1 -846,0866.Prime Palindrome_2.py,"def is_prime(x): - if x < 2: - return False - v = 2 - while v * v <= x: - if x % v == 0: - return False - v += 1 - return True","def sample_funcname ( var_0 ) : - if var_0 < 2 : - return False - var_3 = 2 - while var_3 * var_3 <= var_0 : - if var_0 % var_3 == 0 : - return False - var_3 += 1 - return True -",102,3 -847,2211.Count Collisions on a Road_1.py,"def countCollisions( directions: str) -> int: - d = directions.lstrip('L').rstrip('R') - return len(d) - d.count('S')","def sample_funcname ( var_0 : str ) -> int : - var_7 = var_0.var_3 ( 'L' ).rstrip ( 'R' ) - return len ( var_7 ) - var_7.count ( 'S' ) -",SLR,3 -848,0121.Best Time to Buy and Sell Stock_1.py,"def maxProfit( prices: List[int]) -> int: - res, mi = 0, prices[0] - for price in prices[1:]: - res = max(res, price - mi) - mi = min(mi, price) - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_5 = 0 , var_0 [ 0 ] - for var_7 in var_0 [ 1 : ] : - var_4 = max ( var_4 , var_7 - var_5 ) - var_5 = min ( var_5 , var_7 ) - return var_4 -",10,2 -849,0970.Powerful Integers_1.py,"def powerfulIntegers( x: int, y: int, bound: int) -> List[int]: - s = set() - i = 1 - while i < bound: - j = 1 - while j < bound: - if i + j <= bound: - s.add(i + j) - if y == 1: - break - j *= y - if x == 1: - break - i *= x - return list(s)","def sample_funcname ( var_0 : int , var_2 : int , var_3 : int ) -> List [ int ] : - var_6 = set ( ) - var_8 = 1 - while var_8 < var_3 : - var_9 = 1 - while var_9 < var_3 : - if var_8 + var_9 <= var_3 : - var_6.add ( var_8 + var_9 ) - if var_2 == 1 : - break - var_9 *= var_2 - if var_0 == 1 : - break - var_8 *= var_0 - return list ( var_6 ) -",1,1 -850,1813.Sentence Similarity III_1.py,"def areSentencesSimilar( sentence1: str, sentence2: str) -> bool: - if sentence1 == sentence2: - return True - n1, n2 = len(sentence1), len(sentence2) - if n1 == n2: - return False - if n1 < n2: - sentence1, sentence2 = sentence2, sentence1 - words1, words2 = sentence1.split(), sentence2.split() - i = j = 0 - n1, n2 = len(words1), len(words2) - while i < n2 and words1[i] == words2[i]: - i += 1 - if i == n2: - return True - while j < n2 and words1[n1 - 1 - j] == words2[n2 - 1 - j]: - j += 1 - return j == n2 or i + j == n2","def sample_funcname ( var_0 : str , var_2 : str ) -> bool : - if var_0 == var_2 : - return True - var_6 , var_7 = len ( var_0 ) , len ( var_2 ) - if var_6 == var_7 : - return False - if var_6 < var_7 : - var_0 , var_2 = var_2 , var_0 - var_10 , var_11 = var_0.split ( ) , var_2.split ( ) - var_14 = var_12 = 0 - var_6 , var_7 = len ( var_10 ) , len ( var_11 ) - while var_14 < var_7 and var_10 [ var_14 ] == var_11 [ var_14 ] : - var_14 += 1 - if var_14 == var_7 : - return True - while var_12 < var_7 and var_10 [ var_6 - 1 - var_12 ] == var_11 [ var_7 - 1 - var_12 ] : - var_12 += 1 - return var_12 == var_7 or var_14 + var_12 == var_7 -",10,2 -851,2264.Largest 3-Same-Digit Number in String_1.py,"def largestGoodInteger( num: str) -> str: - for i in range(9, -1, -1): - t = str(i) * 3 - if t in num: - return t - return ''","def sample_funcname ( var_0 : str ) -> str : - for var_5 in range ( 9 , - 1 , - 1 ) : - var_7 = str ( var_5 ) * 3 - if var_7 in var_0 : - return var_7 - return '' -",931,4 -852,2261.K Divisible Elements Subarrays_1.py,"def countDistinct( nums: List[int], k: int, p: int) -> int: - n = len(nums) - s = set() - for i in range(n): - cnt = 0 - t = """" - for j in range(i, n): - if nums[j] % p == 0: - cnt += 1 - if cnt <= k: - t += str(nums[j]) + "","" - s.add(t) - else: - break - return len(s)","def sample_funcname ( var_0 : List [ int ] , var_3 : int , var_4 : int ) -> int : - var_6 = len ( var_0 ) - var_8 = set ( ) - for var_10 in range ( var_6 ) : - var_12 = 0 - var_14 = """" - for var_15 in range ( var_10 , var_6 ) : - if var_0 [ var_15 ] % var_4 == 0 : - var_12 += 1 - if var_12 <= var_3 : - var_14 += str ( var_0 [ var_15 ] ) + "","" - var_8.add ( var_14 ) - else : - break - return len ( var_8 ) -","10,",4 -853,1929.Concatenation of Array_1.py,"def getConcatenation( nums: List[int]) -> List[int]: - return nums + nums","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - return var_0 + var_0 -",,0 -854,0754.Reach a Number_1.py,"def reachNumber( target: int) -> int: - target = abs(target) - k = s = 0 - while 1: - if s >= target and (s - target) % 2 == 0: - break - k += 1 - s += k - return k","def sample_funcname ( var_0 : int ) -> int : - var_0 = abs ( var_0 ) - var_5 = var_3 = 0 - while 1 : - if var_3 >= var_0 and ( var_3 - var_0 ) % 2 == 0 : - break - var_5 += 1 - var_3 += var_5 - return var_5 -",102,3 -855,0673.Number of Longest Increasing Subsequence_1.py,"def findNumberOfLIS( nums: List[int]) -> int: - maxLen, ans, n = 0, 0, len(nums) - dp, cnt = [1] * n, [1] * n - for i in range(n): - for j in range(i): - if nums[i] > nums[j]: - if dp[j] + 1 > dp[i]: - dp[i] = dp[j] + 1 - cnt[i] = cnt[j] - elif dp[j] + 1 == dp[i]: - cnt[i] += cnt[j] - if dp[i] > maxLen: - maxLen = dp[i] - ans = cnt[i] - elif dp[i] == maxLen: - ans += cnt[i] - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_5 , var_7 = 0 , 0 , len ( var_0 ) - var_9 , var_10 = [ 1 ] * var_7 , [ 1 ] * var_7 - for var_12 in range ( var_7 ) : - for var_13 in range ( var_12 ) : - if var_0 [ var_12 ] > var_0 [ var_13 ] : - if var_9 [ var_13 ] + 1 > var_9 [ var_12 ] : - var_9 [ var_12 ] = var_9 [ var_13 ] + 1 - var_10 [ var_12 ] = var_10 [ var_13 ] - elif var_9 [ var_13 ] + 1 == var_9 [ var_12 ] : - var_10 [ var_12 ] += var_10 [ var_13 ] - if var_9 [ var_12 ] > var_4 : - var_4 = var_9 [ var_12 ] - var_5 = var_10 [ var_12 ] - elif var_9 [ var_12 ] == var_4 : - var_5 += var_10 [ var_12 ] - return var_5 -",10,2 -856,0918.Maximum Sum Circular Subarray_1.py,"def maxSubarraySumCircular( nums: List[int]) -> int: - s1 = s2 = f1 = f2 = nums[0] - for num in nums[1:]: - f1 = num + max(f1, 0) - f2 = num + min(f2, 0) - s1 = max(s1, f1) - s2 = min(s2, f2) - return s1 if s1 <= 0 else max(s1, sum(nums) - s2)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_7 = var_3 = var_4 = var_5 = var_0 [ 0 ] - for var_9 in var_0 [ 1 : ] : - var_4 = var_9 + max ( var_4 , 0 ) - var_5 = var_9 + min ( var_5 , 0 ) - var_7 = max ( var_7 , var_4 ) - var_3 = min ( var_3 , var_5 ) - return var_7 if var_7 <= 0 else max ( var_7 , sum ( var_0 ) - var_3 ) -",10,2 -857,2125.Number of Laser Beams in a Bank_1.py,"def numberOfBeams( bank: List[str]) -> int: - last = ans = 0 - for b in bank: - if (t := b.count('1')) > 0: - ans += last * t - last = t - return ans","def sample_funcname ( var_0 : List [ str ] ) -> int : - var_6 = var_4 = 0 - for var_7 in var_0 : - if ( var_8 := var_7.count ( '1' ) ) > 0 : - var_4 += var_6 * var_8 - var_6 = var_8 - return var_4 -",01,2 -858,0752.Open the Lock_1.py,"def next(s): - res = [] - s = list(s) - for i in range(4): - c = s[i] - s[i] = '9' if c == '0' else str(int(c) - 1) - res.append(''.join(s)) - s[i] = '0' if c == '9' else str(int(c) + 1) - res.append(''.join(s)) - s[i] = c - return res","def sample_funcname ( var_0 ) : - var_1 = [ ] - var_0 = list ( var_0 ) - for var_5 in range ( 4 ) : - var_6 = var_0 [ var_5 ] - var_0 [ var_5 ] = '9' if var_6 == '0' else str ( int ( var_6 ) - 1 ) - var_1.append ( ''.join ( var_0 ) ) - var_0 [ var_5 ] = '0' if var_6 == '9' else str ( int ( var_6 ) + 1 ) - var_1.append ( ''.join ( var_0 ) ) - var_0 [ var_5 ] = var_6 - return var_1 -",9014,5 -859,0202.Happy Number_1.py,"def get_next(n): - s = 0 - while n > 0: - n, digit = divmod(n, 10) - s += digit**2 - return s","def sample_funcname ( var_0 ) : - var_2 = 0 - while var_0 > 0 : - var_0 , var_5 = divmod ( var_0 , 10 ) - var_2 += var_5 ** 2 - return var_2 -",1002,3 -860,1022.Sum of Root To Leaf Binary Numbers_1.py,"def dfs(root, t): - if root is None: - return 0 - t = (t << 1) | root.val - if root.left is None and root.right is None: - return t - return dfs(root.left, t) + dfs(root.right, t)","def sample_funcname ( var_1 , var_2 ) : - if var_1 is None : - return 0 - var_2 = ( var_2 << 1 ) | var_1.val - if var_1.left is None and var_1.right is None : - return var_2 - return var_0 ( var_1.left , var_2 ) + var_0 ( var_1.right , var_2 ) -",10None,3 -861,0458.Poor Pigs_1.py,"def poorPigs( buckets: int, minutesToDie: int, minutesToTest: int) -> int: - base = minutesToTest // minutesToDie + 1 - res, p = 0, 1 - while p < buckets: - p *= base - res += 1 - return res","def sample_funcname ( var_0 : int , var_2 : int , var_3 : int ) -> int : - var_5 = var_3 // var_2 + 1 - var_7 , var_8 = 0 , 1 - while var_8 < var_0 : - var_8 *= var_5 - var_7 += 1 - return var_7 -",10,2 -862,2109.Adding Spaces to a String_1.py,"def addSpaces( s: str, spaces: List[int]) -> str: - ans = [] - j = 0 - for i, c in enumerate(s): - if j < len(spaces) and i == spaces[j]: - ans.append(' ') - j += 1 - ans.append(c) - return ''.join(ans)","def sample_funcname ( var_0 : str , var_2 : List [ int ] ) -> str : - var_5 = [ ] - var_7 = 0 - for var_9 , var_10 in enumerate ( var_0 ) : - if var_7 < len ( var_2 ) and var_9 == var_2 [ var_7 ] : - var_5.append ( '' ) - var_7 += 1 - var_5.append ( var_10 ) - return ''.join ( var_5 ) -",10,3 -863,1220.Count Vowels Permutation_1.py,"def countVowelPermutation( n: int) -> int: - dp = (1, 1, 1, 1, 1) - MOD = 1000000007 - for _ in range(n - 1): - dp = ( - (dp[1] + dp[2] + dp[4]) % MOD, - (dp[0] + dp[2]) % MOD, - (dp[1] + dp[3]) % MOD, - dp[2], - (dp[2] + dp[3]) % MOD, - ) - return sum(dp) % MOD","def sample_funcname ( var_0 : int ) -> int : - var_3 = ( 1 , 1 , 1 , 1 , 1 ) - var_5 = 1000000007 - for var_7 in range ( var_0 - 1 ) : - var_3 = ( ( var_3 [ 1 ] + var_3 [ 2 ] + var_3 [ 4 ] ) % var_5 , ( var_3 [ 0 ] + var_3 [ 2 ] ) % var_5 , ( var_3 [ 1 ] + var_3 [ 3 ] ) % var_5 , var_3 [ 2 ] , ( var_3 [ 2 ] + var_3 [ 3 ] ) % var_5 , ) - return sum ( var_3 ) % var_5 -",021100000000734,6 -864,1190.Reverse Substrings Between Each Pair of Parentheses_1.py,"def reverseParentheses( s: str) -> str: - stack = [] - for c in s: - if c == "")"": - tmp = [] - while stack[-1] != ""("": - tmp += stack.pop() - stack.pop() - stack += tmp - else: - stack.append(c) - return """".join(stack)","def sample_funcname ( var_0 : str ) -> str : - var_2 = [ ] - for var_3 in var_0 : - if var_3 == "")"" : - var_5 = [ ] - while var_2 [ - 1 ] != ""("" : - var_5 += var_2.pop ( ) - var_2.pop ( ) - var_2 += var_5 - else : - var_2.append ( var_3 ) - return """".join ( var_2 ) -",)1(,4 -865,1991.Find the Middle Index in Array_1.py,"def findMiddleIndex( nums: List[int]) -> int: - s = sum(nums) - total = 0 - for i, num in enumerate(nums): - total += num - if total - num == s - total: - return i - return -1","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = sum ( var_0 ) - var_6 = 0 - for var_8 , var_9 in enumerate ( var_0 ) : - var_6 += var_9 - if var_6 - var_9 == var_4 - var_6 : - return var_8 - return - 1 -",10,2 -866,0687.Longest Univalue Path_1.py,"def dfs(root): - if root is None: - return 0 - left, right = dfs(root.left), dfs(root.right) - left = left + 1 if root.left and root.left.val == root.val else 0 - right = right + 1 if root.right and root.right.val == root.val else 0 - nonlocal ans - ans = max(ans, left + right) - return max(left, right)","def sample_funcname ( var_1 ) : - if var_1 is None : - return 0 - left , right = var_0 ( var_1.left ) , var_0 ( var_1.right ) - left = left + 1 if var_1.left and var_1.left.val == var_1.val else 0 - right = right + 1 if var_1.right and var_1.right.val == var_1.val else 0 - nonlocal var_8 - var_8 = max ( var_8 , left + right ) - return max ( left , right ) -",10None,3 -867,2178.Maximum Split of Positive Even Integers_1.py,"def maximumEvenSplit( finalSum: int) -> List[int]: - if finalSum % 2: - return [] - i = 2 - ans = [] - while i <= finalSum: - ans.append(i) - finalSum -= i - i += 2 - ans[-1] += finalSum - return ans","def sample_funcname ( var_0 : int ) -> List [ int ] : - if var_0 % 2 : - return [ ] - var_4 = 2 - var_5 = [ ] - while var_4 <= var_0 : - var_5.append ( var_4 ) - var_0 -= var_4 - var_4 += 2 - var_5 [ - 1 ] += var_0 - return var_5 -",12,2 -868,1035.Uncrossed Lines_1.py,"def maxUncrossedLines( nums1: List[int], nums2: List[int]) -> int: - m, n = len(nums1), len(nums2) - dp = [[0] * (n + 1) for i in range(m + 1)] - for i in range(1, m + 1): - for j in range(1, n + 1): - if nums1[i - 1] == nums2[j - 1]: - dp[i][j] = dp[i - 1][j - 1] + 1 - else: - dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - return dp[m][n]","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_5 , var_6 = len ( var_0 ) , len ( var_3 ) - var_11 = [ [ 0 ] * ( var_6 + 1 ) for var_9 in range ( var_5 + 1 ) ] - for var_9 in range ( 1 , var_5 + 1 ) : - for var_12 in range ( 1 , var_6 + 1 ) : - if var_0 [ var_9 - 1 ] == var_3 [ var_12 - 1 ] : - var_11 [ var_9 ] [ var_12 ] = var_11 [ var_9 - 1 ] [ var_12 - 1 ] + 1 - else : - var_11 [ var_9 ] [ var_12 ] = max ( var_11 [ var_9 - 1 ] [ var_12 ] , var_11 [ var_9 ] [ var_12 - 1 ] ) - return var_11 [ var_5 ] [ var_6 ] -",10,2 -869,0930.Binary Subarrays With Sum_1.py,"def numSubarraysWithSum( nums: List[int], goal: int) -> int: - i1 = i2 = s1 = s2 = j = ans = 0 - n = len(nums) - while j < n: - s1 += nums[j] - s2 += nums[j] - while i1 <= j and s1 > goal: - s1 -= nums[i1] - i1 += 1 - while i2 <= j and s2 >= goal: - s2 -= nums[i2] - i2 += 1 - ans += i2 - i1 - j += 1 - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_10 = var_4 = var_5 = var_6 = var_7 = var_8 = 0 - var_12 = len ( var_0 ) - while var_7 < var_12 : - var_5 += var_0 [ var_7 ] - var_6 += var_0 [ var_7 ] - while var_10 <= var_7 and var_5 > var_3 : - var_5 -= var_0 [ var_10 ] - var_10 += 1 - while var_4 <= var_7 and var_6 >= var_3 : - var_6 -= var_0 [ var_4 ] - var_4 += 1 - var_8 += var_4 - var_10 - var_7 += 1 - return var_8 -",10,2 -870,1524.Number of Sub-arrays With Odd Sum_1.py,"def numOfSubarrays( arr: List[int]) -> int: - MOD = int(1e9) + 7 - counter = [0] * 2 - s = ans = 0 - for v in arr: - s += v - counter[s % 2] += 1 - if s % 2 == 1: - ans += 1 + counter[0] - else: - ans += counter[1] - return ans % MOD","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = int ( 1e9 ) + 7 - var_8 = [ 0 ] * 2 - var_10 = var_9 = 0 - for var_11 in var_0 : - var_10 += var_11 - var_8 [ var_10 % 2 ] += 1 - if var_10 % 2 == 1 : - var_9 += 1 + var_8 [ 0 ] - else : - var_9 += var_8 [ 1 ] - return var_9 % var_5 -",1e90217,5 -871,0899.Orderly Queue_1.py,"def orderlyQueue( s: str, k: int) -> str: - if k == 1: - ans = s - for _ in range(len(s) - 1): - s = s[1:] + s[0] - ans = min(ans, s) - return ans - return """".join(sorted(s))","def sample_funcname ( var_0 : str , var_2 : int ) -> str : - if var_2 == 1 : - var_5 = var_0 - for var_8 in range ( len ( var_0 ) - 1 ) : - var_0 = var_0 [ 1 : ] + var_0 [ 0 ] - var_5 = min ( var_5 , var_0 ) - return var_5 - return """".join ( sorted ( var_0 ) ) -",10,3 -872,0915.Partition Array into Disjoint Intervals_1.py,"def partitionDisjoint( A): - loc = 0 - vmx = A[0] - mx = A[0] - for i, el in enumerate(A): - if el > mx: - mx = el - if el < vmx: - loc = i - vmx = mx - return loc + 1","def sample_funcname ( var_0 ) : - var_2 = 0 - var_3 = var_0 [ 0 ] - var_4 = var_0 [ 0 ] - for var_6 , var_7 in enumerate ( var_0 ) : - if var_7 > var_4 : - var_4 = var_7 - if var_7 < var_3 : - var_2 = var_6 - var_3 = var_4 - return var_2 + 1 -",10,2 -873,2029.Stone Game IX_1.py,"def check(c): - if c[1] == 0: - return False - c[1] -= 1 - turn = 1 + min(c[1], c[2]) * 2 + c[0] - if c[1] > c[2]: - turn += 1 - c[1] -= 1 - return turn % 2 == 1 and c[1] != c[2]","def sample_funcname ( var_0 ) : - if var_0 [ 1 ] == 0 : - return False - var_0 [ 1 ] -= 1 - var_6 = 1 + min ( var_0 [ 1 ] , var_0 [ 2 ] ) * 2 + var_0 [ 0 ] - if var_0 [ 1 ] > var_0 [ 2 ] : - var_6 += 1 - var_0 [ 1 ] -= 1 - return var_6 % 2 == 1 and var_0 [ 1 ] != var_0 [ 2 ] -",102,3 -874,2214.Minimum Health to Beat Game_1.py,"def minimumHealth( damage: List[int], armor: int) -> int: - return sum(damage) - min(max(damage), armor) + 1","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - return sum ( var_0 ) - min ( max ( var_0 ) , var_3 ) + 1 -",1,1 -876,0073.Set Matrix Zeroes_1.py,"def setZeroes( matrix: List[List[int]]) -> None: - m, n = len(matrix), len(matrix[0]) - zero_rows = [False] * m - zero_cols = [False] * n - for i in range(m): - for j in range(n): - if matrix[i][j] == 0: - zero_rows[i] = zero_cols[j] = True - for i in range(m): - for j in range(n): - if zero_rows[i] or zero_cols[j]: - matrix[i][j] = 0","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> None : - var_5 , var_7 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_9 = [ False ] * var_5 - var_10 = [ False ] * var_7 - for var_12 in range ( var_5 ) : - for var_13 in range ( var_7 ) : - if var_0 [ var_12 ] [ var_13 ] == 0 : - var_9 [ var_12 ] = var_10 [ var_13 ] = True - for var_12 in range ( var_5 ) : - for var_13 in range ( var_7 ) : - if var_9 [ var_12 ] or var_10 [ var_13 ] : - var_0 [ var_12 ] [ var_13 ] = 0 -",0None,2 -877,0229.Majority Element II_1.py,"def majorityElement( nums: List[int]) -> List[int]: - n1 = n2 = 0 - m1, m2 = 0, 1 - for m in nums: - if m == m1: - n1 += 1 - elif m == m2: - n2 += 1 - elif n1 == 0: - m1, n1 = m, 1 - elif n2 == 0: - m2, n2 = m, 1 - else: - n1, n2 = n1 - 1, n2 - 1 - return [m for m in [m1, m2] if nums.count(m) > len(nums) // 3]","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_5 = var_3 = 0 - var_6 , var_8 = 0 , 1 - for var_9 in var_0 : - if var_9 == var_6 : - var_5 += 1 - elif var_9 == var_8 : - var_3 += 1 - elif var_5 == 0 : - var_6 , var_5 = var_9 , 1 - elif var_3 == 0 : - var_8 , var_3 = var_9 , 1 - else : - var_5 , var_3 = var_5 - 1 , var_3 - 1 - return [ var_9 for var_9 in [ var_6 , var_8 ] if var_0.count ( var_9 ) > len ( var_0 ) // 3 ] -",130,3 -878,1021.Remove Outermost Parentheses_1.py,"def removeOuterParentheses( s: str) -> str: - ans = [] - cnt = 0 - for c in s: - if c == '(': - cnt += 1 - if cnt > 1: - ans.append(c) - else: - cnt -= 1 - if cnt > 0: - ans.append(c) - return ''.join(ans)","def sample_funcname ( var_0 : str ) -> str : - var_2 = [ ] - var_4 = 0 - for var_5 in var_0 : - if var_5 == '(' : - var_4 += 1 - if var_4 > 1 : - var_2.append ( var_5 ) - else : - var_4 -= 1 - if var_4 > 0 : - var_2.append ( var_5 ) - return ''.join ( var_2 ) -",1(0,4 -879,0485.Max Consecutive Ones_1.py,"def findMaxConsecutiveOnes( nums: List[int]) -> int: - res = t = 0 - for num in nums: - if num == 1: - t += 1 - else: - res = max(res, t) - t = 0 - return max(res, t)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - for var_6 in var_0 : - if var_6 == 1 : - var_3 += 1 - else : - var_5 = max ( var_5 , var_3 ) - var_3 = 0 - return max ( var_5 , var_3 ) -",10,2 -880,0191.Number of 1 Bits_1.py,"def hammingWeight( n: int) -> int: - ans = 0 - while n: - n &= n - 1 - ans += 1 - return ans","def sample_funcname ( var_0 : int ) -> int : - var_3 = 0 - while var_0 : - var_0 &= var_0 - 1 - var_3 += 1 - return var_3 -",10,2 -881,0315.Count of Smaller Numbers After Self_1.py,"def lowbit(x): - return x & -x","def sample_funcname ( var_0 ) : - return var_0 & - var_0 -",,0 -882,0937.Reorder Data in Log Files_1.py,"def cmp(x): - a, b = x.split(' ', 1) - return (0, b, a) if b[0].isalpha() else (1,)","def sample_funcname ( var_0 ) : - var_2 , var_5 = var_0.split ( ' ' , 1 ) - return ( 0 , var_5 , var_2 ) if var_5 [ 0 ].isalpha ( ) else ( 1 , ) -",1 0,3 -883,1332.Remove Palindromic Subsequences_1.py,"def removePalindromeSub( s: str) -> int: - if not s: - return 0 - if s[::-1] == s: - return 1 - return 2","def sample_funcname ( var_0 : str ) -> int : - if not var_0 : - return 0 - if var_0 [ : : - 1 ] == var_0 : - return 1 - return 2 -",102,3 -884,0135.Candy_1.py,"def candy( ratings: List[int]) -> int: - n = len(ratings) - left = [1] * n - right = [1] * n - for i in range(1, n): - if ratings[i] > ratings[i - 1]: - left[i] = left[i - 1] + 1 - for i in range(n - 2, -1, -1): - if ratings[i] > ratings[i + 1]: - right[i] = right[i + 1] + 1 - return sum(max(a, b) for a, b in zip(left, right))","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_6 = [ 1 ] * var_4 - var_7 = [ 1 ] * var_4 - for var_9 in range ( 1 , var_4 ) : - if var_0 [ var_9 ] > var_0 [ var_9 - 1 ] : - var_6 [ var_9 ] = var_6 [ var_9 - 1 ] + 1 - for var_9 in range ( var_4 - 2 , - 1 , - 1 ) : - if var_0 [ var_9 ] > var_0 [ var_9 + 1 ] : - var_7 [ var_9 ] = var_7 [ var_9 + 1 ] + 1 - return sum ( max ( var_13 , var_14 ) for var_13 , var_14 in zip ( var_6 , var_7 ) ) -",12,2 -885,1612.Check If Two Expression Trees are Equivalent_1.py,"def calc(ans, left, right, op): - for i in range(26): - if op == '+': - ans[i] = left[i] + right[i] - else: - ans[i] = left[i] - right[i]","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - for var_6 in range ( 26 ) : - if var_3 == '+' : - var_0 [ var_6 ] = var_1 [ var_6 ] + var_2 [ var_6 ] - else : - var_0 [ var_6 ] = var_1 [ var_6 ] - var_2 [ var_6 ] -",+26,2 -886,1471.The k Strongest Values in an Array_1.py,"def getStrongest( arr: List[int], k: int) -> List[int]: - arr.sort() - m = arr[(len(arr) - 1) >> 1] - arr.sort(key=lambda x: (-abs(x - m), -x)) - return arr[:k]","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_0.sort ( ) - var_7 = var_0 [ ( len ( var_0 ) - 1 ) >> 1 ] - var_0.sort ( var_8 = lambda var_9 : ( - abs ( var_9 - var_7 ) , - var_9 ) ) - return var_0 [ : var_3 ] -",1,1 -887,2291.Maximum Profit From Trading Stocks_1.py,"def maximumProfit( present: List[int], future: List[int], budget: int) -> int: - arr = [(a, b - a) for a, b in zip(present, future) if b > a] - dp = [0] * (budget + 1) - for v, w in arr: - for j in range(budget, v - 1, -1): - dp[j] = max(dp[j], dp[j - v] + w) - return dp[-1]","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] , var_4 : int ) -> int : - var_8 = [ ( var_5 , var_6 - var_5 ) for var_5 , var_6 in zip ( var_0 , var_3 ) if var_6 > var_5 ] - var_11 = [ 0 ] * ( var_4 + 1 ) - for var_12 , var_13 in var_8 : - for var_15 in range ( var_4 , var_12 - 1 , - 1 ) : - var_11 [ var_15 ] = max ( var_11 [ var_15 ] , var_11 [ var_15 - var_12 ] + var_13 ) - return var_11 [ - 1 ] -",10,2 -889,1649.Create Sorted Array through Instructions_1.py,"def lowbit(x): - return x & -x","def sample_funcname ( var_0 ) : - return var_0 & - var_0 -",,0 -890,0874.Walking Robot Simulation_1.py,"def robotSim( commands: List[int], obstacles: List[List[int]]) -> int: - dirs = [[-1, 0], [0, 1], [1, 0], [0, -1]] - s = {(x, y) for x, y in obstacles} - ans, p = 0, 1 - x = y = 0 - for v in commands: - if v == -2: - p = (p + 3) % 4 - elif v == -1: - p = (p + 1) % 4 - else: - for _ in range(v): - nx, ny = x + dirs[p][0], y + dirs[p][1] - if (nx, ny) in s: - break - x, y = nx, ny - ans = max(ans, x * x + y * y) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ List [ int ] ] ) -> int : - var_6 = [ [ - 1 , 0 ] , [ 0 , 1 ] , [ 1 , 0 ] , [ 0 , - 1 ] ] - var_9 = { ( var_7 , var_8 ) for var_7 , var_8 in var_3 } - var_10 , var_11 = 0 , 1 - var_7 = var_8 = 0 - for var_12 in var_0 : - if var_12 == - 2 : - var_11 = ( var_11 + 3 ) % 4 - elif var_12 == - 1 : - var_11 = ( var_11 + 1 ) % 4 - else : - for var_17 in range ( var_12 ) : - var_18 , var_19 = var_7 + var_6 [ var_11 ] [ 0 ] , var_8 + var_6 [ var_11 ] [ 1 ] - if ( var_18 , var_19 ) in var_9 : - break - var_7 , var_8 = var_18 , var_19 - var_10 = max ( var_10 , var_7 * var_7 + var_8 * var_8 ) - return var_10 -",02134,5 -891,2028.Find Missing Observations_1.py,"def missingRolls( rolls: List[int], mean: int, n: int) -> List[int]: - m = len(rolls) - s = (n + m) * mean - sum(rolls) - if s > n * 6 or s < n: - return [] - ans = [s // n] * n - for i in range(s % n): - ans[i] += 1 - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int , var_4 : int ) -> List [ int ] : - var_6 = len ( var_0 ) - var_8 = ( var_4 + var_6 ) * var_3 - sum ( var_0 ) - if var_8 > var_4 * 6 or var_8 < var_4 : - return [ ] - var_10 = [ var_8 // var_4 ] * var_4 - for var_12 in range ( var_8 % var_4 ) : - var_10 [ var_12 ] += 1 - return var_10 -",16,2 -892,0342.Power of Four_1.py,"def isPowerOfFour( n: int) -> bool: - return n > 0 and (n & (n - 1)) == 0 and (n & 0xAAAAAAAA) == 0","def sample_funcname ( var_0 : int ) -> bool : - return var_0 > 0 and ( var_0 & ( var_0 - 1 ) ) == 0 and ( var_0 & 0xAAAAAAAA ) == 0 -",100xAAAAAAAA,3 -893,1037.Valid Boomerang_1.py,"def isBoomerang( points: List[List[int]]) -> bool: - (x1, y1), (x2, y2), (x3, y3) = points - return (y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1)","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> bool : - ( var_4 , var_5 ) , ( var_6 , var_7 ) , ( var_8 , var_9 ) = var_0 - return ( var_7 - var_5 ) * ( var_8 - var_6 ) != ( var_9 - var_7 ) * ( var_6 - var_4 ) -",,0 -894,1838.Frequency of the Most Frequent Element_1.py,"def maxFrequency( nums: List[int], k: int) -> int: - nums.sort() - ans = 1 - window = 0 - l, r, n = 0, 1, len(nums) - while r < n: - window += (nums[r] - nums[r - 1]) * (r - l) - r += 1 - while window > k: - window -= nums[r - 1] - nums[l] - l += 1 - ans = max(ans, r - l) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_0.sort ( ) - var_6 = 1 - var_8 = 0 - var_9 , var_10 , var_12 = 0 , 1 , len ( var_0 ) - while var_10 < var_12 : - var_8 += ( var_0 [ var_10 ] - var_0 [ var_10 - 1 ] ) * ( var_10 - var_9 ) - var_10 += 1 - while var_8 > var_3 : - var_8 -= var_0 [ var_10 - 1 ] - var_0 [ var_9 ] - var_9 += 1 - var_6 = max ( var_6 , var_10 - var_9 ) - return var_6 -",10,2 -895,1389.Create Target Array in the Given Order_1.py,"def createTargetArray( nums: List[int], index: List[int]) -> List[int]: - target = [] - for i in range(len(nums)): - target.insert(index[i], nums[i]) - return target","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> List [ int ] : - var_4 = [ ] - for var_7 in range ( len ( var_0 ) ) : - var_4.insert ( var_3 [ var_7 ] , var_0 [ var_7 ] ) - return var_4 -",,0 -896,0661.Image Smoother_1.py,"def imageSmoother( img: List[List[int]]) -> List[List[int]]: - m, n = len(img), len(img[0]) - ans = [[0] * n for _ in range(m)] - for i in range(m): - for j in range(n): - s = cnt = 0 - for x in range(i - 1, i + 2): - for y in range(j - 1, j + 2): - if 0 <= x < m and 0 <= y < n: - cnt += 1 - s += img[x][y] - ans[i][j] = s // cnt - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ List [ int ] ] : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_9 = [ [ 0 ] * var_6 for var_7 in range ( var_4 ) ] - for var_10 in range ( var_4 ) : - for var_11 in range ( var_6 ) : - var_13 = var_12 = 0 - for var_16 in range ( var_10 - 1 , var_10 + 2 ) : - for var_17 in range ( var_11 - 1 , var_11 + 2 ) : - if 0 <= var_16 < var_4 and 0 <= var_17 < var_6 : - var_12 += 1 - var_13 += var_0 [ var_16 ] [ var_17 ] - var_9 [ var_10 ] [ var_11 ] = var_13 // var_12 - return var_9 -",102,3 -897,0493.Reverse Pairs_1.py,"def lowbit(x): - return x & -x","def sample_funcname ( var_0 ) : - return var_0 & - var_0 -",,0 -898,0629.K Inverse Pairs Array_1.py,"def kInversePairs( n: int, k: int) -> int: - mod = 1000000007 - dp, pre = [0] * (k + 1), [0] * (k + 2) - for i in range(1, n + 1): - dp[0] = 1 - - for j in range(1, k + 1): - dp[j] = (pre[j + 1] - pre[max(0, j - i + 1)] + mod) % mod - - for j in range(1, k + 2): - pre[j] = (pre[j - 1] + dp[j - 1]) % mod - - return dp[k]","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_4 = 1000000007 - var_7 , var_9 = [ 0 ] * ( var_2 + 1 ) , [ 0 ] * ( var_2 + 2 ) - for var_11 in range ( 1 , var_0 + 1 ) : - var_7 [ 0 ] = 1 - for var_12 in range ( 1 , var_2 + 1 ) : - var_7 [ var_12 ] = ( var_9 [ var_12 + 1 ] - var_9 [ max ( 0 , var_12 - var_11 + 1 ) ] + var_4 ) % var_4 - for var_12 in range ( 1 , var_2 + 2 ) : - var_9 [ var_12 ] = ( var_9 [ var_12 - 1 ] + var_7 [ var_12 - 1 ] ) % var_4 - return var_7 [ var_2 ] -",1021000000007,4 -899,0361.Bomb Enemy_1.py,"def maxKilledEnemies( grid: List[List[str]]) -> int: - m, n = len(grid), len(grid[0]) - g = [[0] * n for _ in range(m)] - for i in range(m): - t = 0 - for j in range(n): - if grid[i][j] == 'W': - t = 0 - elif grid[i][j] == 'E': - t += 1 - g[i][j] += t - t = 0 - for j in range(n - 1, -1, -1): - if grid[i][j] == 'W': - t = 0 - elif grid[i][j] == 'E': - t += 1 - g[i][j] += t - for j in range(n): - t = 0 - for i in range(m): - if grid[i][j] == 'W': - t = 0 - elif grid[i][j] == 'E': - t += 1 - g[i][j] += t - t = 0 - for i in range(m - 1, -1, -1): - if grid[i][j] == 'W': - t = 0 - elif grid[i][j] == 'E': - t += 1 - g[i][j] += t - return max( - [g[i][j] for i in range(m) for j in range(n) if grid[i][j] == '0'], - default=0, - )","def sample_funcname ( var_0 : List [ List [ str ] ] ) -> int : - var_5 , var_7 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_10 = [ [ 0 ] * var_7 for var_8 in range ( var_5 ) ] - for var_11 in range ( var_5 ) : - var_12 = 0 - for var_13 in range ( var_7 ) : - if var_0 [ var_11 ] [ var_13 ] == 'W' : - var_12 = 0 - elif var_0 [ var_11 ] [ var_13 ] == 'E' : - var_12 += 1 - var_10 [ var_11 ] [ var_13 ] += var_12 - var_12 = 0 - for var_13 in range ( var_7 - 1 , - 1 , - 1 ) : - if var_0 [ var_11 ] [ var_13 ] == 'W' : - var_12 = 0 - elif var_0 [ var_11 ] [ var_13 ] == 'E' : - var_12 += 1 - var_10 [ var_11 ] [ var_13 ] += var_12 - for var_13 in range ( var_7 ) : - var_12 = 0 - for var_11 in range ( var_5 ) : - if var_0 [ var_11 ] [ var_13 ] == 'W' : - var_12 = 0 - elif var_0 [ var_11 ] [ var_13 ] == 'E' : - var_12 += 1 - var_10 [ var_11 ] [ var_13 ] += var_12 - var_12 = 0 - for var_11 in range ( var_5 - 1 , - 1 , - 1 ) : - if var_0 [ var_11 ] [ var_13 ] == 'W' : - var_12 = 0 - elif var_0 [ var_11 ] [ var_13 ] == 'E' : - var_12 += 1 - var_10 [ var_11 ] [ var_13 ] += var_12 - return max ( [ var_10 [ var_11 ] [ var_13 ] for var_11 in range ( var_5 ) for var_13 in range ( var_7 ) if var_0 [ var_11 ] [ var_13 ] == '0' ] , var_19 = 0 , ) -",0E01W,5 -900,1710.Maximum Units on a Truck_1.py,"def maximumUnits( boxTypes: List[List[int]], truckSize: int) -> int: - boxTypes.sort(key=lambda x: -x[1]) - ans = 0 - for a, b in boxTypes: - a = min(a, truckSize) - truckSize -= a - ans += a * b - if truckSize == 0: - break - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : int ) -> int : - var_0.sort ( var_5 = lambda var_6 : - var_6 [ 1 ] ) - var_9 = 0 - for var_10 , var_11 in var_0 : - var_10 = min ( var_10 , var_3 ) - var_3 -= var_10 - var_9 += var_10 * var_11 - if var_3 == 0 : - break - return var_9 -",10,2 -901,2365.Task Scheduler II_1.py,"def taskSchedulerII( tasks: List[int], space: int) -> int: - mp = {} - ans = 0 - for v in tasks: - ans += 1 - ans = max(ans, mp.get(v, 0)) - mp[v] = ans + space + 1 - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_4 = { } - var_6 = 0 - for var_7 in var_0 : - var_6 += 1 - var_6 = max ( var_6 , var_4.get ( var_7 , 0 ) ) - var_4 [ var_7 ] = var_6 + var_3 + 1 - return var_6 -",10,2 -902,0532.K-diff Pairs in an Array_1.py,"def findPairs( nums: List[int], k: int) -> int: - vis, ans = set(), set() - for v in nums: - if v - k in vis: - ans.add(v - k) - if v + k in vis: - ans.add(v) - vis.add(v) - return len(ans)","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_6 = set ( ) , set ( ) - for var_7 in var_0 : - if var_7 - var_3 in var_5 : - var_6.add ( var_7 - var_3 ) - if var_7 + var_3 in var_5 : - var_6.add ( var_7 ) - var_5.add ( var_7 ) - return len ( var_6 ) -",,0 -903,0172.Factorial Trailing Zeroes_1.py,"def trailingZeroes( n: int) -> int: - ans = 0 - while n: - n //= 5 - ans += n - return ans","def sample_funcname ( var_0 : int ) -> int : - var_3 = 0 - while var_0 : - var_0 //= 5 - var_3 += var_0 - return var_3 -",50,2 -904,2371.Minimize Maximum Value in a Grid_1.py,"def minScore( grid: List[List[int]]) -> List[List[int]]: - m, n = len(grid), len(grid[0]) - nums = [(v, i, j) for i, row in enumerate(grid) for j, v in enumerate(row)] - nums.sort() - row_max = [0] * m - col_max = [0] * n - ans = [[0] * n for _ in range(m)] - for _, i, j in nums: - ans[i][j] = max(row_max[i], col_max[j]) + 1 - row_max[i] = col_max[j] = ans[i][j] - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ List [ int ] ] : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_12 = [ ( var_7 , var_8 , var_9 ) for var_8 , var_10 in enumerate ( var_0 ) for var_9 , var_7 in enumerate ( var_10 ) ] - var_12.sort ( ) - var_14 = [ 0 ] * var_4 - var_15 = [ 0 ] * var_6 - var_18 = [ [ 0 ] * var_6 for var_16 in range ( var_4 ) ] - for var_16 , var_8 , var_9 in var_12 : - var_18 [ var_8 ] [ var_9 ] = max ( var_14 [ var_8 ] , var_15 [ var_9 ] ) + 1 - var_14 [ var_8 ] = var_15 [ var_9 ] = var_18 [ var_8 ] [ var_9 ] - return var_18 -",10,2 -905,0134.Gas Station_1.py,"def canCompleteCircuit( gas: List[int], cost: List[int]) -> int: - n = len(gas) - i = j = n - 1 - cnt = s = 0 - while cnt < n: - s += gas[j] - cost[j] - cnt += 1 - j = (j + 1) % n - while s < 0 and cnt < n: - i -= 1 - s += gas[i] - cost[i] - cnt += 1 - return -1 if s < 0 else i","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_5 = len ( var_0 ) - var_8 = var_6 = var_5 - 1 - var_11 = var_9 = 0 - while var_11 < var_5 : - var_9 += var_0 [ var_6 ] - var_3 [ var_6 ] - var_11 += 1 - var_6 = ( var_6 + 1 ) % var_5 - while var_9 < 0 and var_11 < var_5 : - var_8 -= 1 - var_9 += var_0 [ var_8 ] - var_3 [ var_8 ] - var_11 += 1 - return - 1 if var_9 < 0 else var_8 -",10,2 -906,0699.Falling Squares_1.py,"def pushup( node): - node.v = max(node.left.v, node.right.v)","def sample_funcname ( var_0 ) : - var_0.v = max ( var_0.var_2.v , var_0.var_4.v ) -",,0 -907,2091.Removing Minimum and Maximum From Array_1.py,"def minimumDeletions( nums: List[int]) -> int: - mi = mx = 0 - for i, num in enumerate(nums): - if num < nums[mi]: - mi = i - if num > nums[mx]: - mx = i - if mi > mx: - mi, mx = mx, mi - return min(mx + 1, len(nums) - mi, mi + 1 + len(nums) - mx)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - for var_7 , var_8 in enumerate ( var_0 ) : - if var_8 < var_0 [ var_5 ] : - var_5 = var_7 - if var_8 > var_0 [ var_3 ] : - var_3 = var_7 - if var_5 > var_3 : - var_5 , var_3 = var_3 , var_5 - return min ( var_3 + 1 , len ( var_0 ) - var_5 , var_5 + 1 + len ( var_0 ) - var_3 ) -",10,2 -908,2334.Subarray With Elements Greater Than Varying Threshold_1.py,"def validSubarraySize( nums: List[int], threshold: int) -> int: - n = len(nums) - left = [-1] * n - right = [n] * n - stk = [] - for i, v in enumerate(nums): - while stk and nums[stk[-1]] >= v: - stk.pop() - if stk: - left[i] = stk[-1] - stk.append(i) - stk = [] - for i in range(n - 1, -1, -1): - while stk and nums[stk[-1]] >= nums[i]: - stk.pop() - if stk: - right[i] = stk[-1] - stk.append(i) - for i, v in enumerate(nums): - k = right[i] - left[i] - 1 - if v > threshold // k: - return k - return -1","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 = len ( var_0 ) - var_7 = [ - 1 ] * var_5 - var_8 = [ var_5 ] * var_5 - var_9 = [ ] - for var_11 , var_12 in enumerate ( var_0 ) : - while var_9 and var_0 [ var_9 [ - 1 ] ] >= var_12 : - var_9.pop ( ) - if var_9 : - var_7 [ var_11 ] = var_9 [ - 1 ] - var_9.append ( var_11 ) - var_9 = [ ] - for var_11 in range ( var_5 - 1 , - 1 , - 1 ) : - while var_9 and var_0 [ var_9 [ - 1 ] ] >= var_0 [ var_11 ] : - var_9.pop ( ) - if var_9 : - var_8 [ var_11 ] = var_9 [ - 1 ] - var_9.append ( var_11 ) - for var_11 , var_12 in enumerate ( var_0 ) : - var_16 = var_8 [ var_11 ] - var_7 [ var_11 ] - 1 - if var_12 > var_3 // var_16 : - return var_16 - return - 1 -",1,1 -909,2240.Number of Ways to Buy Pens and Pencils_1.py,"def waysToBuyPensPencils( total: int, cost1: int, cost2: int) -> int: - ans = 0 - for x in range(total // cost1 + 1): - v = total - x * cost1 - ans += v // cost2 + 1 - return ans","def sample_funcname ( var_0 : int , var_2 : int , var_3 : int ) -> int : - var_5 = 0 - for var_8 in range ( var_0 // var_2 + 1 ) : - var_9 = var_0 - var_8 * var_2 - var_5 += var_9 // var_3 + 1 - return var_5 -",10,2 -910,2063.Vowels of All Substrings_1.py,"def countVowels( word: str) -> int: - n = len(word) - return sum((i + 1) * (n - i) for i, c in enumerate(word) if c in 'aeiou')","def sample_funcname ( var_0 : str ) -> int : - var_4 = len ( var_0 ) - return sum ( ( var_6 + 1 ) * ( var_4 - var_6 ) for var_6 , var_9 in enumerate ( var_0 ) if var_9 in 'aeiou' ) -",aeiou1,2 -911,0890.Find and Replace Pattern_1.py,"def match(s, t): - m1, m2 = [0] * 128, [0] * 128 - for i, (a, b) in enumerate(zip(s, t), 1): - if m1[ord(a)] != m2[ord(b)]: - return False - m1[ord(a)] = m2[ord(b)] = i - return True","def sample_funcname ( var_0 , var_1 ) : - var_4 , var_5 = [ 0 ] * 128 , [ 0 ] * 128 - for var_7 , ( var_10 , var_11 ) in enumerate ( zip ( var_0 , var_1 ) , 1 ) : - if var_4 [ ord ( var_10 ) ] != var_5 [ ord ( var_11 ) ] : - return False - var_4 [ ord ( var_10 ) ] = var_5 [ ord ( var_11 ) ] = var_7 - return True -",12801,3 -912,0979.Distribute Coins in Binary Tree_1.py,"def dfs(root): - nonlocal ans - if root is None: - return 0 - left, right = dfs(root.left), dfs(root.right) - ans += abs(left) + abs(right) - return left + right + root.val - 1","def sample_funcname ( var_1 ) : - nonlocal var_2 - if var_1 is None : - return 0 - left , right = var_0 ( var_1.left ) , var_0 ( var_1.right ) - var_2 += abs ( left ) + abs ( right ) - return left + right + var_1.val - 1 -",10None,3 -913,0870.Advantage Shuffle_1.py,"def advantageCount( nums1: List[int], nums2: List[int]) -> List[int]: - nums1.sort() - t = [(v, i) for i, v in enumerate(nums2)] - t.sort() - n = len(nums2) - ans = [0] * n - i, j = 0, n - 1 - for v in nums1: - if v <= t[i][0]: - ans[t[j][1]] = v - j -= 1 - else: - ans[t[i][1]] = v - i += 1 - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> List [ int ] : - var_0.sort ( ) - var_8 = [ ( var_5 , var_6 ) for var_6 , var_5 in enumerate ( var_3 ) ] - var_8.sort ( ) - var_10 = len ( var_3 ) - var_12 = [ 0 ] * var_10 - var_6 , var_14 = 0 , var_10 - 1 - for var_5 in var_0 : - if var_5 <= var_8 [ var_6 ] [ 0 ] : - var_12 [ var_8 [ var_14 ] [ 1 ] ] = var_5 - var_14 -= 1 - else : - var_12 [ var_8 [ var_6 ] [ 1 ] ] = var_5 - var_6 += 1 - return var_12 -",10,2 -914,1433.Check If a String Can Break Another String_1.py,"def checkIfCanBreak( s1: str, s2: str) -> bool: - cs1 = sorted(s1) - cs2 = sorted(s2) - return all(a >= b for a, b in zip(cs1, cs2)) or all( - a <= b for a, b in zip(cs1, cs2) - )","def sample_funcname ( var_0 : str , var_2 : str ) -> bool : - var_5 = sorted ( var_0 ) - var_6 = sorted ( var_2 ) - return all ( var_8 >= var_9 for var_8 , var_9 in zip ( var_5 , var_6 ) ) or all ( var_8 <= var_9 for var_8 , var_9 in zip ( var_5 , var_6 ) ) -",,0 -915,0089.Gray Code_1.py,"def grayCode( n: int) -> List[int]: - return [i ^ (i >> 1) for i in range(1 << n)]","def sample_funcname ( var_0 : int ) -> List [ int ] : - return [ var_3 ^ ( var_3 >> 1 ) for var_3 in range ( 1 << var_0 ) ] -",1,1 -916,0349.Intersection of Two Arrays_1.py,"def intersection( nums1: List[int], nums2: List[int]) -> List[int]: - s = set(nums1) - res = set() - for num in nums2: - if num in s: - res.add(num) - return list(res)","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> List [ int ] : - var_5 = set ( var_0 ) - var_6 = set ( ) - for var_7 in var_3 : - if var_7 in var_5 : - var_6.add ( var_7 ) - return list ( var_6 ) -",,0 -917,0893.Groups of Special-Equivalent Strings_1.py,"def numSpecialEquivGroups( words: List[str]) -> int: - s = {''.join(sorted(word[::2]) + sorted(word[1::2])) for word in words} - return len(s)","def sample_funcname ( var_0 : List [ str ] ) -> int : - var_10 = { ''.join ( sorted ( var_7 [ : : 2 ] ) + sorted ( var_7 [ 1 : : 2 ] ) ) for var_7 in var_0 } - return len ( var_10 ) -",12,3 -918,0084.Largest Rectangle in Histogram_1.py,"def largestRectangleArea( heights: List[int]) -> int: - n = len(heights) - stk = [] - left = [-1] * n - right = [n] * n - for i, h in enumerate(heights): - while stk and heights[stk[-1]] >= h: - right[stk[-1]] = i - stk.pop() - if stk: - left[i] = stk[-1] - stk.append(i) - return max(h * (right[i] - left[i] - 1) for i, h in enumerate(heights))","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_5 = [ ] - var_7 = [ - 1 ] * var_4 - var_8 = [ var_4 ] * var_4 - for var_10 , var_11 in enumerate ( var_0 ) : - while var_5 and var_0 [ var_5 [ - 1 ] ] >= var_11 : - var_8 [ var_5 [ - 1 ] ] = var_10 - var_5.pop ( ) - if var_5 : - var_7 [ var_10 ] = var_5 [ - 1 ] - var_5.append ( var_10 ) - return max ( var_11 * ( var_8 [ var_10 ] - var_7 [ var_10 ] - 1 ) for var_10 , var_11 in enumerate ( var_0 ) ) -",1,1 -919,0169.Majority Element_1.py,"def majorityElement( nums: List[int]) -> int: - cnt = m = 0 - for v in nums: - if cnt == 0: - m, cnt = v, 1 - else: - cnt += 1 if m == v else -1 - return m","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - for var_6 in var_0 : - if var_5 == 0 : - var_3 , var_5 = var_6 , 1 - else : - var_5 += 1 if var_3 == var_6 else - 1 - return var_3 -",10,2 -920,1756.Design Most Recently Used Queue_1.py,"def lowbit(x): - return x & -x","def sample_funcname ( var_0 ) : - return var_0 & - var_0 -",,0 -921,0953.Verifying an Alien Dictionary_1.py,"def isAlienSorted( words: List[str], order: str) -> bool: - m = {c: i for i, c in enumerate(order)} - for i in range(20): - prev = -1 - valid = True - for x in words: - curr = -1 if i >= len(x) else m[x[i]] - if prev > curr: - return False - if prev == curr: - valid = False - prev = curr - if valid: - return True - return True","def sample_funcname ( var_0 : List [ str ] , var_3 : str ) -> bool : - var_8 = { var_5 : var_6 for var_6 , var_5 in enumerate ( var_3 ) } - for var_6 in range ( 20 ) : - var_12 = - 1 - var_14 = True - for var_15 in var_0 : - var_17 = - 1 if var_6 >= len ( var_15 ) else var_8 [ var_15 [ var_6 ] ] - if var_12 > var_17 : - return False - if var_12 == var_17 : - var_14 = False - var_12 = var_17 - if var_14 : - return True - return True -",120,2 -922,0015.3Sum_1.py,"def threeSum( nums: List[int]) -> List[List[int]]: - n, res = len(nums), [] - if n < 3: - return res - nums.sort() - for i in range(n - 2): - if nums[i] > 0: - break - if i > 0 and nums[i] == nums[i - 1]: - continue - j, k = i + 1, n - 1 - while j < k: - if nums[i] + nums[j] + nums[k] == 0: - res.append([nums[i], nums[j], nums[k]]) - j += 1 - k -= 1 - while j < n and nums[j] == nums[j - 1]: - j += 1 - while k > i and nums[k] == nums[k + 1]: - k -= 1 - elif nums[i] + nums[j] + nums[k] < 0: - j += 1 - else: - k -= 1 - return res","def sample_funcname ( var_0 : List [ int ] ) -> List [ List [ int ] ] : - var_4 , var_5 = len ( var_0 ) , [ ] - if var_4 < 3 : - return var_5 - var_0.sort ( ) - for var_10 in range ( var_4 - 2 ) : - if var_0 [ var_10 ] > 0 : - break - if var_10 > 0 and var_0 [ var_10 ] == var_0 [ var_10 - 1 ] : - continue - var_13 , var_14 = var_10 + 1 , var_4 - 1 - while var_13 < var_14 : - if var_0 [ var_10 ] + var_0 [ var_13 ] + var_0 [ var_14 ] == 0 : - var_5.append ( [ var_0 [ var_10 ] , var_0 [ var_13 ] , var_0 [ var_14 ] ] ) - var_13 += 1 - var_14 -= 1 - while var_13 < var_4 and var_0 [ var_13 ] == var_0 [ var_13 - 1 ] : - var_13 += 1 - while var_14 > var_10 and var_0 [ var_14 ] == var_0 [ var_14 + 1 ] : - var_14 -= 1 - elif var_0 [ var_10 ] + var_0 [ var_13 ] + var_0 [ var_14 ] < 0 : - var_13 += 1 - else : - var_14 -= 1 - return var_5 -",1302,4 -923,0606.Construct String from Binary Tree_1.py,"def dfs(root): - if root is None: - return '' - if root.left is None and root.right is None: - return str(root.val) - if root.right is None: - return f'{root.val}({dfs(root.left)})' - return f'{root.val}({dfs(root.left)})({dfs(root.right)})'","def sample_funcname ( var_0 ) : - if var_0 is None : - return '' - if var_0.left is None and var_0.right is None : - return str ( var_0.val ) - if var_0.right is None : - return f'{var_0.val}({dfs(var_0.left)})' - return f'{var_0.val}({dfs(var_0.left)})({dfs(var_0.right)})' -",f{var_0.val}({dfs(var_0.left)})Nonef{var_0.val}({dfs(var_0.left)})({dfs(var_0.right)}),4 -924,1013.Partition Array Into Three Parts With Equal Sum_1.py,"def canThreePartsEqualSum( arr: List[int]) -> bool: - s = sum(arr) - if s % 3 != 0: - return False - i, j = 0, len(arr) - 1 - a = b = 0 - while i < len(arr): - a += arr[i] - if a == s // 3: - break - i += 1 - while ~j: - b += arr[j] - if b == s // 3: - break - j -= 1 - return i < j - 1","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_5 = sum ( var_0 ) - if var_5 % 3 != 0 : - return False - var_9 , var_12 = 0 , len ( var_0 ) - 1 - var_14 = var_13 = 0 - while var_9 < len ( var_0 ) : - var_14 += var_0 [ var_9 ] - if var_14 == var_5 // 3 : - break - var_9 += 1 - while ~ var_12 : - var_13 += var_0 [ var_12 ] - if var_13 == var_5 // 3 : - break - var_12 -= 1 - return var_9 < var_12 - 1 -",130,3 -925,0944.Delete Columns to Make Sorted_1.py,"def minDeletionSize( strs: List[str]) -> int: - m, n = len(strs[0]), len(strs) - ans = 0 - for j in range(m): - for i in range(1, n): - if strs[i][j] < strs[i - 1][j]: - ans += 1 - break - return ans","def sample_funcname ( var_0 : List [ str ] ) -> int : - var_6 , var_7 = len ( var_0 [ 0 ] ) , len ( var_0 ) - var_8 = 0 - for var_10 in range ( var_6 ) : - for var_12 in range ( 1 , var_7 ) : - if var_0 [ var_12 ] [ var_10 ] < var_0 [ var_12 - 1 ] [ var_10 ] : - var_8 += 1 - break - return var_8 -",10,2 -926,2355.Maximum Number of Books You Can Take_1.py,"def maximumBooks( books: List[int]) -> int: - nums = [v - i for i, v in enumerate(books)] - n = len(nums) - left = [-1] * n - stk = [] - for i, v in enumerate(nums): - while stk and nums[stk[-1]] >= v: - stk.pop() - if stk: - left[i] = stk[-1] - stk.append(i) - ans = 0 - dp = [0] * n - dp[0] = books[0] - for i, v in enumerate(books): - j = left[i] - cnt = min(v, i - j) - u = v - cnt + 1 - s = (u + v) * cnt // 2 - dp[i] = s + (0 if j == -1 else dp[j]) - ans = max(ans, dp[i]) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_6 = [ var_3 - var_4 for var_4 , var_3 in enumerate ( var_0 ) ] - var_8 = len ( var_6 ) - var_10 = [ - 1 ] * var_8 - var_11 = [ ] - for var_4 , var_3 in enumerate ( var_6 ) : - while var_11 and var_6 [ var_11 [ - 1 ] ] >= var_3 : - var_11.pop ( ) - if var_11 : - var_10 [ var_4 ] = var_11 [ - 1 ] - var_11.append ( var_4 ) - var_15 = 0 - var_16 = [ 0 ] * var_8 - var_16 [ 0 ] = var_0 [ 0 ] - for var_4 , var_3 in enumerate ( var_0 ) : - var_17 = var_10 [ var_4 ] - var_19 = min ( var_3 , var_4 - var_17 ) - var_20 = var_3 - var_19 + 1 - var_22 = ( var_20 + var_3 ) * var_19 // 2 - var_16 [ var_4 ] = var_22 + ( 0 if var_17 == - 1 else var_16 [ var_17 ] ) - var_15 = max ( var_15 , var_16 [ var_4 ] ) - return var_15 -",102,3 -927,0056.Merge Intervals_1.py,"def merge( intervals: List[List[int]]) -> List[List[int]]: - intervals.sort() - ans = [] - st, ed = intervals[0] - for s, e in intervals[1:]: - if ed < s: - ans.append([st, ed]) - st, ed = s, e - else: - ed = max(ed, e) - ans.append([st, ed]) - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ List [ int ] ] : - var_0.sort ( ) - var_4 = [ ] - var_6 , var_7 = var_0 [ 0 ] - for var_9 , var_10 in var_0 [ 1 : ] : - if var_7 < var_9 : - var_4.append ( [ var_6 , var_7 ] ) - var_6 , var_7 = var_9 , var_10 - else : - var_7 = max ( var_7 , var_10 ) - var_4.append ( [ var_6 , var_7 ] ) - return var_4 -",10,2 -928,0058.Length of Last Word_1.py,"def lengthOfLastWord( s: str) -> int: - last_word_length = 0 - meet_word = False - for i in range(len(s) - 1, -1, -1): - ch = ord(s[i]) - if ch >= 65 and ch <= 122: - meet_word = True - last_word_length += 1 - elif meet_word: - break - return last_word_length","def sample_funcname ( var_0 : str ) -> int : - var_4 = 0 - var_6 = False - for var_10 in range ( len ( var_0 ) - 1 , - 1 , - 1 ) : - var_12 = ord ( var_0 [ var_10 ] ) - if var_12 >= 65 and var_12 <= 122 : - var_6 = True - var_4 += 1 - elif var_6 : - break - return var_4 -",1065122,4 -929,0205.Isomorphic Strings_1.py,"def isIsomorphic( s: str, t: str) -> bool: - d1, d2 = [0] * 256, [0] * 256 - for i, (a, b) in enumerate(zip(s, t)): - a, b = ord(a), ord(b) - if d1[a] != d2[b]: - return False - d1[a] = d2[b] = i + 1 - return True","def sample_funcname ( var_0 : str , var_2 : str ) -> bool : - var_6 , var_7 = [ 0 ] * 256 , [ 0 ] * 256 - for var_9 , ( var_11 , var_12 ) in enumerate ( zip ( var_0 , var_2 ) ) : - var_11 , var_12 = ord ( var_11 ) , ord ( var_12 ) - if var_6 [ var_11 ] != var_7 [ var_12 ] : - return False - var_6 [ var_11 ] = var_7 [ var_12 ] = var_9 + 1 - return True -",10256,3 -930,1143.Longest Common Subsequence_1.py,"def longestCommonSubsequence( text1: str, text2: str) -> int: - m, n = len(text1), len(text2) - dp = [[0] * (n + 1) for _ in range(m + 1)] - for i in range(1, m + 1): - for j in range(1, n + 1): - if text1[i - 1] == text2[j - 1]: - dp[i][j] = dp[i - 1][j - 1] + 1 - else: - dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - return dp[-1][-1]","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - var_5 , var_6 = len ( var_0 ) , len ( var_2 ) - var_11 = [ [ 0 ] * ( var_6 + 1 ) for var_9 in range ( var_5 + 1 ) ] - for var_12 in range ( 1 , var_5 + 1 ) : - for var_13 in range ( 1 , var_6 + 1 ) : - if var_0 [ var_12 - 1 ] == var_2 [ var_13 - 1 ] : - var_11 [ var_12 ] [ var_13 ] = var_11 [ var_12 - 1 ] [ var_13 - 1 ] + 1 - else : - var_11 [ var_12 ] [ var_13 ] = max ( var_11 [ var_12 - 1 ] [ var_13 ] , var_11 [ var_12 ] [ var_13 - 1 ] ) - return var_11 [ - 1 ] [ - 1 ] -",10,2 -931,1310.XOR Queries of a Subarray_1.py,"def xorQueries( arr: List[int], queries: List[List[int]]) -> List[int]: - xors = [0] - for v in arr: - xors.append(xors[-1] ^ v) - return [xors[l] ^ xors[r + 1] for l, r in queries]","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ List [ int ] ] ) -> List [ int ] : - var_5 = [ 0 ] - for var_6 in var_0 : - var_5.append ( var_5 [ - 1 ] ^ var_6 ) - return [ var_5 [ var_9 ] ^ var_5 [ var_10 + 1 ] for var_9 , var_10 in var_3 ] -",10,2 -932,0153.Find Minimum in Rotated Sorted Array_1.py,"def findMin( nums: List[int]) -> int: - if nums[0] <= nums[-1]: - return nums[0] - left, right = 0, len(nums) - 1 - while left < right: - mid = (left + right) >> 1 - if nums[0] <= nums[mid]: - left = mid + 1 - else: - right = mid - return nums[left]","def sample_funcname ( var_0 : List [ int ] ) -> int : - if var_0 [ 0 ] <= var_0 [ - 1 ] : - return var_0 [ 0 ] - var_5 , var_7 = 0 , len ( var_0 ) - 1 - while var_5 < var_7 : - var_8 = ( var_5 + var_7 ) >> 1 - if var_0 [ 0 ] <= var_0 [ var_8 ] : - var_5 = var_8 + 1 - else : - var_7 = var_8 - return var_0 [ var_5 ] -",10,2 -933,0045.Jump Game II_1.py,"def jump( nums: List[int]) -> int: - end = mx = steps = 0 - for i, num in enumerate(nums[:-1]): - mx = max(mx, i + num) - if i == end: - end = mx - steps += 1 - return steps","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_6 = var_3 = var_4 = 0 - for var_8 , var_10 in enumerate ( var_0 [ : - 1 ] ) : - var_3 = max ( var_3 , var_8 + var_10 ) - if var_8 == var_6 : - var_6 = var_3 - var_4 += 1 - return var_4 -",10,2 -934,2022.Convert 1D Array Into 2D Array_1.py,"def construct2DArray( original: List[int], m: int, n: int) -> List[List[int]]: - if m * n != len(original): - return [] - return [original[i : i + n] for i in range(0, m * n, n)]","def sample_funcname ( var_0 : List [ int ] , var_3 : int , var_4 : int ) -> List [ List [ int ] ] : - if var_3 * var_4 != len ( var_0 ) : - return [ ] - return [ var_0 [ var_6 : var_6 + var_4 ] for var_6 in range ( 0 , var_3 * var_4 , var_4 ) ] -",0,1 -935,0111.Minimum Depth of Binary Tree_1.py,"def dfs(root): - if root is None: - return 0 - if root.left is None: - return 1 + dfs(root.right) - if root.right is None: - return 1 + dfs(root.left) - return 1 + min(dfs(root.left), dfs(root.right))","def sample_funcname ( var_1 ) : - if var_1 is None : - return 0 - if var_1.left is None : - return 1 + var_0 ( var_1.right ) - if var_1.right is None : - return 1 + var_0 ( var_1.left ) - return 1 + min ( var_0 ( var_1.left ) , var_0 ( var_1.right ) ) -",10None,3 -936,0941.Valid Mountain Array_1.py,"def validMountainArray( arr: List[int]) -> bool: - n = len(arr) - if n < 3: - return False - l, r = 0, n - 1 - while l + 1 < n - 1 and arr[l] < arr[l + 1]: - l += 1 - while r - 1 > 0 and arr[r] < arr[r - 1]: - r -= 1 - return l == r","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_5 = len ( var_0 ) - if var_5 < 3 : - return False - var_9 , var_11 = 0 , var_5 - 1 - while var_9 + 1 < var_5 - 1 and var_0 [ var_9 ] < var_0 [ var_9 + 1 ] : - var_9 += 1 - while var_11 - 1 > 0 and var_0 [ var_11 ] < var_0 [ var_11 - 1 ] : - var_11 -= 1 - return var_9 == var_11 -",130,3 -937,0068.Text Justification_1.py,"def partition(n, cnt): - res = [] - base, mod = divmod(n, cnt) - i = j = 0 - while i < cnt: - t = [' ' * base] - if j < mod: - t.append(' ') - res.append(''.join(t)) - i, j = i + 1, j + 1 - return res","def sample_funcname ( var_0 , var_1 ) : - var_2 = [ ] - var_4 , var_5 = divmod ( var_0 , var_1 ) - var_8 = var_6 = 0 - while var_8 < var_1 : - var_10 = [ '' * var_4 ] - if var_6 < var_5 : - var_10.append ( '' ) - var_2.append ( ''.join ( var_10 ) ) - var_8 , var_6 = var_8 + 1 , var_6 + 1 - return var_2 -",10,3 -938,0033.Search in Rotated Sorted Array_1.py,"def search( nums: List[int], target: int) -> int: - n = len(nums) - left, right = 0, n - 1 - while left < right: - mid = (left + right) >> 1 - if nums[0] <= nums[mid]: - if nums[0] <= target <= nums[mid]: - right = mid - else: - left = mid + 1 - else: - if nums[mid] < target <= nums[n - 1]: - left = mid + 1 - else: - right = mid - return left if nums[left] == target else -1","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 = len ( var_0 ) - var_7 , var_9 = 0 , var_5 - 1 - while var_7 < var_9 : - var_10 = ( var_7 + var_9 ) >> 1 - if var_0 [ 0 ] <= var_0 [ var_10 ] : - if var_0 [ 0 ] <= var_3 <= var_0 [ var_10 ] : - var_9 = var_10 - else : - var_7 = var_10 + 1 - else : - if var_0 [ var_10 ] < var_3 <= var_0 [ var_5 - 1 ] : - var_7 = var_10 + 1 - else : - var_9 = var_10 - return var_7 if var_0 [ var_7 ] == var_3 else - 1 -",10,2 -939,0337.House Robber III_1.py,"def dfs(root): - if root is None: - return 0 - if root.left is None and root.right is None: - return root.val - a = dfs(root.left) + dfs(root.right) - b = root.val - if root.left: - b += dfs(root.left.left) + dfs(root.left.right) - if root.right: - b += dfs(root.right.left) + dfs(root.right.right) - return max(a, b)","def sample_funcname ( var_1 ) : - if var_1 is None : - return 0 - if var_1.left is None and var_1.right is None : - return var_1.val - var_7 = var_0 ( var_1.left ) + var_0 ( var_1.right ) - var_8 = var_1.val - if var_1.left : - var_8 += var_0 ( var_1.left.left ) + var_0 ( var_1.left.right ) - if var_1.right : - var_8 += var_0 ( var_1.right.left ) + var_0 ( var_1.right.right ) - return max ( var_7 , var_8 ) -",0None,2 -940,0780.Reaching Points_1.py,"def reachingPoints( sx: int, sy: int, tx: int, ty: int) -> bool: - while tx > sx and ty > sy and tx != ty: - if tx > ty: - tx %= ty - else: - ty %= tx - if tx == sx and ty == sy: - return True - if tx == sx: - return ty > sy and (ty - sy) % tx == 0 - if ty == sy: - return tx > sx and (tx - sx) % ty == 0 - return False","def sample_funcname ( var_0 : int , var_2 : int , var_3 : int , var_4 : int ) -> bool : - while var_3 > var_0 and var_4 > var_2 and var_3 != var_4 : - if var_3 > var_4 : - var_3 %= var_4 - else : - var_4 %= var_3 - if var_3 == var_0 and var_4 == var_2 : - return True - if var_3 == var_0 : - return var_4 > var_2 and ( var_4 - var_2 ) % var_3 == 0 - if var_4 == var_2 : - return var_3 > var_0 and ( var_3 - var_0 ) % var_4 == 0 - return False -",0,1 -941,0335.Self Crossing_1.py,"def isSelfCrossing( distance: List[int]) -> bool: - d = distance - for i in range(3, len(d)): - if d[i] >= d[i - 2] and d[i - 1] <= d[i - 3]: - return True - if i >= 4 and d[i - 1] == d[i - 3] and d[i] + d[i - 4] >= d[i - 2]: - return True - if ( - i >= 5 - and d[i - 2] >= d[i - 4] - and d[i - 1] <= d[i - 3] - and d[i] >= d[i - 2] - d[i - 4] - and d[i - 1] + d[i - 5] >= d[i - 3] - ): - return True - return False","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_4 = var_0 - for var_8 in range ( 3 , len ( var_4 ) ) : - if var_4 [ var_8 ] >= var_4 [ var_8 - 2 ] and var_4 [ var_8 - 1 ] <= var_4 [ var_8 - 3 ] : - return True - if var_8 >= 4 and var_4 [ var_8 - 1 ] == var_4 [ var_8 - 3 ] and var_4 [ var_8 ] + var_4 [ var_8 - 4 ] >= var_4 [ var_8 - 2 ] : - return True - if ( var_8 >= 5 and var_4 [ var_8 - 2 ] >= var_4 [ var_8 - 4 ] and var_4 [ var_8 - 1 ] <= var_4 [ var_8 - 3 ] and var_4 [ var_8 ] >= var_4 [ var_8 - 2 ] - var_4 [ var_8 - 4 ] and var_4 [ var_8 - 1 ] + var_4 [ var_8 - 5 ] >= var_4 [ var_8 - 3 ] ) : - return True - return False -",52134,5 -942,1904.The Number of Full Rounds You Have Played_1.py,"def get(s: str) -> int: - return int(s[:2]) * 60 + int(s[3:])","def sample_funcname ( var_0 : str ) -> int : - return int ( var_0 [ : 2 ] ) * 60 + int ( var_0 [ 3 : ] ) -",6032,3 -943,0372.Super Pow_1.py,"def superPow( a: int, b: List[int]) -> int: - MOD = 1337 - ans = 1 - for e in b[::-1]: - ans = ans * pow(a, e, MOD) % MOD - a = pow(a, 10, MOD) - return ans","def sample_funcname ( var_0 : int , var_2 : List [ int ] ) -> int : - var_5 = 1337 - var_7 = 1 - for var_8 in var_2 [ : : - 1 ] : - var_7 = var_7 * pow ( var_0 , var_8 , var_5 ) % var_5 - var_0 = pow ( var_0 , 10 , var_5 ) - return var_7 -",1011337,3 -944,2073.Time Needed to Buy Tickets_1.py,"def timeRequiredToBuy( tickets: List[int], k: int) -> int: - ans = 0 - for i, t in enumerate(tickets): - if i <= k: - ans += min(tickets[k], t) - else: - ans += min(tickets[k] - 1, t) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 = 0 - for var_7 , var_8 in enumerate ( var_0 ) : - if var_7 <= var_3 : - var_5 += min ( var_0 [ var_3 ] , var_8 ) - else : - var_5 += min ( var_0 [ var_3 ] - 1 , var_8 ) - return var_5 -",10,2 -945,2184.Number of Ways to Build Sturdy Brick Wall_1.py,"def check(a, b): - s1, s2 = a[0], b[0] - i = j = 1 - while i < len(a) and j < len(b): - if s1 == s2: - return False - if s1 < s2: - s1 += a[i] - i += 1 - else: - s2 += b[j] - j += 1 - return True","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 = var_0 [ 0 ] , var_1 [ 0 ] - var_7 = var_5 = 1 - while var_7 < len ( var_0 ) and var_5 < len ( var_1 ) : - if var_3 == var_4 : - return False - if var_3 < var_4 : - var_3 += var_0 [ var_7 ] - var_7 += 1 - else : - var_4 += var_1 [ var_5 ] - var_5 += 1 - return True -",10,2 -946,1009.Complement of Base 10 Integer_1.py,"def bitwiseComplement( n: int) -> int: - if n == 0: - return 1 - ans = 0 - find = False - for i in range(30, -1, -1): - b = n & (1 << i) - if not find and b == 0: - continue - find = True - if b == 0: - ans |= 1 << i - return ans","def sample_funcname ( var_0 : int ) -> int : - if var_0 == 0 : - return 1 - var_4 = 0 - var_6 = False - for var_9 in range ( 30 , - 1 , - 1 ) : - var_10 = var_0 & ( 1 << var_9 ) - if not var_6 and var_10 == 0 : - continue - var_6 = True - if var_10 == 0 : - var_4 |= 1 << var_9 - return var_4 -",1030,3 -947,0009.Palindrome Number_1.py,"def isPalindrome( x: int) -> bool: - if x < 0: - return False - y, t = 0, x - while t: - y = y * 10 + t % 10 - t //= 10 - return x == y","def sample_funcname ( var_0 : int ) -> bool : - if var_0 < 0 : - return False - var_5 , var_6 = 0 , var_0 - while var_6 : - var_5 = var_5 * 10 + var_6 % 10 - var_6 //= 10 - return var_0 == var_5 -",100,2 -948,1716.Calculate Money in Leetcode Bank_1.py,"def totalMoney( n: int) -> int: - a, b = divmod(n, 7) - return (28 + 28 + 7 * (a - 1)) * a // 2 + (a * 2 + b + 1) * b // 2","def sample_funcname ( var_0 : int ) -> int : - var_3 , var_5 = divmod ( var_0 , 7 ) - return ( 28 + 28 + 7 * ( var_3 - 1 ) ) * var_3 // 2 + ( var_3 * 2 + var_5 + 1 ) * var_5 // 2 -",17282,4 -949,0231.Power of Two_1.py,"def isPowerOfTwo( n: int) -> bool: - return n > 0 and (n & (n - 1)) == 0","def sample_funcname ( var_0 : int ) -> bool : - return var_0 > 0 and ( var_0 & ( var_0 - 1 ) ) == 0 -",10,2 -950,1576.Replace All 's to Avoid Consecutive Repeating Characters_1.py,"def modifyString( s: str) -> str: - ans = list(s) - for i, c in enumerate(ans): - if c == '?': - for cc in 'abc': - if i > 0 and ans[i - 1] == cc: - continue - if i < len(s) - 1 and ans[i + 1] == cc: - continue - ans[i] = cc - break - return ''.join(ans)","def sample_funcname ( var_0 : str ) -> str : - var_3 = list ( var_0 ) - for var_5 , var_6 in enumerate ( var_3 ) : - if var_6 == '?' : - for var_9 in 'abc' : - if var_5 > 0 and var_3 [ var_5 - 1 ] == var_9 : - continue - if var_5 < len ( var_0 ) - 1 and var_3 [ var_5 + 1 ] == var_9 : - continue - var_3 [ var_5 ] = var_9 - break - return ''.join ( var_3 ) -",0?1abc,5 -951,0264.Ugly Number II_1.py,"def nthUglyNumber( n: int) -> int: - dp = [1] * n - p2 = p3 = p5 = 0 - for i in range(1, n): - next2, next3, next5 = dp[p2] * 2, dp[p3] * 3, dp[p5] * 5 - dp[i] = min(next2, next3, next5) - if dp[i] == next2: - p2 += 1 - if dp[i] == next3: - p3 += 1 - if dp[i] == next5: - p5 += 1 - return dp[n - 1]","def sample_funcname ( var_0 : int ) -> int : - var_3 = [ 1 ] * var_0 - var_7 = var_4 = var_5 = 0 - for var_9 in range ( 1 , var_0 ) : - var_11 , var_13 , var_15 = var_3 [ var_7 ] * 2 , var_3 [ var_4 ] * 3 , var_3 [ var_5 ] * 5 - var_3 [ var_9 ] = min ( var_11 , var_13 , var_15 ) - if var_3 [ var_9 ] == var_11 : - var_7 += 1 - if var_3 [ var_9 ] == var_13 : - var_4 += 1 - if var_3 [ var_9 ] == var_15 : - var_5 += 1 - return var_3 [ var_0 - 1 ] -",50213,5 -952,0988.Smallest String Starting From Leaf_1.py,"def dfs(root, path): - nonlocal ans - if root: - path.append(chr(ord('a') + root.val)) - if root.left is None and root.right is None: - ans = min(ans, ''.join(reversed(path))) - dfs(root.left, path) - dfs(root.right, path) - path.pop()","def sample_funcname ( var_1 , var_2 ) : - nonlocal var_3 - if var_1 : - var_2.append ( chr ( ord ( 'a' ) + var_1.val ) ) - if var_1.left is None and var_1.right is None : - var_3 = min ( var_3 , ''.join ( reversed ( var_2 ) ) ) - var_0 ( var_1.left , var_2 ) - var_0 ( var_1.right , var_2 ) - var_2.pop ( ) -",aNone,3 -953,1876.Substrings of Size Three with Distinct Characters_1.py,"def countGoodSubstrings( s: str) -> int: - count, n = 0, len(s) - for i in range(n - 2): - count += s[i] != s[i + 1] and s[i] != s[i + 2] and s[i + 1] != s[i + 2] - return count","def sample_funcname ( var_0 : str ) -> int : - var_4 , var_6 = 0 , len ( var_0 ) - for var_9 in range ( var_6 - 2 ) : - var_4 += var_0 [ var_9 ] != var_0 [ var_9 + 1 ] and var_0 [ var_9 ] != var_0 [ var_9 + 2 ] and var_0 [ var_9 + 1 ] != var_0 [ var_9 + 2 ] - return var_4 -",102,3 -954,0139.Word Break_1.py,"def wordBreak( s: str, wordDict: List[str]) -> bool: - words = set(wordDict) - n = len(s) - dp = [False] * (n + 1) - dp[0] = True - for i in range(1, n + 1): - for j in range(i): - if dp[j] and s[j:i] in words: - dp[i] = True - break - return dp[-1]","def sample_funcname ( var_0 : str , var_2 : List [ str ] ) -> bool : - var_6 = set ( var_2 ) - var_8 = len ( var_0 ) - var_11 = [ False ] * ( var_8 + 1 ) - var_11 [ 0 ] = True - for var_15 in range ( 1 , var_8 + 1 ) : - for var_16 in range ( var_15 ) : - if var_11 [ var_16 ] and var_0 [ var_16 : var_15 ] in var_6 : - var_11 [ var_15 ] = True - break - return var_11 [ - 1 ] -",10,2 -955,0474.Ones and Zeroes_1.py,"def findMaxForm( strs: List[str], m: int, n: int) -> int: - dp = [[0] * (n + 1) for _ in range(m + 1)] - t = [(s.count('0'), s.count('1')) for s in strs] - for k in range(len(strs)): - n0, n1 = t[k] - for i in range(m, n0 - 1, -1): - for j in range(n, n1 - 1, -1): - dp[i][j] = max(dp[i][j], dp[i - n0][j - n1] + 1) - return dp[-1][-1]","def sample_funcname ( var_0 : List [ str ] , var_3 : int , var_5 : int ) -> int : - var_10 = [ [ 0 ] * ( var_5 + 1 ) for var_8 in range ( var_3 + 1 ) ] - var_15 = [ ( var_11.count ( '0' ) , var_11.count ( '1' ) ) for var_11 in var_0 ] - for var_17 in range ( len ( var_0 ) ) : - var_18 , var_19 = var_15 [ var_17 ] - for var_20 in range ( var_3 , var_18 - 1 , - 1 ) : - for var_21 in range ( var_5 , var_19 - 1 , - 1 ) : - var_10 [ var_20 ] [ var_21 ] = max ( var_10 [ var_20 ] [ var_21 ] , var_10 [ var_20 - var_18 ] [ var_21 - var_19 ] + 1 ) - return var_10 [ - 1 ] [ - 1 ] -",1001,4 -956,0386.Lexicographical Numbers_1.py,"def lexicalOrder( n: int) -> List[int]: - v = 1 - ans = [] - for i in range(n): - ans.append(v) - if v * 10 <= n: - v *= 10 - else: - while v % 10 == 9 or v + 1 > n: - v //= 10 - v += 1 - return ans","def sample_funcname ( var_0 : int ) -> List [ int ] : - var_4 = 1 - var_5 = [ ] - for var_7 in range ( var_0 ) : - var_5.append ( var_4 ) - if var_4 * 10 <= var_0 : - var_4 *= 10 - else : - while var_4 % 10 == 9 or var_4 + 1 > var_0 : - var_4 //= 10 - var_4 += 1 - return var_5 -",1019,3 -957,0062.Unique Paths_1.py,"def uniquePaths( m: int, n: int) -> int: - dp = [[1] * n for _ in range(m)] - for i in range(1, m): - for j in range(1, n): - dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - return dp[-1][-1]","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_6 = [ [ 1 ] * var_2 for var_4 in range ( var_0 ) ] - for var_7 in range ( 1 , var_0 ) : - for var_8 in range ( 1 , var_2 ) : - var_6 [ var_7 ] [ var_8 ] = var_6 [ var_7 - 1 ] [ var_8 ] + var_6 [ var_7 ] [ var_8 - 1 ] - return var_6 [ - 1 ] [ - 1 ] -",1,1 -958,0080.Remove Duplicates from Sorted Array II_1.py,"def removeDuplicates( nums: List[int]) -> int: - i = 0 - for num in nums: - if i < 2 or num != nums[i - 2]: - nums[i] = num - i += 1 - return i","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 0 - for var_5 in var_0 : - if var_4 < 2 or var_5 != var_0 [ var_4 - 2 ] : - var_0 [ var_4 ] = var_5 - var_4 += 1 - return var_4 -",102,3 -959,2348.Number of Zero-Filled Subarrays_1.py,"def zeroFilledSubarray( nums: List[int]) -> int: - ans = 0 - cnt = 0 - for v in nums: - if v == 0: - cnt += 1 - else: - ans += (1 + cnt) * cnt // 2 - cnt = 0 - ans += (1 + cnt) * cnt // 2 - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 0 - var_5 = 0 - for var_6 in var_0 : - if var_6 == 0 : - var_5 += 1 - else : - var_4 += ( 1 + var_5 ) * var_5 // 2 - var_5 = 0 - var_4 += ( 1 + var_5 ) * var_5 // 2 - return var_4 -",102,3 -960,1442.Count Triplets That Can Form Two Arrays of Equal XOR_1.py,"def countTriplets( arr: List[int]) -> int: - n = len(arr) - pre = [0] * (n + 1) - for i in range(n): - pre[i + 1] = pre[i] ^ arr[i] - ans = 0 - for i in range(n - 1): - for j in range(i + 1, n): - for k in range(j, n): - a, b = pre[j] ^ pre[i], pre[k + 1] ^ pre[j] - if a == b: - ans += 1 - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_7 = [ 0 ] * ( var_4 + 1 ) - for var_9 in range ( var_4 ) : - var_7 [ var_9 + 1 ] = var_7 [ var_9 ] ^ var_0 [ var_9 ] - var_10 = 0 - for var_9 in range ( var_4 - 1 ) : - for var_11 in range ( var_9 + 1 , var_4 ) : - for var_12 in range ( var_11 , var_4 ) : - var_13 , var_14 = var_7 [ var_11 ] ^ var_7 [ var_9 ] , var_7 [ var_12 + 1 ] ^ var_7 [ var_11 ] - if var_13 == var_14 : - var_10 += 1 - return var_10 -",10,2 -961,0237.Delete Node in a Linked List_1.py,"def deleteNode( node): - node.val = node.next.val - node.next = node.next.next","def sample_funcname ( var_0 ) : - var_0.val = var_0.next.val - var_0.next = var_0.next.next -",,0 -962,0306.Additive Number_1.py,"def dfs(a, b, num): - if not num: - return True - if a + b > 0 and num[0] == '0': - return False - for i in range(1, len(num) + 1): - if a + b == int(num[:i]): - if dfs(b, a + b, num[i:]): - return True - return False","def sample_funcname ( var_1 , var_2 , var_3 ) : - if not var_3 : - return True - if var_1 + var_2 > 0 and var_3 [ 0 ] == '0' : - return False - for var_11 in range ( 1 , len ( var_3 ) + 1 ) : - if var_1 + var_2 == int ( var_3 [ : var_11 ] ) : - if var_0 ( var_2 , var_1 + var_2 , var_3 [ var_11 : ] ) : - return True - return False -",100,3 -963,0120.Triangle_1.py,"def minimumTotal( triangle: List[List[int]]) -> int: - n = len(triangle) - dp = [0] * (n + 1) - for i in range(n - 1, -1, -1): - for j in range(i + 1): - dp[j] = min(dp[j], dp[j + 1]) + triangle[i][j] - return dp[0]","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 = len ( var_0 ) - var_7 = [ 0 ] * ( var_4 + 1 ) - for var_9 in range ( var_4 - 1 , - 1 , - 1 ) : - for var_10 in range ( var_9 + 1 ) : - var_7 [ var_10 ] = min ( var_7 [ var_10 ] , var_7 [ var_10 + 1 ] ) + var_0 [ var_9 ] [ var_10 ] - return var_7 [ 0 ] -",10,2 -964,1854.Maximum Population Year_1.py,"def maximumPopulation( logs: List[List[int]]) -> int: - delta = [0] * 2055 - for birth, death in logs: - delta[birth] += 1 - delta[death] -= 1 - - mx = res = cur = 0 - for i, v in enumerate(delta): - cur += v - if mx < cur: - mx = cur - res = i - return res","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_5 = [ 0 ] * 2055 - for var_6 , var_7 in var_0 : - var_5 [ var_6 ] += 1 - var_5 [ var_7 ] -= 1 - var_11 = var_9 = var_10 = 0 - for var_13 , var_14 in enumerate ( var_5 ) : - var_10 += var_14 - if var_11 < var_10 : - var_11 = var_10 - var_9 = var_13 - return var_9 -",102055,3 -965,0435.Non-overlapping Intervals_1.py,"def eraseOverlapIntervals( intervals: List[List[int]]) -> int: - intervals.sort(key=lambda x: x[1]) - ans, t = 0, intervals[0][1] - for s, e in intervals[1:]: - if s >= t: - t = e - else: - ans += 1 - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_0.sort ( var_4 = lambda var_5 : var_5 [ 1 ] ) - var_8 , var_9 = 0 , var_0 [ 0 ] [ 1 ] - for var_10 , var_11 in var_0 [ 1 : ] : - if var_10 >= var_9 : - var_9 = var_11 - else : - var_8 += 1 - return var_8 -",10,2 -966,1385.Find the Distance Value Between Two Arrays_1.py,"def findTheDistanceValue( arr1: List[int], arr2: List[int], d: int) -> int: - return sum(all(abs(a - b) > d for b in arr2) for a in arr1)","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] , var_4 : int ) -> int : - return sum ( all ( abs ( var_8 - var_9 ) > var_4 for var_9 in var_3 ) for var_8 in var_0 ) -",,0 -967,2310.Sum of Numbers With Units Digit K_1.py,"def minimumNumbers( num: int, k: int) -> int: - if num == 0: - return 0 - for i in range(1, num + 1): - if (t := num - k * i) >= 0 and t % 10 == 0: - return i - return -1","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - if var_0 == 0 : - return 0 - for var_6 in range ( 1 , var_0 + 1 ) : - if ( var_7 := var_0 - var_2 * var_6 ) >= 0 and var_7 % 10 == 0 : - return var_6 - return - 1 -",1010,3 -968,1451.Rearrange Words in a Sentence_1.py,"def arrangeWords( text: str) -> str: - words = text.split() - words[0] = words[0].lower() - words.sort(key=len) - words[0] = words[0].title() - return "" "".join(words)","def sample_funcname ( var_0 : str ) -> str : - var_3 = var_0.split ( ) - var_3 [ 0 ] = var_3 [ 0 ].lower ( ) - var_3.sort ( var_7 = len ) - var_3 [ 0 ] = var_3 [ 0 ].title ( ) - return "" "".join ( var_3 ) -",0 ,2 -969,0003.Longest Substring Without Repeating Characters_1.py,"def lengthOfLongestSubstring( s: str) -> int: - ss = set() - i = ans = 0 - for j, c in enumerate(s): - while c in ss: - ss.remove(s[i]) - i += 1 - ss.add(c) - ans = max(ans, j - i + 1) - return ans","def sample_funcname ( var_0 : str ) -> int : - var_4 = set ( ) - var_7 = var_5 = 0 - for var_9 , var_10 in enumerate ( var_0 ) : - while var_10 in var_4 : - var_4.remove ( var_0 [ var_7 ] ) - var_7 += 1 - var_4.add ( var_10 ) - var_5 = max ( var_5 , var_9 - var_7 + 1 ) - return var_5 -",10,2 -970,0426.Convert Binary Search Tree to Sorted Doubly Linked List_1.py,"def dfs(root): - if root is None: - return - nonlocal prev, head - dfs(root.left) - if prev: - prev.right = root - root.left = prev - else: - head = root - prev = root - dfs(root.right)","def sample_funcname ( var_1 ) : - if var_1 is None : - return - nonlocal var_3 , var_4 - var_0 ( var_1.left ) - if var_3 : - var_3.right = var_1 - var_1.left = var_3 - else : - var_4 = var_1 - var_3 = var_1 - var_0 ( var_1.right ) -",None,1 -971,0364.Nested List Weight Sum II_1.py,"def dfs(nestedList, max_depth): - depth_sum = 0 - for item in nestedList: - if item.isInteger(): - depth_sum += item.getInteger() * max_depth - else: - depth_sum += dfs(item.getList(), max_depth - 1) - return depth_sum","def sample_funcname ( var_1 , var_2 ) : - var_4 = 0 - for var_5 in var_1 : - if var_5.isInteger ( ) : - var_4 += var_5.getInteger ( ) * var_2 - else : - var_4 += var_0 ( var_5.getList ( ) , var_2 - 1 ) - return var_4 -",10,2 -972,0146.LRU Cache_1.py,"def remove_node( node): - node.prev.next = node.next - node.next.prev = node.prev","def sample_funcname ( var_0 ) : - var_0.prev.next = var_0.next - var_0.next.prev = var_0.prev -",,0 -973,2155.All Divisions With the Highest Score of a Binary Array_1.py,"def maxScoreIndices( nums: List[int]) -> List[int]: - left, right = 0, sum(nums) - mx = right - ans = [0] - for i, num in enumerate(nums): - if num == 0: - left += 1 - else: - right -= 1 - t = left + right - if mx == t: - ans.append(i + 1) - elif mx < t: - mx = t - ans = [i + 1] - return ans","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 , var_6 = 0 , sum ( var_0 ) - var_7 = var_6 - var_8 = [ 0 ] - for var_10 , var_11 in enumerate ( var_0 ) : - if var_11 == 0 : - var_4 += 1 - else : - var_6 -= 1 - var_13 = var_4 + var_6 - if var_7 == var_13 : - var_8.append ( var_10 + 1 ) - elif var_7 < var_13 : - var_7 = var_13 - var_8 = [ var_10 + 1 ] - return var_8 -",10,2 -974,1855.Maximum Distance Between a Pair of Values_1.py,"def maxDistance( nums1: List[int], nums2: List[int]) -> int: - ans, n = 0, len(nums2) - for i, num in enumerate(nums1): - left, right = i, n - 1 - while left < right: - mid = (left + right + 1) >> 1 - if nums2[mid] >= num: - left = mid - else: - right = mid - 1 - ans = max(ans, left - i) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_5 , var_7 = 0 , len ( var_3 ) - for var_9 , var_10 in enumerate ( var_0 ) : - var_11 , var_13 = var_9 , var_7 - 1 - while var_11 < var_13 : - var_14 = ( var_11 + var_13 + 1 ) >> 1 - if var_3 [ var_14 ] >= var_10 : - var_11 = var_14 - else : - var_13 = var_14 - 1 - var_5 = max ( var_5 , var_11 - var_9 ) - return var_5 -",10,2 -975,1403.Minimum Subsequence in Non-Increasing Order_1.py,"def minSubsequence( nums: List[int]) -> List[int]: - nums.sort(reverse=True) - s = sum(nums) - ans = [] - t = 0 - for v in nums: - ans.append(v) - t += v - if t > s - t: - break - return ans","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_0.sort ( var_4 = True ) - var_7 = sum ( var_0 ) - var_8 = [ ] - var_10 = 0 - for var_11 in var_0 : - var_8.append ( var_11 ) - var_10 += var_11 - if var_10 > var_7 - var_10 : - break - return var_8 -",0,1 -976,0081.Search in Rotated Sorted Array II_1.py,"def search( nums: List[int], target: int) -> bool: - l, r = 0, len(nums) - 1 - while l <= r: - mid = (l + r) >> 1 - if nums[mid] == target: - return True - if nums[mid] < nums[r] or nums[mid] < nums[l]: - if target > nums[mid] and target <= nums[r]: - l = mid + 1 - else: - r = mid - 1 - elif nums[mid] > nums[l] or nums[mid] > nums[r]: - if target < nums[mid] and target >= nums[l]: - r = mid - 1 - else: - l = mid + 1 - else: - r -= 1 - return False","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> bool : - var_6 , var_9 = 0 , len ( var_0 ) - 1 - while var_6 <= var_9 : - var_10 = ( var_6 + var_9 ) >> 1 - if var_0 [ var_10 ] == var_3 : - return True - if var_0 [ var_10 ] < var_0 [ var_9 ] or var_0 [ var_10 ] < var_0 [ var_6 ] : - if var_3 > var_0 [ var_10 ] and var_3 <= var_0 [ var_9 ] : - var_6 = var_10 + 1 - else : - var_9 = var_10 - 1 - elif var_0 [ var_10 ] > var_0 [ var_6 ] or var_0 [ var_10 ] > var_0 [ var_9 ] : - if var_3 < var_0 [ var_10 ] and var_3 >= var_0 [ var_6 ] : - var_9 = var_10 - 1 - else : - var_6 = var_10 + 1 - else : - var_9 -= 1 - return False -",10,2 -978,0455.Assign Cookies_1.py,"def findContentChildren( g: List[int], s: List[int]) -> int: - g.sort() - s.sort() - j = 0 - for i, v in enumerate(g): - while j < len(s) and s[j] < v: - j += 1 - if j >= len(s): - return i - j += 1 - return len(g)","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_0.sort ( ) - var_3.sort ( ) - var_6 = 0 - for var_8 , var_9 in enumerate ( var_0 ) : - while var_6 < len ( var_3 ) and var_3 [ var_6 ] < var_9 : - var_6 += 1 - if var_6 >= len ( var_3 ) : - return var_8 - var_6 += 1 - return len ( var_0 ) -",10,2 -979,2321.Maximum Score Of Spliced Array_1.py,"def f(nums1, nums2): - d = [a - b for a, b in zip(nums1, nums2)] - t = mx = d[0] - for v in d[1:]: - if t > 0: - t += v - else: - t = v - mx = max(mx, t) - return mx","def sample_funcname ( var_0 , var_1 ) : - var_5 = [ var_2 - var_3 for var_2 , var_3 in zip ( var_0 , var_1 ) ] - var_8 = var_6 = var_5 [ 0 ] - for var_10 in var_5 [ 1 : ] : - if var_8 > 0 : - var_8 += var_10 - else : - var_8 = var_10 - var_6 = max ( var_6 , var_8 ) - return var_6 -",10,2 -980,1196.How Many Apples Can You Put into the Basket_1.py,"def maxNumberOfApples( weight: List[int]) -> int: - weight.sort() - ans = 0 - t = 0 - for v in weight: - if t + v > 5000: - break - t += v - ans += 1 - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( ) - var_5 = 0 - var_6 = 0 - for var_7 in var_0 : - if var_6 + var_7 > 5000 : - break - var_6 += var_7 - var_5 += 1 - return var_5 -",105000,3 -981,2399.Check Distances Between Same Letters_1.py,"def checkDistances( s: str, distance: List[int]) -> bool: - d = [0] * 26 - for i, c in enumerate(s): - j = ord(c) - ord(""a"") - if d[j] and i - d[j] != distance[j]: - return False - d[j] = i + 1 - return True","def sample_funcname ( var_0 : str , var_2 : List [ int ] ) -> bool : - var_8 = [ 0 ] * 26 - for var_10 , var_11 in enumerate ( var_0 ) : - var_14 = ord ( var_11 ) - ord ( ""a"" ) - if var_8 [ var_14 ] and var_10 - var_8 [ var_14 ] != var_2 [ var_14 ] : - return False - var_8 [ var_14 ] = var_10 + 1 - return True -",1026a,4 -982,1529.Minimum Suffix Flips_1.py,"def minFlips( target: str) -> int: - ans = 0 - for v in target: - if (ans & 1) ^ int(v): - ans += 1 - return ans","def sample_funcname ( var_0 : str ) -> int : - var_4 = 0 - for var_5 in var_0 : - if ( var_4 & 1 ) ^ int ( var_5 ) : - var_4 += 1 - return var_4 -",10,2 -983,1713.Minimum Operations to Make a Subsequence_1.py,"def lowbit(x): - return x & -x","def sample_funcname ( var_0 ) : - return var_0 & - var_0 -",,0 -984,0085.Maximal Rectangle_1.py,"def largestRectangleArea( heights: List[int]) -> int: - n = len(heights) - stk = [] - left = [-1] * n - right = [n] * n - for i, h in enumerate(heights): - while stk and heights[stk[-1]] >= h: - stk.pop() - if stk: - left[i] = stk[-1] - stk.append(i) - stk = [] - for i in range(n - 1, -1, -1): - h = heights[i] - while stk and heights[stk[-1]] >= h: - stk.pop() - if stk: - right[i] = stk[-1] - stk.append(i) - return max(h * (right[i] - left[i] - 1) for i, h in enumerate(heights))","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_5 = [ ] - var_7 = [ - 1 ] * var_4 - var_8 = [ var_4 ] * var_4 - for var_10 , var_11 in enumerate ( var_0 ) : - while var_5 and var_0 [ var_5 [ - 1 ] ] >= var_11 : - var_5.pop ( ) - if var_5 : - var_7 [ var_10 ] = var_5 [ - 1 ] - var_5.append ( var_10 ) - var_5 = [ ] - for var_10 in range ( var_4 - 1 , - 1 , - 1 ) : - var_11 = var_0 [ var_10 ] - while var_5 and var_0 [ var_5 [ - 1 ] ] >= var_11 : - var_5.pop ( ) - if var_5 : - var_8 [ var_10 ] = var_5 [ - 1 ] - var_5.append ( var_10 ) - return max ( var_11 * ( var_8 [ var_10 ] - var_7 [ var_10 ] - 1 ) for var_10 , var_11 in enumerate ( var_0 ) ) -",1,1 -985,0520.Detect Capital_1.py,"def detectCapitalUse( word: str) -> bool: - cnt = 0 - for c in word: - if c.isupper(): - cnt += 1 - return cnt == 0 or cnt == len(word) or (cnt == 1 and word[0].isupper())","def sample_funcname ( var_0 : str ) -> bool : - var_4 = 0 - for var_5 in var_0 : - if var_5.isupper ( ) : - var_4 += 1 - return var_4 == 0 or var_4 == len ( var_0 ) or ( var_4 == 1 and var_0 [ 0 ].isupper ( ) ) -",10,2 -986,0506.Relative Ranks_1.py,"def findRelativeRanks( score: List[int]) -> List[str]: - n = len(score) - idx = list(range(n)) - idx.sort(key=lambda x: -score[x]) - top3 = ['Gold Medal', 'Silver Medal', 'Bronze Medal'] - ans = [None] * n - for i in range(n): - ans[idx[i]] = top3[i] if i < 3 else str(i + 1) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> List [ str ] : - var_5 = len ( var_0 ) - var_8 = list ( range ( var_5 ) ) - var_8.sort ( var_10 = lambda var_11 : - var_0 [ var_11 ] ) - var_15 = [ 'Gold Medal' , 'Silver Medal' , 'Bronze Medal' ] - var_17 = [ None ] * var_5 - for var_18 in range ( var_5 ) : - var_17 [ var_8 [ var_18 ] ] = var_15 [ var_18 ] if var_18 < 3 else str ( var_18 + 1 ) - return var_17 -",Silver MedalBronze MedalNoneGold Medal13,6 -987,0605.Can Place Flowers_1.py,"def canPlaceFlowers( flowerbed: List[int], n: int) -> bool: - flowerbed = [0] + flowerbed + [0] - for i in range(1, len(flowerbed) - 1): - if sum(flowerbed[i - 1 : i + 2]) == 0: - flowerbed[i] = 1 - n -= 1 - return n <= 0","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> bool : - var_0 = [ 0 ] + var_0 + [ 0 ] - for var_9 in range ( 1 , len ( var_0 ) - 1 ) : - if sum ( var_0 [ var_9 - 1 : var_9 + 2 ] ) == 0 : - var_0 [ var_9 ] = 1 - var_3 -= 1 - return var_3 <= 0 -",102,3 -988,0101.Symmetric Tree_1.py,"def dfs(root1, root2): - if root1 is None and root2 is None: - return True - if root1 is None or root2 is None or root1.val != root2.val: - return False - return dfs(root1.left, root2.right) and dfs(root1.right, root2.left)","def sample_funcname ( var_1 , var_2 ) : - if var_1 is None and var_2 is None : - return True - if var_1 is None or var_2 is None or var_1.val != var_2.val : - return False - return var_0 ( var_1.left , var_2.right ) and var_0 ( var_1.right , var_2.left ) -",None,1 -989,0122.Best Time to Buy and Sell Stock II_1.py,"def maxProfit( prices: List[int]) -> int: - res = 0 - for i in range(1, len(prices)): - t = prices[i] - prices[i - 1] - res += max(t, 0) - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 0 - for var_8 in range ( 1 , len ( var_0 ) ) : - var_9 = var_0 [ var_8 ] - var_0 [ var_8 - 1 ] - var_4 += max ( var_9 , 0 ) - return var_4 -",10,2 -990,0931.Minimum Falling Path Sum_1.py,"def minFallingPathSum( matrix: List[List[int]]) -> int: - n = len(matrix) - for i in range(1, n): - for j in range(n): - mi = matrix[i - 1][j] - if j > 0: - mi = min(mi, matrix[i - 1][j - 1]) - if j < n - 1: - mi = min(mi, matrix[i - 1][j + 1]) - matrix[i][j] += mi - return min(matrix[n - 1])","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 = len ( var_0 ) - for var_7 in range ( 1 , var_4 ) : - for var_8 in range ( var_4 ) : - var_9 = var_0 [ var_7 - 1 ] [ var_8 ] - if var_8 > 0 : - var_9 = min ( var_9 , var_0 [ var_7 - 1 ] [ var_8 - 1 ] ) - if var_8 < var_4 - 1 : - var_9 = min ( var_9 , var_0 [ var_7 - 1 ] [ var_8 + 1 ] ) - var_0 [ var_7 ] [ var_8 ] += var_9 - return min ( var_0 [ var_4 - 1 ] ) -",10,2 -991,2366.Minimum Replacements to Sort the Array_1.py,"def minimumReplacement( nums: List[int]) -> int: - ans, n = 0, len(nums) - mi = nums[-1] - for i in range(n - 2, -1, -1): - v = nums[i] - if v <= mi: - mi = v - continue - k = (v + mi - 1) // mi - ans += k - 1 - mi = v // k - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_6 = 0 , len ( var_0 ) - var_8 = var_0 [ - 1 ] - for var_11 in range ( var_6 - 2 , - 1 , - 1 ) : - var_12 = var_0 [ var_11 ] - if var_12 <= var_8 : - var_8 = var_12 - continue - var_13 = ( var_12 + var_8 - 1 ) // var_8 - var_4 += var_13 - 1 - var_8 = var_12 // var_13 - return var_4 -",102,3 -992,0922.Sort Array By Parity II_1.py,"def sortArrayByParityII( nums: List[int]) -> List[int]: - n, j = len(nums), 1 - for i in range(0, n, 2): - if (nums[i] & 1) == 1: - while (nums[j] & 1) == 1: - j += 2 - nums[i], nums[j] = nums[j], nums[i] - return nums","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 , var_6 = len ( var_0 ) , 1 - for var_10 in range ( 0 , var_4 , 2 ) : - if ( var_0 [ var_10 ] & 1 ) == 1 : - while ( var_0 [ var_6 ] & 1 ) == 1 : - var_6 += 2 - var_0 [ var_10 ] , var_0 [ var_6 ] = var_0 [ var_6 ] , var_0 [ var_10 ] - return var_0 -",102,3 -993,0394.Decode String_1.py,"def decodeString( s: str) -> str: - s1, s2 = [], [] - num, res = 0, '' - for c in s: - if c.isdigit(): - num = num * 10 + int(c) - elif c == '[': - s1.append(num) - s2.append(res) - num, res = 0, '' - elif c == ']': - res = s2.pop() + res * s1.pop() - else: - res += c - return res","def sample_funcname ( var_0 : str ) -> str : - var_2 , var_3 = [ ] , [ ] - var_5 , var_7 = 0 , '' - for var_8 in var_0 : - if var_8.isdigit ( ) : - var_5 = var_5 * 10 + int ( var_8 ) - elif var_8 == '[' : - var_2.append ( var_5 ) - var_3.append ( var_7 ) - var_5 , var_7 = 0 , '' - elif var_8 == ']' : - var_7 = var_3.pop ( ) + var_7 * var_2.pop ( ) - else : - var_7 += var_8 - return var_7 -",100][,5 -994,2185.Counting Words With a Given Prefix_1.py,"def prefixCount( words: List[str], pref: str) -> int: - return sum(w.startswith(pref) for w in words)","def sample_funcname ( var_0 : List [ str ] , var_3 : str ) -> int : - return sum ( var_6.startswith ( var_3 ) for var_6 in var_0 ) -",,0 -995,0403.Frog Jump_1.py,"def canCross( stones: List[int]) -> bool: - n = len(stones) - dp = [[False] * n for i in range(n)] - dp[0][0] = True - for i in range(1, n): - for j in range(i): - k = stones[i] - stones[j] - if k > j + 1: - continue - dp[i][k] = dp[j][k - 1] or dp[j][k] or dp[j][k + 1] - if i == n - 1 and dp[i][k]: - return True - return False","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_5 = len ( var_0 ) - var_9 = [ [ False ] * var_5 for var_7 in range ( var_5 ) ] - var_9 [ 0 ] [ 0 ] = True - for var_7 in range ( 1 , var_5 ) : - for var_13 in range ( var_7 ) : - var_14 = var_0 [ var_7 ] - var_0 [ var_13 ] - if var_14 > var_13 + 1 : - continue - var_9 [ var_7 ] [ var_14 ] = var_9 [ var_13 ] [ var_14 - 1 ] or var_9 [ var_13 ] [ var_14 ] or var_9 [ var_13 ] [ var_14 + 1 ] - if var_7 == var_5 - 1 and var_9 [ var_7 ] [ var_14 ] : - return True - return False -",10,2 -996,0518.Coin Change 2_1.py,"def change( amount: int, coins: List[int]) -> int: - dp = [0] * (amount + 1) - dp[0] = 1 - for coin in coins: - for j in range(coin, amount + 1): - dp[j] += dp[j - coin] - return dp[-1]","def sample_funcname ( var_0 : int , var_2 : List [ int ] ) -> int : - var_6 = [ 0 ] * ( var_0 + 1 ) - var_6 [ 0 ] = 1 - for var_7 in var_2 : - for var_9 in range ( var_7 , var_0 + 1 ) : - var_6 [ var_9 ] += var_6 [ var_9 - var_7 ] - return var_6 [ - 1 ] -",10,2 -997,0657.Robot Return to Origin_1.py,"def judgeCircle( moves: str) -> bool: - x = y = 0 - for c in moves: - if c == 'R': - x += 1 - elif c == 'L': - x -= 1 - elif c == 'U': - y += 1 - elif c == 'D': - y -= 1 - return x == 0 and y == 0","def sample_funcname ( var_0 : str ) -> bool : - var_5 = var_3 = 0 - for var_6 in var_0 : - if var_6 == 'R' : - var_5 += 1 - elif var_6 == 'L' : - var_5 -= 1 - elif var_6 == 'U' : - var_3 += 1 - elif var_6 == 'D' : - var_3 -= 1 - return var_5 == 0 and var_3 == 0 -",0LR1UD,6 -998,1313.Decompress Run-Length Encoded List_1.py,"def decompressRLElist( nums: List[int]) -> List[int]: - res = [] - for i in range(1, len(nums), 2): - res.extend([nums[i]] * nums[i - 1]) - return res","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_3 = [ ] - for var_8 in range ( 1 , len ( var_0 ) , 2 ) : - var_3.extend ( [ var_0 [ var_8 ] ] * var_0 [ var_8 - 1 ] ) - return var_3 -",12,2 -999,0487.Max Consecutive Ones II_1.py,"def findMaxConsecutiveOnes( nums: List[int]) -> int: - n = len(nums) - prefix = [0] * n - suffix = [0] * n - res = 0 - for i in range(n): - if i == 0: - prefix[i] = nums[i] - else: - prefix[i] = 0 if nums[i] == 0 else prefix[i - 1] + 1 - res = max(res, prefix[i]) - - for i in range(n - 1, -1, -1): - if i == n - 1: - suffix[i] = nums[i] - else: - suffix[i] = 0 if nums[i] == 0 else suffix[i + 1] + 1 - - for i in range(n): - if nums[i] == 0: - t = 1 - if i > 0: - t += prefix[i - 1] - if i < n - 1: - t += suffix[i + 1] - res = max(res, t) - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_6 = [ 0 ] * var_4 - var_7 = [ 0 ] * var_4 - var_8 = 0 - for var_10 in range ( var_4 ) : - if var_10 == 0 : - var_6 [ var_10 ] = var_0 [ var_10 ] - else : - var_6 [ var_10 ] = 0 if var_0 [ var_10 ] == 0 else var_6 [ var_10 - 1 ] + 1 - var_8 = max ( var_8 , var_6 [ var_10 ] ) - for var_10 in range ( var_4 - 1 , - 1 , - 1 ) : - if var_10 == var_4 - 1 : - var_7 [ var_10 ] = var_0 [ var_10 ] - else : - var_7 [ var_10 ] = 0 if var_0 [ var_10 ] == 0 else var_7 [ var_10 + 1 ] + 1 - for var_10 in range ( var_4 ) : - if var_0 [ var_10 ] == 0 : - var_13 = 1 - if var_10 > 0 : - var_13 += var_6 [ var_10 - 1 ] - if var_10 < var_4 - 1 : - var_13 += var_7 [ var_10 + 1 ] - var_8 = max ( var_8 , var_13 ) - return var_8 -",10,2 -1000,0575.Distribute Candies_1.py,"def distributeCandies( candyType: List[int]) -> int: - return min(len(candyType) >> 1, len(set(candyType)))","def sample_funcname ( var_0 : List [ int ] ) -> int : - return min ( len ( var_0 ) >> 1 , len ( set ( var_0 ) ) ) -",1,1 -1001,2248.Intersection of Multiple Arrays_1.py,"def intersection( nums: List[List[int]]) -> List[int]: - cnt = [0] * 1001 - for num in nums: - for v in num: - cnt[v] += 1 - n = len(nums) - return [i for i, v in enumerate(cnt) if v == n]","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ int ] : - var_5 = [ 0 ] * 1001 - for var_6 in var_0 : - for var_7 in var_6 : - var_5 [ var_7 ] += 1 - var_10 = len ( var_0 ) - return [ var_11 for var_11 , var_7 in enumerate ( var_5 ) if var_7 == var_10 ] -",101001,3 -1002,0732.My Calendar III_1.py,"def pushup( node): - node.v = max(node.left.v, node.right.v)","def sample_funcname ( var_0 ) : - var_0.v = max ( var_0.var_2.v , var_0.var_4.v ) -",,0 -1004,1339.Maximum Product of Splitted Binary Tree_2.py,"def sum(root): - if root is None: - return 0 - return root.val + sum(root.left) + sum(root.right)","def sample_funcname ( var_1 ) : - if var_1 is None : - return 0 - return var_1.val + var_0 ( var_1.left ) + var_0 ( var_1.right ) -",0None,2 -1005,0636.Exclusive Time of Functions_1.py,"def exclusiveTime( n: int, logs: List[str]) -> List[int]: - ans = [0] * n - stk = [] - curr = -1 - for log in logs: - t = log.split(':') - fid = int(t[0]) - ts = int(t[2]) - if t[1] == 'start': - if stk: - ans[stk[-1]] += ts - curr - stk.append(fid) - curr = ts - else: - fid = stk.pop() - ans[fid] += ts - curr + 1 - curr = ts + 1 - return ans","def sample_funcname ( var_0 : int , var_2 : List [ str ] ) -> List [ int ] : - var_6 = [ 0 ] * var_0 - var_7 = [ ] - var_9 = - 1 - for var_10 in var_2 : - var_13 = var_10.split ( ':' ) - var_14 = int ( var_13 [ 0 ] ) - var_16 = int ( var_13 [ 2 ] ) - if var_13 [ 1 ] == 'start' : - if var_7 : - var_6 [ var_7 [ - 1 ] ] += var_16 - var_9 - var_7.append ( var_14 ) - var_9 = var_16 - else : - var_14 = var_7.pop ( ) - var_6 [ var_14 ] += var_16 - var_9 + 1 - var_9 = var_16 + 1 - return var_6 -",0:21start,5 -1006,2194.Cells in a Range on an Excel Sheet_1.py,"def cellsInRange( s: str) -> List[str]: - return [ - chr(i) + str(j) - for i in range(ord(s[0]), ord(s[-2]) + 1) - for j in range(int(s[1]), int(s[-1]) + 1) - ]","def sample_funcname ( var_0 : str ) -> List [ str ] : - return [ chr ( var_4 ) + str ( var_5 ) for var_4 in range ( ord ( var_0 [ 0 ] ) , ord ( var_0 [ - 2 ] ) + 1 ) for var_5 in range ( int ( var_0 [ 1 ] ) , int ( var_0 [ - 1 ] ) + 1 ) ] -",102,3 -1009,2212.Maximum Points in an Archery Competition_1.py,"def maximumBobPoints( numArrows: int, aliceArrows: List[int]) -> List[int]: - n = len(aliceArrows) - state = 0 - mx = -1 - for mask in range(1 << n): - cnt = points = 0 - for i, alice in enumerate(aliceArrows): - if (mask >> i) & 1: - cnt += alice + 1 - points += i - if cnt <= numArrows and mx < points: - state = mask - mx = points - ans = [0] * n - for i, alice in enumerate(aliceArrows): - if (state >> i) & 1: - ans[i] = alice + 1 - numArrows -= ans[i] - ans[0] = numArrows - return ans","def sample_funcname ( var_0 : int , var_2 : List [ int ] ) -> List [ int ] : - var_5 = len ( var_2 ) - var_7 = 0 - var_9 = - 1 - for var_11 in range ( 1 << var_5 ) : - var_13 = var_12 = 0 - for var_15 , var_16 in enumerate ( var_2 ) : - if ( var_11 >> var_15 ) & 1 : - var_13 += var_16 + 1 - var_12 += var_15 - if var_13 <= var_0 and var_9 < var_12 : - var_7 = var_11 - var_9 = var_12 - var_17 = [ 0 ] * var_5 - for var_15 , var_16 in enumerate ( var_2 ) : - if ( var_7 >> var_15 ) & 1 : - var_17 [ var_15 ] = var_16 + 1 - var_0 -= var_17 [ var_15 ] - var_17 [ 0 ] = var_0 - return var_17 -",10,2 -1010,1930.Unique Length-3 Palindromic Subsequences_1.py,"def countPalindromicSubsequence( s: str) -> int: - res = 0 - for i in range(26): - c = chr(ord('a') + i) - if c in s: - l, r = s.index(c), s.rindex(c) - chars = {s[j] for j in range(l + 1, r)} - res += len(chars) - return res","def sample_funcname ( var_0 : str ) -> int : - var_4 = 0 - for var_7 in range ( 26 ) : - var_11 = chr ( ord ( 'a' ) + var_7 ) - if var_11 in var_0 : - var_13 , var_15 = var_0.index ( var_11 ) , var_0.rindex ( var_11 ) - var_18 = { var_0 [ var_16 ] for var_16 in range ( var_13 + 1 , var_15 ) } - var_4 += len ( var_18 ) - return var_4 -",a0126,4 -1011,1016.Binary String With Substrings Representing 1 To N_1.py,"def queryString( s: str, n: int) -> bool: - for i in range(n, n // 2, -1): - if bin(i)[2:] not in s: - return False - return True","def sample_funcname ( var_0 : str , var_2 : int ) -> bool : - for var_8 in range ( var_2 , var_2 // 2 , - 1 ) : - if bin ( var_8 ) [ 2 : ] not in var_0 : - return False - return True -",12,2 -1012,2278.Percentage of Letter in String_1.py,"def percentageLetter( s: str, letter: str) -> int: - return s.count(letter) * 100 // len(s)","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - return var_0.count ( var_2 ) * 100 // len ( var_0 ) -",100,1 -1013,0016.3Sum Closest_1.py,"def twoSumClosest(nums, start, end, target): - res = 0 - diff = 10000 - while start < end: - val = nums[start] + nums[end] - if val == target: - return val - if abs(val - target) < diff: - res = val - diff = abs(val - target) - if val < target: - start += 1 - else: - end -= 1 - return res","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - var_5 = 0 - var_7 = 10000 - while var_1 < var_2 : - var_8 = var_0 [ var_1 ] + var_0 [ var_2 ] - if var_8 == var_3 : - return var_8 - if abs ( var_8 - var_3 ) < var_7 : - var_5 = var_8 - var_7 = abs ( var_8 - var_3 ) - if var_8 < var_3 : - var_1 += 1 - else : - var_2 -= 1 - return var_5 -",1010000,3 -1014,1503.Last Moment Before All Ants Fall Out of a Plank_1.py,"def getLastMoment( n: int, left: List[int], right: List[int]) -> int: - ans = 0 - for t in left: - ans = max(ans, t) - for t in right: - ans = max(ans, n - t) - return ans","def sample_funcname ( var_0 : int , var_2 : List [ int ] , var_4 : List [ int ] ) -> int : - var_6 = 0 - for var_7 in var_2 : - var_6 = max ( var_6 , var_7 ) - for var_7 in var_4 : - var_6 = max ( var_6 , var_0 - var_7 ) - return var_6 -",0,1 -1015,0069.Sqrt(x)_1.py,"def mySqrt( x: int) -> int: - left, right = 0, x - while left < right: - mid = (left + right + 1) >> 1 - if mid <= x // mid: - left = mid - else: - right = mid - 1 - return left","def sample_funcname ( var_0 : int ) -> int : - var_3 , var_4 = 0 , var_0 - while var_3 < var_4 : - var_6 = ( var_3 + var_4 + 1 ) >> 1 - if var_6 <= var_0 // var_6 : - var_3 = var_6 - else : - var_4 = var_6 - 1 - return var_3 -",10,2 -1016,0682.Baseball Game_1.py,"def calPoints( ops: List[str]) -> int: - stk = [] - for op in ops: - if op == '+': - stk.append(stk[-1] + stk[-2]) - elif op == 'D': - stk.append(stk[-1] << 1) - elif op == 'C': - stk.pop() - else: - stk.append(int(op)) - return sum(stk)","def sample_funcname ( var_0 : List [ str ] ) -> int : - var_4 = [ ] - for var_5 in var_0 : - if var_5 == '+' : - var_4.append ( var_4 [ - 1 ] + var_4 [ - 2 ] ) - elif var_5 == 'D' : - var_4.append ( var_4 [ - 1 ] << 1 ) - elif var_5 == 'C' : - var_4.pop ( ) - else : - var_4.append ( int ( var_5 ) ) - return sum ( var_4 ) -",+21DC,5 -1017,0748.Shortest Completing Word_2.py,"def count(word): - counter = [0] * 26 - for c in word: - counter[ord(c) - ord('a')] += 1 - return counter","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * 26 - for var_4 in var_0 : - var_3 [ ord ( var_4 ) - ord ( 'a' ) ] += 1 - return var_3 -",a0126,4 -1018,1456.Maximum Number of Vowels in a Substring of Given Length_1.py,"def maxVowels( s: str, k: int) -> int: - vowels = set('aeiou') - t = sum(c in vowels for c in s[:k]) - ans = t - for i in range(k, len(s)): - t += s[i] in vowels - t -= s[i - k] in vowels - ans = max(ans, t) - return ans","def sample_funcname ( var_0 : str , var_2 : int ) -> int : - var_6 = set ( 'aeiou' ) - var_9 = sum ( var_8 in var_6 for var_8 in var_0 [ : var_2 ] ) - var_10 = var_9 - for var_13 in range ( var_2 , len ( var_0 ) ) : - var_9 += var_0 [ var_13 ] in var_6 - var_9 -= var_0 [ var_13 - var_2 ] in var_6 - var_10 = max ( var_10 , var_9 ) - return var_10 -",aeiou,1 -1019,1004.Max Consecutive Ones III_1.py,"def longestOnes( nums: List[int], k: int) -> int: - l = r = -1 - while r < len(nums) - 1: - r += 1 - if nums[r] == 0: - k -= 1 - if k < 0: - l += 1 - if nums[l] == 0: - k += 1 - return r - l","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_6 = var_4 = - 1 - while var_4 < len ( var_0 ) - 1 : - var_4 += 1 - if var_0 [ var_4 ] == 0 : - var_3 -= 1 - if var_3 < 0 : - var_6 += 1 - if var_0 [ var_6 ] == 0 : - var_3 += 1 - return var_4 - var_6 -",10,2 -1020,0396.Rotate Function_1.py,"def maxRotateFunction( nums: List[int]) -> int: - f = sum(i * v for i, v in enumerate(nums)) - n, s = len(nums), sum(nums) - ans = f - for i in range(1, n): - f = f + s - n * nums[n - i] - ans = max(ans, f) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_7 = sum ( var_4 * var_5 for var_4 , var_5 in enumerate ( var_0 ) ) - var_9 , var_10 = len ( var_0 ) , sum ( var_0 ) - var_11 = var_7 - for var_4 in range ( 1 , var_9 ) : - var_7 = var_7 + var_10 - var_9 * var_0 [ var_9 - var_4 ] - var_11 = max ( var_11 , var_7 ) - return var_11 -",1,1 -1022,0715.Range Module_1.py,"def pushup( node): - node.v = bool(node.left and node.left.v and node.right and node.right.v)","def sample_funcname ( var_0 ) : - var_0.v = bool ( var_0.left and var_0.left.v and var_0.right and var_0.right.v ) -",,0 -1023,0339.Nested List Weight Sum_1.py,"def dfs(nestedList, depth): - depth_sum = 0 - for item in nestedList: - if item.isInteger(): - depth_sum += item.getInteger() * depth - else: - depth_sum += dfs(item.getList(), depth + 1) - return depth_sum","def sample_funcname ( var_1 , var_2 ) : - var_4 = 0 - for var_5 in var_1 : - if var_5.isInteger ( ) : - var_4 += var_5.getInteger ( ) * var_2 - else : - var_4 += var_0 ( var_5.getList ( ) , var_2 + 1 ) - return var_4 -",10,2 -1024,2319.Check if Matrix Is X-Matrix_1.py,"def checkXMatrix( grid: List[List[int]]) -> bool: - n = len(grid) - for i, row in enumerate(grid): - for j, v in enumerate(row): - if i == j or i == n - j - 1: - if v == 0: - return False - elif v: - return False - return True","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> bool : - var_5 = len ( var_0 ) - for var_7 , var_8 in enumerate ( var_0 ) : - for var_9 , var_10 in enumerate ( var_8 ) : - if var_7 == var_9 or var_7 == var_5 - var_9 - 1 : - if var_10 == 0 : - return False - elif var_10 : - return False - return True -",10,2 -1025,0026.Remove Duplicates from Sorted Array_1.py,"def removeDuplicates( nums: List[int]) -> int: - i = 0 - for num in nums: - if i < 1 or num != nums[i - 1]: - nums[i] = num - i += 1 - return i","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 0 - for var_5 in var_0 : - if var_4 < 1 or var_5 != var_0 [ var_4 - 1 ] : - var_0 [ var_4 ] = var_5 - var_4 += 1 - return var_4 -",10,2 -1026,1740.Find Distance in a Binary Tree_2.py,"def lca(root, p, q): - if root is None or root.val in [p, q]: - return root - left = lca(root.left, p, q) - right = lca(root.right, p, q) - if left is None: - return right - if right is None: - return left - return root","def sample_funcname ( var_1 , var_2 , var_3 ) : - if var_1 is None or var_1.val in [ var_2 , var_3 ] : - return var_1 - left = var_0 ( var_1.left , var_2 , var_3 ) - right = var_0 ( var_1.right , var_2 , var_3 ) - if left is None : - return right - if right is None : - return left - return var_1 -",None,1 -1027,2135.Count Words Obtained After Adding a Letter_1.py,"def wordCount( startWords: List[str], targetWords: List[str]) -> int: - s = set() - for word in startWords: - mask = 0 - for c in word: - mask |= 1 << (ord(c) - ord('a')) - s.add(mask) - - ans = 0 - for word in targetWords: - mask = 0 - for c in word: - mask |= 1 << (ord(c) - ord('a')) - for c in word: - t = mask ^ (1 << (ord(c) - ord('a'))) - if t in s: - ans += 1 - break - return ans","def sample_funcname ( var_0 : List [ str ] , var_3 : List [ str ] ) -> int : - var_6 = set ( ) - for var_7 in var_0 : - var_9 = 0 - for var_10 in var_7 : - var_9 |= 1 << ( ord ( var_10 ) - ord ( 'a' ) ) - var_6.add ( var_9 ) - var_15 = 0 - for var_7 in var_3 : - var_9 = 0 - for var_10 in var_7 : - var_9 |= 1 << ( ord ( var_10 ) - ord ( 'a' ) ) - for var_10 in var_7 : - var_16 = var_9 ^ ( 1 << ( ord ( var_10 ) - ord ( 'a' ) ) ) - if var_16 in var_6 : - var_15 += 1 - break - return var_15 -",10a,3 -1028,2396.Strictly Palindromic Number_1.py,"def isStrictlyPalindromic( n: int) -> bool: - return False","def sample_funcname ( var_0 : int ) -> bool : - return False -",,0 -1030,0088.Merge Sorted Array_1.py,"def merge( nums1: List[int], m: int, nums2: List[int], n: int) -> None: - i, j, k = m - 1, n - 1, m + n - 1 - while j >= 0: - if i >= 0 and nums1[i] > nums2[j]: - nums1[k] = nums1[i] - i -= 1 - else: - nums1[k] = nums2[j] - j -= 1 - k -= 1","def sample_funcname ( var_0 : List [ int ] , var_3 : int , var_4 : List [ int ] , var_5 : int ) -> None : - var_8 , var_9 , var_10 = var_3 - 1 , var_5 - 1 , var_3 + var_5 - 1 - while var_9 >= 0 : - if var_8 >= 0 and var_0 [ var_8 ] > var_4 [ var_9 ] : - var_0 [ var_10 ] = var_0 [ var_8 ] - var_8 -= 1 - else : - var_0 [ var_10 ] = var_4 [ var_9 ] - var_9 -= 1 - var_10 -= 1 -",1None0,3 -1031,1518.Water Bottles_1.py,"def numWaterBottles( numBottles: int, numExchange: int) -> int: - ans = numBottles - while numBottles >= numExchange: - numBottles -= numExchange - 1 - ans += 1 - return ans","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_3 = var_0 - while var_0 >= var_2 : - var_0 -= var_2 - 1 - var_3 += 1 - return var_3 -",1,1 -1032,2216.Minimum Deletions to Make Array Beautiful_1.py,"def minDeletion( nums: List[int]) -> int: - n = len(nums) - i = ans = 0 - while i < n - 1: - if nums[i] == nums[i + 1]: - ans += 1 - i += 1 - else: - i += 2 - if (n - ans) % 2: - ans += 1 - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_7 = var_5 = 0 - while var_7 < var_4 - 1 : - if var_0 [ var_7 ] == var_0 [ var_7 + 1 ] : - var_5 += 1 - var_7 += 1 - else : - var_7 += 2 - if ( var_4 - var_5 ) % 2 : - var_5 += 1 - return var_5 -",102,3 -1033,0852.Peak Index in a Mountain Array_1.py,"def peakIndexInMountainArray( arr: List[int]) -> int: - left, right = 1, len(arr) - 2 - while left < right: - mid = (left + right) >> 1 - if arr[mid] > arr[mid + 1]: - right = mid - else: - left = mid + 1 - return left","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_7 = 1 , len ( var_0 ) - 2 - while var_4 < var_7 : - var_8 = ( var_4 + var_7 ) >> 1 - if var_0 [ var_8 ] > var_0 [ var_8 + 1 ] : - var_7 = var_8 - else : - var_4 = var_8 + 1 - return var_4 -",12,2 -1034,1380.Lucky Numbers in a Matrix_1.py,"def luckyNumbers( matrix: List[List[int]]) -> List[int]: - rows = {min(row) for row in matrix} - cols = {max(col) for col in zip(*matrix)} - return list(rows & cols)","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ int ] : - var_5 = { min ( var_4 ) for var_4 in var_0 } - var_9 = { max ( var_7 ) for var_7 in zip ( * var_0 ) } - return list ( var_5 & var_9 ) -",,0 -1036,0406.Queue Reconstruction by Height_1.py,"def reconstructQueue( people: List[List[int]]) -> List[List[int]]: - people.sort(key=lambda x: (-x[0], x[1])) - ans = [] - for p in people: - ans.insert(p[1], p) - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ List [ int ] ] : - var_0.sort ( var_4 = lambda var_5 : ( - var_5 [ 0 ] , var_5 [ 1 ] ) ) - var_8 = [ ] - for var_9 in var_0 : - var_8.insert ( var_9 [ 1 ] , var_9 ) - return var_8 -",10,2 -1037,1829.Maximum XOR for Each Query_1.py,"def getMaximumXor( nums: List[int], maximumBit: int) -> List[int]: - n = len(nums) - s = [0] * (n + 1) - for i, x in enumerate(nums): - s[i + 1] = s[i] ^ x - ans = [] - for x in s[:0:-1]: - t = 0 - for i in range(maximumBit): - if ((x >> i) & 1) == 0: - t |= 1 << i - ans.append(t) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_5 = len ( var_0 ) - var_8 = [ 0 ] * ( var_5 + 1 ) - for var_10 , var_11 in enumerate ( var_0 ) : - var_8 [ var_10 + 1 ] = var_8 [ var_10 ] ^ var_11 - var_12 = [ ] - for var_11 in var_8 [ : 0 : - 1 ] : - var_13 = 0 - for var_10 in range ( var_3 ) : - if ( ( var_11 >> var_10 ) & 1 ) == 0 : - var_13 |= 1 << var_10 - var_12.append ( var_13 ) - return var_12 -",10,2 -1038,1103.Distribute Candies to People_1.py,"def distributeCandies( candies: int, num_people: int) -> List[int]: - ans = [0] * num_people - i = 0 - while candies > 0: - ans[i % num_people] += min(candies, i + 1) - candies -= min(candies, i + 1) - i += 1 - return ans","def sample_funcname ( var_0 : int , var_2 : int ) -> List [ int ] : - var_5 = [ 0 ] * var_2 - var_6 = 0 - while var_0 > 0 : - var_5 [ var_6 % var_2 ] += min ( var_0 , var_6 + 1 ) - var_0 -= min ( var_0 , var_6 + 1 ) - var_6 += 1 - return var_5 -",10,2 -1039,0259.3Sum Smaller_1.py,"def threeSumSmaller( nums: List[int], target: int) -> int: - nums.sort() - ans, n = 0, len(nums) - for i in range(n): - j, k = i + 1, n - 1 - while j < k: - s = nums[i] + nums[j] + nums[k] - if s >= target: - k -= 1 - else: - ans += k - j - j += 1 - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_0.sort ( ) - var_6 , var_8 = 0 , len ( var_0 ) - for var_10 in range ( var_8 ) : - var_12 , var_13 = var_10 + 1 , var_8 - 1 - while var_12 < var_13 : - var_14 = var_0 [ var_10 ] + var_0 [ var_12 ] + var_0 [ var_13 ] - if var_14 >= var_3 : - var_13 -= 1 - else : - var_6 += var_13 - var_12 - var_12 += 1 - return var_6 -",10,2 -1040,1689.Partitioning Into Minimum Number Of Deci-Binary Numbers_1.py,"def minPartitions( n: str) -> int: - return int(max(n))","def sample_funcname ( var_0 : str ) -> int : - return int ( max ( var_0 ) ) -",,0 -1042,0867.Transpose Matrix_1.py,"def transpose( matrix: List[List[int]]) -> List[List[int]]: - return list(zip(*matrix))","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ List [ int ] ] : - return list ( zip ( * var_0 ) ) -",,0 -1043,0027.Remove Element_1.py,"def removeElement( nums: List[int], val: int) -> int: - cnt, n = 0, len(nums) - for i in range(n): - if nums[i] == val: - cnt += 1 - else: - nums[i - cnt] = nums[i] - return n - cnt","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_7 = 0 , len ( var_0 ) - for var_9 in range ( var_7 ) : - if var_0 [ var_9 ] == var_3 : - var_5 += 1 - else : - var_0 [ var_9 - var_5 ] = var_0 [ var_9 ] - return var_7 - var_5 -",10,2 -1044,0905.Sort Array By Parity_1.py,"def sortArrayByParity( nums: List[int]) -> List[int]: - i, j = 0, len(nums) - 1 - while i < j: - if nums[i] & 1: - nums[i], nums[j] = nums[j], nums[i] - j -= 1 - else: - i += 1 - return nums","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 , var_7 = 0 , len ( var_0 ) - 1 - while var_4 < var_7 : - if var_0 [ var_4 ] & 1 : - var_0 [ var_4 ] , var_0 [ var_7 ] = var_0 [ var_7 ] , var_0 [ var_4 ] - var_7 -= 1 - else : - var_4 += 1 - return var_0 -",10,2 -1045,1457.Pseudo-Palindromic Paths in a Binary Tree_1.py,"def dfs(root): - if root is None: - return - nonlocal ans, counter - counter[root.val] += 1 - if root.left is None and root.right is None: - if sum(1 for i in range(1, 10) if counter[i] % 2 == 1) < 2: - ans += 1 - else: - dfs(root.left) - dfs(root.right) - counter[root.val] -= 1","def sample_funcname ( var_1 ) : - if var_1 is None : - return - nonlocal var_3 , var_4 - var_4 [ var_1.val ] += 1 - if var_1.left is None and var_1.right is None : - if sum ( 1 for var_12 in range ( 1 , 10 ) if var_4 [ var_12 ] % 2 == 1 ) < 2 : - var_3 += 1 - else : - var_0 ( var_1.left ) - var_0 ( var_1.right ) - var_4 [ var_1.val ] -= 1 -",101None2,4 -1046,1567.Maximum Length of Subarray With Positive Product_1.py,"def getMaxLen( nums: List[int]) -> int: - f1 = 1 if nums[0] > 0 else 0 - f2 = 1 if nums[0] < 0 else 0 - res = f1 - for num in nums[1:]: - pf1, pf2 = f1, f2 - if num > 0: - f1 += 1 - if f2 > 0: - f2 += 1 - else: - f2 = 0 - elif num < 0: - pf1, pf2 = f1, f2 - f2 = pf1 + 1 - if pf2 > 0: - f1 = pf2 + 1 - else: - f1 = 0 - else: - f1 = 0 - f2 = 0 - res = max(res, f1) - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = 1 if var_0 [ 0 ] > 0 else 0 - var_6 = 1 if var_0 [ 0 ] < 0 else 0 - var_7 = var_5 - for var_8 in var_0 [ 1 : ] : - var_9 , var_10 = var_5 , var_6 - if var_8 > 0 : - var_5 += 1 - if var_6 > 0 : - var_6 += 1 - else : - var_6 = 0 - elif var_8 < 0 : - var_9 , var_10 = var_5 , var_6 - var_6 = var_9 + 1 - if var_10 > 0 : - var_5 = var_10 + 1 - else : - var_5 = 0 - else : - var_5 = 0 - var_6 = 0 - var_7 = max ( var_7 , var_5 ) - return var_7 -",10,2 -1047,2104.Sum of Subarray Ranges_1.py,"def f(nums): - stk = [] - n = len(nums) - left = [-1] * n - right = [n] * n - for i, v in enumerate(nums): - while stk and nums[stk[-1]] <= v: - stk.pop() - if stk: - left[i] = stk[-1] - stk.append(i) - stk = [] - for i in range(n - 1, -1, -1): - while stk and nums[stk[-1]] < nums[i]: - stk.pop() - if stk: - right[i] = stk[-1] - stk.append(i) - return sum((i - left[i]) * (right[i] - i) * v for i, v in enumerate(nums))","def sample_funcname ( var_0 ) : - var_1 = [ ] - var_3 = len ( var_0 ) - var_5 = [ - 1 ] * var_3 - var_6 = [ var_3 ] * var_3 - for var_8 , var_9 in enumerate ( var_0 ) : - while var_1 and var_0 [ var_1 [ - 1 ] ] <= var_9 : - var_1.pop ( ) - if var_1 : - var_5 [ var_8 ] = var_1 [ - 1 ] - var_1.append ( var_8 ) - var_1 = [ ] - for var_8 in range ( var_3 - 1 , - 1 , - 1 ) : - while var_1 and var_0 [ var_1 [ - 1 ] ] < var_0 [ var_8 ] : - var_1.pop ( ) - if var_1 : - var_6 [ var_8 ] = var_1 [ - 1 ] - var_1.append ( var_8 ) - return sum ( ( var_8 - var_5 [ var_8 ] ) * ( var_6 [ var_8 ] - var_8 ) * var_9 for var_8 , var_9 in enumerate ( var_0 ) ) -",1,1 -1048,0042.Trapping Rain Water_1.py,"def trap( height: List[int]) -> int: - n = len(height) - if n < 3: - return 0 - - lmx, rmx = [height[0]] * n, [height[n - 1]] * n - for i in range(1, n): - lmx[i] = max(lmx[i - 1], height[i]) - rmx[n - 1 - i] = max(rmx[n - i], height[n - 1 - i]) - - res = 0 - for i in range(n): - res += min(lmx[i], rmx[i]) - height[i] - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - if var_4 < 3 : - return 0 - var_7 , var_9 = [ var_0 [ 0 ] ] * var_4 , [ var_0 [ var_4 - 1 ] ] * var_4 - for var_11 in range ( 1 , var_4 ) : - var_7 [ var_11 ] = max ( var_7 [ var_11 - 1 ] , var_0 [ var_11 ] ) - var_9 [ var_4 - 1 - var_11 ] = max ( var_9 [ var_4 - var_11 ] , var_0 [ var_4 - 1 - var_11 ] ) - var_13 = 0 - for var_11 in range ( var_4 ) : - var_13 += min ( var_7 [ var_11 ] , var_9 [ var_11 ] ) - var_0 [ var_11 ] - return var_13 -",130,3 -1049,2108.Find First Palindromic String in the Array_1.py,"def check(s): - i, j = 0, len(s) - 1 - while i < j: - if s[i] != s[j]: - return False - i += 1 - j -= 1 - return True","def sample_funcname ( var_0 ) : - var_2 , var_5 = 0 , len ( var_0 ) - 1 - while var_2 < var_5 : - if var_0 [ var_2 ] != var_0 [ var_5 ] : - return False - var_2 += 1 - var_5 -= 1 - return True -",10,2 -1050,0865.Smallest Subtree with all the Deepest Nodes_1.py,"def dfs(root): - if root is None: - return None, 0 - l, d1 = dfs(root.left) - r, d2 = dfs(root.right) - if d1 > d2: - return l, d1 + 1 - if d1 < d2: - return r, d2 + 1 - return root, d1 + 1","def sample_funcname ( var_1 ) : - if var_1 is None : - return None , 0 - var_4 , var_6 = var_0 ( var_1.left ) - var_7 , var_9 = var_0 ( var_1.right ) - if var_6 > var_9 : - return var_4 , var_6 + 1 - if var_6 < var_9 : - return var_7 , var_9 + 1 - return var_1 , var_6 + 1 -",10None,3 -1051,2089.Find Target Indices After Sorting Array_1.py,"def targetIndices( nums: List[int], target: int) -> List[int]: - nums.sort() - return [i for i, num in enumerate(nums) if num == target]","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_0.sort ( ) - return [ var_5 for var_5 , var_7 in enumerate ( var_0 ) if var_7 == var_3 ] -",,0 -1052,0883.Projection Area of 3D Shapes_1.py,"def projectionArea( grid: List[List[int]]) -> int: - xy = sum(v > 0 for row in grid for v in row) - yz = sum(max(row) for row in grid) - zx = sum(max(col) for col in zip(*grid)) - return xy + yz + zx","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_7 = sum ( var_4 > 0 for var_6 in var_0 for var_4 in var_6 ) - var_9 = sum ( max ( var_6 ) for var_6 in var_0 ) - var_12 = sum ( max ( var_10 ) for var_10 in zip ( * var_0 ) ) - return var_7 + var_9 + var_12 -",0,1 -1053,2074.Reverse Nodes in Even Length Groups_1.py,"def reverse(head, l): - prev, cur, tail = None, head, head - i = 0 - while cur and i < l: - t = cur.next - cur.next = prev - prev = cur - cur = t - i += 1 - tail.next = cur - return prev","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_4 , var_5 = None , var_0 , var_0 - var_7 = 0 - while var_4 and var_7 < var_1 : - var_9 = var_4.next - var_4.next = var_3 - var_3 = var_4 - var_4 = var_9 - var_7 += 1 - var_5.next = var_4 - return var_3 -",10None,3 -1054,1324.Print Words Vertically_1.py,"def printVertically( s: str) -> List[str]: - words = s.split() - m, n = len(words), max(len(word) for word in words) - ans = [] - for j in range(n): - t = [] - for i in range(m): - word = words[i] - t.append(word[j] if j < len(word) else ' ') - ans.append(''.join(t).rstrip()) - return ans","def sample_funcname ( var_0 : str ) -> List [ str ] : - var_4 = var_0.split ( ) - var_6 , var_9 = len ( var_4 ) , max ( len ( var_8 ) for var_8 in var_4 ) - var_10 = [ ] - for var_12 in range ( var_9 ) : - var_13 = [ ] - for var_14 in range ( var_6 ) : - var_8 = var_4 [ var_14 ] - var_13.append ( var_8 [ var_12 ] if var_12 < len ( var_8 ) else '' ) - var_10.append ( ''.var_18 ( var_13 ).rstrip ( ) ) - return var_10 -",,1 -1055,1968.Array With Elements Not Equal to Average of Neighbors_1.py,"def rearrangeArray( nums: List[int]) -> List[int]: - nums.sort() - n = len(nums) - m = (n + 1) >> 1 - ans = [] - for i in range(m): - ans.append(nums[i]) - if i + m < n: - ans.append(nums[i + m]) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_0.sort ( ) - var_5 = len ( var_0 ) - var_7 = ( var_5 + 1 ) >> 1 - var_8 = [ ] - for var_10 in range ( var_7 ) : - var_8.append ( var_0 [ var_10 ] ) - if var_10 + var_7 < var_5 : - var_8.append ( var_0 [ var_10 + var_7 ] ) - return var_8 -",1,1 -1056,1798.Maximum Number of Consecutive Values You Can Make_1.py,"def getMaximumConsecutive( coins: List[int]) -> int: - res = 1 - for coin in sorted(coins): - if coin > res: - break - res += coin - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 1 - for var_6 in sorted ( var_0 ) : - if var_6 > var_4 : - break - var_4 += var_6 - return var_4 -",1,1 -1057,1436.Destination City_1.py,"def destCity( paths: List[List[str]]) -> str: - s = {a for a, _ in paths} - return next(b for _, b in paths if b not in s)","def sample_funcname ( var_0 : List [ List [ str ] ] ) -> str : - var_5 = { var_3 for var_3 , var_4 in var_0 } - return next ( var_7 for var_4 , var_7 in var_0 if var_7 not in var_5 ) -",,0 -1058,1957.Delete Characters to Make Fancy String_1.py,"def makeFancyString( s: str) -> str: - ans = [] - for c in s: - if len(ans) > 1 and ans[-1] == ans[-2] == c: - continue - ans.append(c) - return ''.join(ans)","def sample_funcname ( var_0 : str ) -> str : - var_2 = [ ] - for var_3 in var_0 : - if len ( var_2 ) > 1 and var_2 [ - 1 ] == var_2 [ - 2 ] == var_3 : - continue - var_2.append ( var_3 ) - return ''.join ( var_2 ) -",12,3 -1059,1891.Cutting Ribbons_1.py,"def maxLength( ribbons: List[int], k: int) -> int: - low, high = 0, 100000 - while low < high: - mid = (low + high + 1) >> 1 - cnt = 0 - for ribbon in ribbons: - cnt += ribbon // mid - if cnt < k: - high = mid - 1 - else: - low = mid - return low","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_7 = 0 , 100000 - while var_5 < var_7 : - var_9 = ( var_5 + var_7 + 1 ) >> 1 - var_10 = 0 - for var_11 in var_0 : - var_10 += var_11 // var_9 - if var_10 < var_3 : - var_7 = var_9 - 1 - else : - var_5 = var_9 - return var_5 -",10100000,3 -1060,1628.Design an Expression Tree With Evaluate Function_1.py,"def evaluate() -> int: - pass","def sample_funcname ( ) -> int : - pass -",,0 -1061,1961.Check If String Is a Prefix of Array_1.py,"def isPrefixString( s: str, words: List[str]) -> bool: - t = 0 - for i, w in enumerate(words): - t += len(w) - if len(s) == t: - return ''.join(words[: i + 1]) == s - return False","def sample_funcname ( var_0 : str , var_2 : List [ str ] ) -> bool : - var_6 = 0 - for var_8 , var_9 in enumerate ( var_2 ) : - var_6 += len ( var_9 ) - if len ( var_0 ) == var_6 : - return ''.join ( var_2 [ : var_8 + 1 ] ) == var_0 - return False -",10,3 -1062,1461.Check If a String Contains All Binary Codes of Size K_1.py,"def hasAllCodes( s: str, k: int) -> bool: - ss = {s[i : i + k] for i in range(len(s) - k + 1)} - return len(ss) == 1 << k","def sample_funcname ( var_0 : str , var_2 : int ) -> bool : - var_9 = { var_0 [ var_5 : var_5 + var_2 ] for var_5 in range ( len ( var_0 ) - var_2 + 1 ) } - return len ( var_9 ) == 1 << var_2 -",1,1 -1063,0697.Degree of an Array_1.py,"def findShortestSubArray( nums: List[int]) -> int: - mapper = {} - for i, v in enumerate(nums): - if v in mapper: - arr = mapper[v] - arr[0] += 1 - arr[2] = i - else: - arr = [1, i, i] - mapper[v] = arr - max_degree = min_len = 0 - for arr in mapper.values(): - if max_degree < arr[0]: - max_degree = arr[0] - min_len = arr[2] - arr[1] + 1 - elif max_degree == arr[0]: - min_len = min(min_len, arr[2] - arr[1] + 1) - return min_len","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_3 = { } - for var_5 , var_6 in enumerate ( var_0 ) : - if var_6 in var_3 : - var_7 = var_3 [ var_6 ] - var_7 [ 0 ] += 1 - var_7 [ 2 ] = var_5 - else : - var_7 = [ 1 , var_5 , var_5 ] - var_3 [ var_6 ] = var_7 - var_12 = var_11 = 0 - for var_7 in var_3.values ( ) : - if var_12 < var_7 [ 0 ] : - var_12 = var_7 [ 0 ] - var_11 = var_7 [ 2 ] - var_7 [ 1 ] + 1 - elif var_12 == var_7 [ 0 ] : - var_11 = min ( var_11 , var_7 [ 2 ] - var_7 [ 1 ] + 1 ) - return var_11 -",102,3 -1064,0280.Wiggle Sort_1.py,"def wiggleSort( nums: List[int]) -> None: - for i in range(1, len(nums)): - if (i % 2 == 1 and nums[i] < nums[i - 1]) or ( - i % 2 == 0 and nums[i] > nums[i - 1] - ): - nums[i], nums[i - 1] = nums[i - 1], nums[i]","def sample_funcname ( var_0 : List [ int ] ) -> None : - for var_7 in range ( 1 , len ( var_0 ) ) : - if ( var_7 % 2 == 1 and var_0 [ var_7 ] < var_0 [ var_7 - 1 ] ) or ( var_7 % 2 == 0 and var_0 [ var_7 ] > var_0 [ var_7 - 1 ] ) : - var_0 [ var_7 ] , var_0 [ var_7 - 1 ] = var_0 [ var_7 - 1 ] , var_0 [ var_7 ] -",1None02,4 -1065,1874.Minimize Product Sum of Two Arrays_1.py,"def minProductSum( nums1: List[int], nums2: List[int]) -> int: - nums1.sort() - nums2.sort() - n, res = len(nums1), 0 - for i in range(n): - res += nums1[i] * nums2[n - i - 1] - return res","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_0.sort ( ) - var_3.sort ( ) - var_6 , var_8 = len ( var_0 ) , 0 - for var_10 in range ( var_6 ) : - var_8 += var_0 [ var_10 ] * var_3 [ var_6 - var_10 - 1 ] - return var_8 -",10,2 -1066,2079.Watering Plants_1.py,"def wateringPlants( plants: List[int], capacity: int) -> int: - ans, cap = 0, capacity - for i, x in enumerate(plants): - if cap >= x: - cap -= x - ans += 1 - else: - cap = capacity - x - ans += i * 2 + 1 - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_6 = 0 , var_3 - for var_8 , var_9 in enumerate ( var_0 ) : - if var_6 >= var_9 : - var_6 -= var_9 - var_5 += 1 - else : - var_6 = var_3 - var_9 - var_5 += var_8 * 2 + 1 - return var_5 -",102,3 -1067,1807.Evaluate the Bracket Pairs of a String_1.py,"def find_right_bracket(s, start, end): - for i in range(start, end): - if s[i] == ')': - return i","def sample_funcname ( var_0 , var_1 , var_2 ) : - for var_4 in range ( var_1 , var_2 ) : - if var_0 [ var_4 ] == ')' : - return var_4 -",),1 -1068,0683.K Empty Slots_1.py,"def lowbit(x): - return x & -x","def sample_funcname ( var_0 ) : - return var_0 & - var_0 -",,0 -1069,2373.Largest Local Values in a Matrix_1.py,"def largestLocal( grid: List[List[int]]) -> List[List[int]]: - n = len(grid) - ans = [[0] * (n - 2) for _ in range(n - 2)] - for i in range(n - 2): - for j in range(n - 2): - ans[i][j] = max( - grid[x][y] for x in range(i, i + 3) for y in range(j, j + 3) - ) - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ List [ int ] ] : - var_4 = len ( var_0 ) - var_9 = [ [ 0 ] * ( var_4 - 2 ) for var_7 in range ( var_4 - 2 ) ] - for var_10 in range ( var_4 - 2 ) : - for var_11 in range ( var_4 - 2 ) : - var_9 [ var_10 ] [ var_11 ] = max ( var_0 [ var_15 ] [ var_13 ] for var_15 in range ( var_10 , var_10 + 3 ) for var_13 in range ( var_11 , var_11 + 3 ) ) - return var_9 -",302,3 -1070,0322.Coin Change_1.py,"def coinChange( coins: List[int], amount: int) -> int: - dp = [amount + 1] * (amount + 1) - dp[0] = 0 - for coin in coins: - for j in range(coin, amount + 1): - dp[j] = min(dp[j], dp[j - coin] + 1) - return -1 if dp[-1] > amount else dp[-1]","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 = [ var_3 + 1 ] * ( var_3 + 1 ) - var_5 [ 0 ] = 0 - for var_7 in var_0 : - for var_9 in range ( var_7 , var_3 + 1 ) : - var_5 [ var_9 ] = min ( var_5 [ var_9 ] , var_5 [ var_9 - var_7 ] + 1 ) - return - 1 if var_5 [ - 1 ] > var_3 else var_5 [ - 1 ] -",10,2 -1071,0565.Array Nesting_1.py,"def arrayNesting( nums: List[int]) -> int: - ans, n = 0, len(nums) - for i in range(n): - cnt = 0 - while nums[i] != n: - j = nums[i] - nums[i] = n - i = j - cnt += 1 - ans = max(ans, cnt) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_6 = 0 , len ( var_0 ) - for var_8 in range ( var_6 ) : - var_9 = 0 - while var_0 [ var_8 ] != var_6 : - var_10 = var_0 [ var_8 ] - var_0 [ var_8 ] = var_6 - var_8 = var_10 - var_9 += 1 - var_4 = max ( var_4 , var_9 ) - return var_4 -",10,2 -1072,1267.Count Servers that Communicate_1.py,"def countServers( grid: List[List[int]]) -> int: - m, n = len(grid), len(grid[0]) - rows = [0] * m - cols = [0] * n - for i in range(m): - for j in range(n): - if grid[i][j] == 1: - rows[i] += 1 - cols[j] += 1 - res = 0 - for i in range(m): - for j in range(n): - if grid[i][j] == 1: - if rows[i] > 1 or cols[j] > 1: - res += 1 - return res","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_7 = [ 0 ] * var_4 - var_8 = [ 0 ] * var_6 - for var_10 in range ( var_4 ) : - for var_11 in range ( var_6 ) : - if var_0 [ var_10 ] [ var_11 ] == 1 : - var_7 [ var_10 ] += 1 - var_8 [ var_11 ] += 1 - var_13 = 0 - for var_10 in range ( var_4 ) : - for var_11 in range ( var_6 ) : - if var_0 [ var_10 ] [ var_11 ] == 1 : - if var_7 [ var_10 ] > 1 or var_8 [ var_11 ] > 1 : - var_13 += 1 - return var_13 -",10,2 -1073,0563.Binary Tree Tilt_1.py,"def sum(root): - if root is None: - return 0 - nonlocal ans - left = sum(root.left) - right = sum(root.right) - ans += abs(left - right) - return root.val + left + right","def sample_funcname ( var_1 ) : - if var_1 is None : - return 0 - nonlocal var_4 - left = var_0 ( var_1.left ) - right = var_0 ( var_1.right ) - var_4 += abs ( left - right ) - return var_1.val + left + right -",0None,2 -1074,2239.Find Closest Number to Zero_1.py,"def findClosestNumber( nums: List[int]) -> int: - ans, d = 0, 1000000 - for v in nums: - if (t := abs(v)) < d or (t == d and v > ans): - ans, d = v, t - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_6 = 0 , 1000000 - for var_7 in var_0 : - if ( var_8 := abs ( var_7 ) ) < var_6 or ( var_8 == var_6 and var_7 > var_4 ) : - var_4 , var_6 = var_7 , var_8 - return var_4 -",01000000,2 -1075,0222.Count Complete Tree Nodes_1.py,"def depth(root): - res = 0 - while root: - res += 1 - root = root.left - return res","def sample_funcname ( var_0 ) : - var_2 = 0 - while var_0 : - var_2 += 1 - var_0 = var_0.left - return var_2 -",10,2 -1076,2169.Count Operations to Obtain Zero_1.py,"def countOperations( num1: int, num2: int) -> int: - ans = 0 - while num1 and num2: - if num1 >= num2: - num1, num2 = num2, num1 - num2 -= num1 - ans += 1 - return ans","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_4 = 0 - while var_0 and var_2 : - if var_0 >= var_2 : - var_0 , var_2 = var_2 , var_0 - var_2 -= var_0 - var_4 += 1 - return var_4 -",10,2 -1077,0020.Valid Parentheses_1.py,"def isValid( s: str) -> bool: - q = [] - parentheses = {'()', '[]', '{}'} - for ch in s: - if ch in '([{': - q.append(ch) - elif not q or q.pop() + ch not in parentheses: - return False - return not q","def sample_funcname ( var_0 : str ) -> bool : - var_3 = [ ] - var_7 = { '()' , '[]' , '{}' } - for var_8 in var_0 : - if var_8 in '([{' : - var_3.append ( var_8 ) - elif not var_3 or var_3.pop ( ) + var_8 not in var_7 : - return False - return not var_3 -",([{{}()[],4 -1078,0498.Diagonal Traverse_1.py,"def findDiagonalOrder( mat: List[List[int]]) -> List[int]: - m, n = len(mat), len(mat[0]) - ans = [] - for k in range(m + n - 1): - t = [] - i = 0 if k < n else k - n + 1 - j = k if k < n else n - 1 - while i < m and j >= 0: - t.append(mat[i][j]) - i += 1 - j -= 1 - if k % 2 == 0: - t = t[::-1] - ans.extend(t) - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ int ] : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_7 = [ ] - for var_10 in range ( var_4 + var_6 - 1 ) : - var_11 = [ ] - var_12 = 0 if var_10 < var_6 else var_10 - var_6 + 1 - var_13 = var_10 if var_10 < var_6 else var_6 - 1 - while var_12 < var_4 and var_13 >= 0 : - var_11.append ( var_0 [ var_12 ] [ var_13 ] ) - var_12 += 1 - var_13 -= 1 - if var_10 % 2 == 0 : - var_11 = var_11 [ : : - 1 ] - var_7.extend ( var_11 ) - return var_7 -",102,3 -1079,0364.Nested List Weight Sum II_2.py,"def max_depth(nestedList): - depth = 1 - for item in nestedList: - if item.isInteger(): - continue - depth = max(depth, max_depth(item.getList()) + 1) - return depth","def sample_funcname ( var_1 ) : - var_3 = 1 - for var_4 in var_1 : - if var_4.isInteger ( ) : - continue - var_3 = max ( var_3 , var_0 ( var_4.getList ( ) ) + 1 ) - return var_3 -",1,1 -1080,0036.Valid Sudoku_1.py,"def isValidSudoku( board: List[List[str]]) -> bool: - row = [[False] * 9 for _ in range(9)] - col = [[False] * 9 for _ in range(9)] - sub = [[False] * 9 for _ in range(9)] - for i in range(9): - for j in range(9): - c = board[i][j] - if c == '.': - continue - num = int(c) - 1 - k = i // 3 * 3 + j // 3 - if row[i][num] or col[j][num] or sub[k][num]: - return False - row[i][num] = True - col[j][num] = True - sub[k][num] = True - return True","def sample_funcname ( var_0 : List [ List [ str ] ] ) -> bool : - var_8 = [ [ False ] * 9 for var_6 in range ( 9 ) ] - var_9 = [ [ False ] * 9 for var_6 in range ( 9 ) ] - var_10 = [ [ False ] * 9 for var_6 in range ( 9 ) ] - for var_11 in range ( 9 ) : - for var_12 in range ( 9 ) : - var_13 = var_0 [ var_11 ] [ var_12 ] - if var_13 == '.' : - continue - var_17 = int ( var_13 ) - 1 - var_19 = var_11 // 3 * 3 + var_12 // 3 - if var_8 [ var_11 ] [ var_17 ] or var_9 [ var_12 ] [ var_17 ] or var_10 [ var_19 ] [ var_17 ] : - return False - var_8 [ var_11 ] [ var_17 ] = True - var_9 [ var_12 ] [ var_17 ] = True - var_10 [ var_19 ] [ var_17 ] = True - return True -",931.,4 -1081,2114.Maximum Number of Words Found in Sentences_1.py,"def mostWordsFound( sentences: List[str]) -> int: - return 1 + max(s.count(' ') for s in sentences)","def sample_funcname ( var_0 : List [ str ] ) -> int : - return 1 + max ( var_6.count ( ' ' ) for var_6 in var_0 ) -",1 ,2 -1082,0566.Reshape the Matrix_1.py,"def matrixReshape( nums: List[List[int]], r: int, c: int) -> List[List[int]]: - m, n = len(nums), len(nums[0]) - if m * n != r * c: - return nums - res = [[0] * c for _ in range(r)] - for x in range(m * n): - res[x // c][x % c] = nums[x // n][x % n] - return res","def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : int , var_4 : int ) -> List [ List [ int ] ] : - var_6 , var_8 = len ( var_0 ) , len ( var_0 [ 0 ] ) - if var_6 * var_8 != var_3 * var_4 : - return var_0 - var_11 = [ [ 0 ] * var_4 for var_9 in range ( var_3 ) ] - for var_12 in range ( var_6 * var_8 ) : - var_11 [ var_12 // var_4 ] [ var_12 % var_4 ] = var_0 [ var_12 // var_8 ] [ var_12 % var_8 ] - return var_11 -",0,1 -1083,0152.Maximum Product Subarray_1.py,"def maxProduct( nums: List[int]) -> int: - maxf = minf = res = nums[0] - for num in nums[1:]: - m, n = maxf, minf - maxf = max(num, m * num, n * num) - minf = min(num, m * num, n * num) - res = max(res, maxf) - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_6 = var_3 = var_4 = var_0 [ 0 ] - for var_8 in var_0 [ 1 : ] : - var_9 , var_10 = var_6 , var_3 - var_6 = max ( var_8 , var_9 * var_8 , var_10 * var_8 ) - var_3 = min ( var_8 , var_9 * var_8 , var_10 * var_8 ) - var_4 = max ( var_4 , var_6 ) - return var_4 -",10,2 -1084,2127.Maximum Employees to Be Invited to a Meeting_1.py,"def max_cycle(fa): - n = len(fa) - vis = [False] * n - ans = 0 - for i in range(n): - if vis[i]: - continue - cycle = [] - j = i - while not vis[j]: - cycle.append(j) - vis[j] = True - j = fa[j] - for k, v in enumerate(cycle): - if v == j: - ans = max(ans, len(cycle) - k) - break - return ans","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_4 = [ False ] * var_2 - var_6 = 0 - for var_8 in range ( var_2 ) : - if var_4 [ var_8 ] : - continue - var_9 = [ ] - var_10 = var_8 - while not var_4 [ var_10 ] : - var_9.append ( var_10 ) - var_4 [ var_10 ] = True - var_10 = var_0 [ var_10 ] - for var_14 , var_15 in enumerate ( var_9 ) : - if var_15 == var_10 : - var_6 = max ( var_6 , len ( var_9 ) - var_14 ) - break - return var_6 -",0,1 -1085,1424.Diagonal Traverse II_1.py,"def findDiagonalOrder( nums: List[List[int]]) -> List[int]: - arr = [] - for i, row in enumerate(nums): - for j, v in enumerate(row): - arr.append((i + j, j, v)) - arr.sort() - return [v[2] for v in arr]","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ int ] : - var_3 = [ ] - for var_5 , var_6 in enumerate ( var_0 ) : - for var_7 , var_8 in enumerate ( var_6 ) : - var_3.append ( ( var_5 + var_7 , var_7 , var_8 ) ) - var_3.sort ( ) - return [ var_8 [ 2 ] for var_8 in var_3 ] -",2,1 -1087,1404.Number of Steps to Reduce a Number in Binary Representation to One_1.py,"def numSteps( s: str) -> int: - carry = False - ans = 0 - for c in s[:0:-1]: - if carry: - if c == '0': - c = '1' - carry = False - else: - c = '0' - if c == '1': - ans += 1 - carry = True - ans += 1 - if carry: - ans += 1 - return ans","def sample_funcname ( var_0 : str ) -> int : - var_4 = False - var_6 = 0 - for var_8 in var_0 [ : 0 : - 1 ] : - if var_4 : - if var_8 == '0' : - var_8 = '1' - var_4 = False - else : - var_8 = '0' - if var_8 == '1' : - var_6 += 1 - var_4 = True - var_6 += 1 - if var_4 : - var_6 += 1 - return var_6 -",1001,4 -1088,1796.Second Largest Digit in a String_1.py,"def secondHighest( s: str) -> int: - largest_digit = second_largest_digit = -1 - for c in s: - if c.isdigit(): - num = int(c) - if num > largest_digit: - second_largest_digit, largest_digit = largest_digit, num - elif num > second_largest_digit and num < largest_digit: - second_largest_digit = num - return second_largest_digit","def sample_funcname ( var_0 : str ) -> int : - var_5 = var_3 = - 1 - for var_6 in var_0 : - if var_6.isdigit ( ) : - var_8 = int ( var_6 ) - if var_8 > var_5 : - var_3 , var_5 = var_5 , var_8 - elif var_8 > var_3 and var_8 < var_5 : - var_3 = var_8 - return var_3 -",1,1 -1089,1374.Generate a String With Characters That Have Odd Counts_1.py,"def generateTheString( n: int) -> str: - return 'a' * n if n & 1 else 'a' * (n - 1) + 'b'","def sample_funcname ( var_0 : int ) -> str : - return 'a' * var_0 if var_0 & 1 else 'a' * ( var_0 - 1 ) + 'b' -",a1b,3 -1090,0376.Wiggle Subsequence_1.py,"def wiggleMaxLength( nums: List[int]) -> int: - up = down = 1 - for i in range(1, len(nums)): - if nums[i] > nums[i - 1]: - up = max(up, down + 1) - elif nums[i] < nums[i - 1]: - down = max(down, up + 1) - return max(up, down)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 1 - for var_8 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_8 ] > var_0 [ var_8 - 1 ] : - var_5 = max ( var_5 , var_3 + 1 ) - elif var_0 [ var_8 ] < var_0 [ var_8 - 1 ] : - var_3 = max ( var_3 , var_5 + 1 ) - return max ( var_5 , var_3 ) -",1,1 -1091,1967.Number of Strings That Appear as Substrings in Word_1.py,"def numOfStrings( patterns: List[str], word: str) -> int: - return sum(1 for p in patterns if p in word)","def sample_funcname ( var_0 : List [ str ] , var_3 : str ) -> int : - return sum ( 1 for var_7 in var_0 if var_7 in var_3 ) -",1,1 -1092,0718.Maximum Length of Repeated Subarray_1.py,"def findLength( nums1: List[int], nums2: List[int]) -> int: - m, n = len(nums1), len(nums2) - dp = [[0] * (n + 1) for _ in range(m + 1)] - ans = 0 - for i in range(1, m + 1): - for j in range(1, n + 1): - if nums1[i - 1] == nums2[j - 1]: - dp[i][j] = 1 + dp[i - 1][j - 1] - ans = max(ans, dp[i][j]) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_5 , var_6 = len ( var_0 ) , len ( var_3 ) - var_11 = [ [ 0 ] * ( var_6 + 1 ) for var_9 in range ( var_5 + 1 ) ] - var_12 = 0 - for var_13 in range ( 1 , var_5 + 1 ) : - for var_14 in range ( 1 , var_6 + 1 ) : - if var_0 [ var_13 - 1 ] == var_3 [ var_14 - 1 ] : - var_11 [ var_13 ] [ var_14 ] = 1 + var_11 [ var_13 - 1 ] [ var_14 - 1 ] - var_12 = max ( var_12 , var_11 [ var_13 ] [ var_14 ] ) - return var_12 -",10,2 -1093,0324.Wiggle Sort II_1.py,"def wiggleSort( nums: List[int]) -> None: - arr = sorted(nums) - n = len(arr) - i, j = (n - 1) >> 1, n - 1 - for k in range(n): - if k % 2 == 0: - nums[k] = arr[i] - i -= 1 - else: - nums[k] = arr[j] - j -= 1","def sample_funcname ( var_0 : List [ int ] ) -> None : - var_5 = sorted ( var_0 ) - var_7 = len ( var_5 ) - var_9 , var_10 = ( var_7 - 1 ) >> 1 , var_7 - 1 - for var_12 in range ( var_7 ) : - if var_12 % 2 == 0 : - var_0 [ var_12 ] = var_5 [ var_9 ] - var_9 -= 1 - else : - var_0 [ var_12 ] = var_5 [ var_10 ] - var_10 -= 1 -",1None02,4 -1094,1085.Sum of Digits in the Minimum Number_1.py,"def sumOfDigits( nums: List[int]) -> int: - x = min(nums) - s = 0 - while x: - s += x % 10 - x //= 10 - return 0 if s % 2 else 1","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = min ( var_0 ) - var_6 = 0 - while var_4 : - var_6 += var_4 % 10 - var_4 //= 10 - return 0 if var_6 % 2 else 1 -",10012,4 -1095,1860.Incremental Memory Leak_1.py,"def memLeak( memory1: int, memory2: int) -> List[int]: - i = 1 - while memory1 >= i or memory2 >= i: - if memory1 >= memory2: - memory1 -= i - else: - memory2 -= i - i += 1 - return [i, memory1, memory2]","def sample_funcname ( var_0 : int , var_2 : int ) -> List [ int ] : - var_5 = 1 - while var_0 >= var_5 or var_2 >= var_5 : - if var_0 >= var_2 : - var_0 -= var_5 - else : - var_2 -= var_5 - var_5 += 1 - return [ var_5 , var_0 , var_2 ] -",1,1 -1096,1790.Check if One String Swap Can Make Strings Equal_1.py,"def areAlmostEqual( s1: str, s2: str) -> bool: - cnt, n = 0, len(s1) - c1 = c2 = None - for i in range(n): - if s1[i] != s2[i]: - cnt += 1 - if (cnt == 2 and (s1[i] != c2 or s2[i] != c1)) or cnt > 2: - return False - c1, c2 = s1[i], s2[i] - return cnt == 0 or cnt == 2","def sample_funcname ( var_0 : str , var_2 : str ) -> bool : - var_5 , var_7 = 0 , len ( var_0 ) - var_10 = var_8 = None - for var_12 in range ( var_7 ) : - if var_0 [ var_12 ] != var_2 [ var_12 ] : - var_5 += 1 - if ( var_5 == 2 and ( var_0 [ var_12 ] != var_8 or var_2 [ var_12 ] != var_10 ) ) or var_5 > 2 : - return False - var_10 , var_8 = var_0 [ var_12 ] , var_2 [ var_12 ] - return var_5 == 0 or var_5 == 2 -",10None2,4 -1097,1553.Minimum Number of Days to Eat N Oranges_1.py,"def dfs(n): - if n < 2: - return n - return 1 + min(n % 2 + dfs(n // 2), n % 3 + dfs(n // 3))","def sample_funcname ( var_1 ) : - if var_1 < 2 : - return var_1 - return 1 + min ( var_1 % 2 + var_0 ( var_1 // 2 ) , var_1 % 3 + var_0 ( var_1 // 3 ) ) -",312,3 -1098,2390.Removing Stars From a String_1.py,"def removeStars( s: str) -> str: - stk = [] - for c in s: - if c == '*': - stk.pop() - else: - stk.append(c) - return ''.join(stk)","def sample_funcname ( var_0 : str ) -> str : - var_2 = [ ] - for var_3 in var_0 : - if var_3 == '*' : - var_2.pop ( ) - else : - var_2.append ( var_3 ) - return ''.join ( var_2 ) -",*,2 -1099,1946.Largest Number After Mutating Substring_1.py,"def maximumNumber( num: str, change: List[int]) -> str: - find = False - nums = list(num) - for i, c in enumerate(num): - if int(c) < change[int(c)]: - nums[i] = str(change[int(c)]) - find = True - elif find and int(c) == change[int(c)]: - continue - elif find: - break - return ''.join(nums)","def sample_funcname ( var_0 : str , var_2 : List [ int ] ) -> str : - var_6 = False - var_8 = list ( var_0 ) - for var_10 , var_11 in enumerate ( var_0 ) : - if int ( var_11 ) < var_2 [ int ( var_11 ) ] : - var_8 [ var_10 ] = str ( var_2 [ int ( var_11 ) ] ) - var_6 = True - elif var_6 and int ( var_11 ) == var_2 [ int ( var_11 ) ] : - continue - elif var_6 : - break - return ''.join ( var_8 ) -",,1 -1100,1165.Single-Row Keyboard_1.py,"def calculateTime( keyboard: str, word: str) -> int: - index = {c: i for i, c in enumerate(keyboard)} - res = t = 0 - for c in word: - res += abs(index[c] - t) - t = index[c] - return res","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - var_7 = { var_4 : var_5 for var_5 , var_4 in enumerate ( var_0 ) } - var_10 = var_8 = 0 - for var_4 in var_2 : - var_10 += abs ( var_7 [ var_4 ] - var_8 ) - var_8 = var_7 [ var_4 ] - return var_10 -",0,1 -1101,1339.Maximum Product of Splitted Binary Tree_1.py,"def dfs(root): - nonlocal s, ans - if root is None: - return 0 - t = root.val + dfs(root.left) + dfs(root.right) - if t < s: - ans = max(ans, t * (s - t)) - return t","def sample_funcname ( var_1 ) : - nonlocal var_2 , var_3 - if var_1 is None : - return 0 - var_9 = var_1.val + var_0 ( var_1.left ) + var_0 ( var_1.right ) - if var_9 < var_2 : - var_3 = max ( var_3 , var_9 * ( var_2 - var_9 ) ) - return var_9 -",0None,2 -1102,1992.Find All Groups of Farmland_1.py,"def findFarmland( land: List[List[int]]) -> List[List[int]]: - m, n = len(land), len(land[0]) - ans = [] - for i in range(m): - for j in range(n): - if ( - land[i][j] == 0 - or (j > 0 and land[i][j - 1] == 1) - or (i > 0 and land[i - 1][j] == 1) - ): - continue - x, y = i, j - while x + 1 < m and land[x + 1][j] == 1: - x += 1 - while y + 1 < n and land[x][y + 1] == 1: - y += 1 - ans.append([i, j, x, y]) - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ List [ int ] ] : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_7 = [ ] - for var_9 in range ( var_4 ) : - for var_10 in range ( var_6 ) : - if ( var_0 [ var_9 ] [ var_10 ] == 0 or ( var_10 > 0 and var_0 [ var_9 ] [ var_10 - 1 ] == 1 ) or ( var_9 > 0 and var_0 [ var_9 - 1 ] [ var_10 ] == 1 ) ) : - continue - var_12 , var_13 = var_9 , var_10 - while var_12 + 1 < var_4 and var_0 [ var_12 + 1 ] [ var_10 ] == 1 : - var_12 += 1 - while var_13 + 1 < var_6 and var_0 [ var_12 ] [ var_13 + 1 ] == 1 : - var_13 += 1 - var_7.append ( [ var_9 , var_10 , var_12 , var_13 ] ) - return var_7 -",10,2 -1103,0907.Sum of Subarray Minimums_1.py,"def sumSubarrayMins( arr: List[int]) -> int: - n = len(arr) - left = [-1] * n - right = [n] * n - stk = [] - for i, v in enumerate(arr): - while stk and arr[stk[-1]] >= v: - stk.pop() - if stk: - left[i] = stk[-1] - stk.append(i) - stk = [] - for i in range(n - 1, -1, -1): - while stk and arr[stk[-1]] > arr[i]: - stk.pop() - if stk: - right[i] = stk[-1] - stk.append(i) - mod = int(1e9) + 7 - return sum((i - left[i]) * (right[i] - i) * v for i, v in enumerate(arr)) % mod","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_6 = [ - 1 ] * var_4 - var_7 = [ var_4 ] * var_4 - var_8 = [ ] - for var_10 , var_11 in enumerate ( var_0 ) : - while var_8 and var_0 [ var_8 [ - 1 ] ] >= var_11 : - var_8.pop ( ) - if var_8 : - var_6 [ var_10 ] = var_8 [ - 1 ] - var_8.append ( var_10 ) - var_8 = [ ] - for var_10 in range ( var_4 - 1 , - 1 , - 1 ) : - while var_8 and var_0 [ var_8 [ - 1 ] ] > var_0 [ var_10 ] : - var_8.pop ( ) - if var_8 : - var_7 [ var_10 ] = var_8 [ - 1 ] - var_8.append ( var_10 ) - var_17 = int ( 1e9 ) + 7 - return sum ( ( var_10 - var_6 [ var_10 ] ) * ( var_7 [ var_10 ] - var_10 ) * var_11 for var_10 , var_11 in enumerate ( var_0 ) ) % var_17 -",1e917,3 -1104,0308.Range Sum Query 2D - Mutable_1.py,"def lowbit(x): - return x & -x","def sample_funcname ( var_0 ) : - return var_0 & - var_0 -",,0 -1105,1228.Missing Number In Arithmetic Progression_1.py,"def missingNumber( arr: List[int]) -> int: - n = len(arr) - d = (arr[-1] - arr[0]) // n - for i in range(1, n): - if arr[i] != arr[i - 1] + d: - return arr[i - 1] + d - return arr[0]","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_7 = ( var_0 [ - 1 ] - var_0 [ 0 ] ) // var_4 - for var_9 in range ( 1 , var_4 ) : - if var_0 [ var_9 ] != var_0 [ var_9 - 1 ] + var_7 : - return var_0 [ var_9 - 1 ] + var_7 - return var_0 [ 0 ] -",10,2 -1106,0541.Reverse String II_1.py,"def reverseStr( s: str, k: int) -> str: - t = list(s) - for i in range(0, len(t), k << 1): - t[i : i + k] = reversed(t[i : i + k]) - return ''.join(t)","def sample_funcname ( var_0 : str , var_2 : int ) -> str : - var_5 = list ( var_0 ) - for var_10 in range ( 0 , len ( var_5 ) , var_2 << 1 ) : - var_5 [ var_10 : var_10 + var_2 ] = reversed ( var_5 [ var_10 : var_10 + var_2 ] ) - return ''.join ( var_5 ) -",10,3 -1107,0098.Validate Binary Search Tree_1.py,"def dfs(root): - nonlocal prev - if root is None: - return True - if not dfs(root.left): - return False - if prev >= root.val: - return False - prev = root.val - if not dfs(root.right): - return False - return True","def sample_funcname ( var_1 ) : - nonlocal var_2 - if var_1 is None : - return True - if not var_0 ( var_1.left ) : - return False - if var_2 >= var_1.val : - return False - var_2 = var_1.val - if not var_0 ( var_1.right ) : - return False - return True -",None,1 -1108,0548.Split Array with Equal Sum_1.py,"def splitArray( nums: List[int]) -> bool: - n = len(nums) - s = [0] * (n + 1) - for i, v in enumerate(nums): - s[i + 1] = s[i] + v - for j in range(3, n - 3): - seen = set() - for i in range(1, j - 1): - if s[i] == s[j] - s[i + 1]: - seen.add(s[i]) - for k in range(j + 2, n - 1): - if s[n] - s[k + 1] == s[k] - s[j + 1] and s[n] - s[k + 1] in seen: - return True - return False","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_5 = len ( var_0 ) - var_8 = [ 0 ] * ( var_5 + 1 ) - for var_10 , var_11 in enumerate ( var_0 ) : - var_8 [ var_10 + 1 ] = var_8 [ var_10 ] + var_11 - for var_14 in range ( 3 , var_5 - 3 ) : - var_16 = set ( ) - for var_10 in range ( 1 , var_14 - 1 ) : - if var_8 [ var_10 ] == var_8 [ var_14 ] - var_8 [ var_10 + 1 ] : - var_16.add ( var_8 [ var_10 ] ) - for var_19 in range ( var_14 + 2 , var_5 - 1 ) : - if var_8 [ var_5 ] - var_8 [ var_19 + 1 ] == var_8 [ var_19 ] - var_8 [ var_14 + 1 ] and var_8 [ var_5 ] - var_8 [ var_19 + 1 ] in var_16 : - return True - return False -",1302,4 -1109,0897.Increasing Order Search Tree_1.py,"def dfs(root): - if root is None: - return - nonlocal prev - dfs(root.left) - prev.right = root - root.left = None - prev = root - dfs(root.right)","def sample_funcname ( var_1 ) : - if var_1 is None : - return - nonlocal var_3 - var_0 ( var_1.left ) - var_3.right = var_1 - var_1.left = None - var_3 = var_1 - var_0 ( var_1.right ) -",None,1 -1110,0748.Shortest Completing Word_1.py,"def check(counter1, counter2): - for i in range(26): - if counter1[i] > counter2[i]: - return False - return True","def sample_funcname ( var_0 , var_1 ) : - for var_4 in range ( 26 ) : - if var_0 [ var_4 ] > var_1 [ var_4 ] : - return False - return True -",26,1 -1111,0561.Array Partition_1.py,"def arrayPairSum( nums: List[int]) -> int: - return sum(sorted(nums)[::2])","def sample_funcname ( var_0 : List [ int ] ) -> int : - return sum ( sorted ( var_0 ) [ : : 2 ] ) -",2,1 -1112,2220.Minimum Bit Flips to Convert Number_1.py,"def minBitFlips( start: int, goal: int) -> int: - t = start ^ goal - ans = 0 - while t: - ans += t & 1 - t >>= 1 - return ans","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_3 = var_0 ^ var_2 - var_5 = 0 - while var_3 : - var_5 += var_3 & 1 - var_3 >>= 1 - return var_5 -",10,2 -1113,0136.Single Number_1.py,"def singleNumber( nums: List[int]) -> int: - res = 0 - for num in nums: - res ^= num - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 0 - for var_5 in var_0 : - var_4 ^= var_5 - return var_4 -",0,1 -1114,1323.Maximum 69 Number_1.py,"def maximum69Number( num: int) -> int: - return int(str(num).replace(""6"", ""9"", 1))","def sample_funcname ( var_0 : int ) -> int : - return int ( str ( var_0 ).replace ( ""6"" , ""9"" , 1 ) ) -",169,3 -1115,0467.Unique Substrings in Wraparound String_1.py,"def findSubstringInWraproundString( p: str) -> int: - dp = [0] * 26 - k = 0 - for i, c in enumerate(p): - if i and (ord(c) - ord(p[i - 1])) % 26 == 1: - k += 1 - else: - k = 1 - idx = ord(c) - ord('a') - dp[idx] = max(dp[idx], k) - return sum(dp)","def sample_funcname ( var_0 : str ) -> int : - var_5 = [ 0 ] * 26 - var_6 = 0 - for var_8 , var_9 in enumerate ( var_0 ) : - if var_8 and ( ord ( var_9 ) - ord ( var_0 [ var_8 - 1 ] ) ) % 26 == 1 : - var_6 += 1 - else : - var_6 = 1 - var_13 = ord ( var_9 ) - ord ( 'a' ) - var_5 [ var_13 ] = max ( var_5 [ var_13 ] , var_6 ) - return sum ( var_5 ) -",10a26,4 -1116,1448.Count Good Nodes in Binary Tree_1.py,"def dfs(root, mx): - if root is None: - return - nonlocal ans - if mx <= root.val: - ans += 1 - mx = root.val - dfs(root.left, mx) - dfs(root.right, mx)","def sample_funcname ( var_1 , var_2 ) : - if var_1 is None : - return - nonlocal var_4 - if var_2 <= var_1.val : - var_4 += 1 - var_2 = var_1.val - var_0 ( var_1.left , var_2 ) - var_0 ( var_1.right , var_2 ) -",1None,2 -1117,2249.Count Lattice Points Inside a Circle_1.py,"def countLatticePoints( circles: List[List[int]]) -> int: - ans = 0 - imx = max(x + r for x, _, r in circles) - jmx = max(y + r for _, y, r in circles) - for i in range(imx + 1): - for j in range(jmx + 1): - for x, y, r in circles: - x, y = x - i, y - j - if x * x + y * y <= r * r: - ans += 1 - break - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 = 0 - var_9 = max ( var_6 + var_7 for var_6 , var_8 , var_7 in var_0 ) - var_11 = max ( var_10 + var_7 for var_8 , var_10 , var_7 in var_0 ) - for var_14 in range ( var_9 + 1 ) : - for var_15 in range ( var_11 + 1 ) : - for var_6 , var_10 , var_7 in var_0 : - var_6 , var_10 = var_6 - var_14 , var_10 - var_15 - if var_6 * var_6 + var_10 * var_10 <= var_7 * var_7 : - var_4 += 1 - break - return var_4 -",10,2 -1118,0482.License Key Formatting_1.py,"def licenseKeyFormatting( s: str, k: int) -> str: - s = s.replace('-', '').upper() - res = [] - cnt = (len(s) % k) or k - t = 0 - for i, c in enumerate(s): - res.append(c) - t += 1 - if t == cnt: - t = 0 - cnt = k - if i != len(s) - 1: - res.append('-') - return ''.join(res)","def sample_funcname ( var_0 : str , var_2 : int ) -> str : - var_0 = var_0.var_4 ( '-' , '' ).upper ( ) - var_8 = [ ] - var_10 = ( len ( var_0 ) % var_2 ) or var_2 - var_12 = 0 - for var_14 , var_15 in enumerate ( var_0 ) : - var_8.append ( var_15 ) - var_12 += 1 - if var_12 == var_10 : - var_12 = 0 - var_10 = var_2 - if var_14 != len ( var_0 ) - 1 : - var_8.append ( '-' ) - return ''.join ( var_8 ) -",10-,4 -1119,2357.Make Array Zero by Subtracting Equal Amounts_1.py,"def minimumOperations( nums: List[int]) -> int: - s = {v for v in nums if v} - return len(s)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = { var_3 for var_3 in var_0 if var_3 } - return len ( var_4 ) -",,0 -1120,2193.Minimum Number of Moves to Make Palindrome_1.py,"def minMovesToMakePalindrome( s: str) -> int: - cs = list(s) - ans, n = 0, len(s) - i, j = 0, n - 1 - while i < j: - even = False - for k in range(j, i, -1): - if cs[i] == cs[k]: - even = True - while k < j: - cs[k], cs[k + 1] = cs[k + 1], cs[k] - k += 1 - ans += 1 - j -= 1 - break - if not even: - ans += n // 2 - i - i += 1 - return ans","def sample_funcname ( var_0 : str ) -> int : - var_4 = list ( var_0 ) - var_6 , var_8 = 0 , len ( var_0 ) - var_9 , var_11 = 0 , var_8 - 1 - while var_9 < var_11 : - var_13 = False - for var_15 in range ( var_11 , var_9 , - 1 ) : - if var_4 [ var_9 ] == var_4 [ var_15 ] : - var_13 = True - while var_15 < var_11 : - var_4 [ var_15 ] , var_4 [ var_15 + 1 ] = var_4 [ var_15 + 1 ] , var_4 [ var_15 ] - var_15 += 1 - var_6 += 1 - var_11 -= 1 - break - if not var_13 : - var_6 += var_8 // 2 - var_9 - var_9 += 1 - return var_6 -",102,3 -1121,0875.Koko Eating Bananas_1.py,"def minEatingSpeed( piles: List[int], h: int) -> int: - left, right = 1, int(1e9) - while left < right: - mid = (left + right) >> 1 - s = sum((x + mid - 1) // mid for x in piles) - if s <= h: - right = mid - else: - left = mid + 1 - return left","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_7 = 1 , int ( 1e9 ) - while var_5 < var_7 : - var_8 = ( var_5 + var_7 ) >> 1 - var_11 = sum ( ( var_10 + var_8 - 1 ) // var_8 for var_10 in var_0 ) - if var_11 <= var_3 : - var_7 = var_8 - else : - var_5 = var_8 + 1 - return var_5 -",1e91,2 -1122,2149.Rearrange Array Elements by Sign_1.py,"def rearrangeArray( nums: List[int]) -> List[int]: - ans = [0] * len(nums) - i, j = 0, 1 - for num in nums: - if num > 0: - ans[i] = num - i += 2 - else: - ans[j] = num - j += 2 - return ans","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_5 = [ 0 ] * len ( var_0 ) - var_6 , var_8 = 0 , 1 - for var_9 in var_0 : - if var_9 > 0 : - var_5 [ var_6 ] = var_9 - var_6 += 2 - else : - var_5 [ var_8 ] = var_9 - var_8 += 2 - return var_5 -",102,3 -1123,0074.Search a 2D Matrix_1.py,"def searchMatrix( matrix: List[List[int]], target: int) -> bool: - m, n = len(matrix), len(matrix[0]) - left, right = 0, m * n - 1 - while left < right: - mid = (left + right) >> 1 - x, y = divmod(mid, n) - if matrix[x][y] >= target: - right = mid - else: - left = mid + 1 - return matrix[left // n][left % n] == target","def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : int ) -> bool : - var_6 , var_8 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_9 , var_11 = 0 , var_6 * var_8 - 1 - while var_9 < var_11 : - var_12 = ( var_9 + var_11 ) >> 1 - var_14 , var_15 = divmod ( var_12 , var_8 ) - if var_0 [ var_14 ] [ var_15 ] >= var_3 : - var_11 = var_12 - else : - var_9 = var_12 + 1 - return var_0 [ var_9 // var_8 ] [ var_9 % var_8 ] == var_3 -",10,2 -1124,1768.Merge Strings Alternately_1.py,"def mergeAlternately( word1: str, word2: str) -> str: - i, m, n = 0, len(word1), len(word2) - res = [] - while i < m or i < n: - if i < m: - res.append(word1[i]) - if i < n: - res.append(word2[i]) - i += 1 - return ''.join(res)","def sample_funcname ( var_0 : str , var_2 : str ) -> str : - var_4 , var_6 , var_7 = 0 , len ( var_0 ) , len ( var_2 ) - var_8 = [ ] - while var_4 < var_6 or var_4 < var_7 : - if var_4 < var_6 : - var_8.append ( var_0 [ var_4 ] ) - if var_4 < var_7 : - var_8.append ( var_2 [ var_4 ] ) - var_4 += 1 - return ''.join ( var_8 ) -",10,3 -1125,0154.Find Minimum in Rotated Sorted Array II_1.py,"def findMin( nums: List[int]) -> int: - left, right = 0, len(nums) - 1 - while left < right: - mid = (left + right) >> 1 - if nums[mid] > nums[right]: - left = mid + 1 - elif nums[mid] < nums[right]: - right = mid - else: - right -= 1 - return nums[left]","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_7 = 0 , len ( var_0 ) - 1 - while var_4 < var_7 : - var_8 = ( var_4 + var_7 ) >> 1 - if var_0 [ var_8 ] > var_0 [ var_7 ] : - var_4 = var_8 + 1 - elif var_0 [ var_8 ] < var_0 [ var_7 ] : - var_7 = var_8 - else : - var_7 -= 1 - return var_0 [ var_4 ] -",10,2 -1126,0275.H-Index II_1.py,"def hIndex( citations: List[int]) -> int: - n = len(citations) - left, right = 0, n - while left < right: - mid = (left + right + 1) >> 1 - if citations[n - mid] >= mid: - left = mid - else: - right = mid - 1 - return left","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_6 , var_7 = 0 , var_4 - while var_6 < var_7 : - var_9 = ( var_6 + var_7 + 1 ) >> 1 - if var_0 [ var_4 - var_9 ] >= var_9 : - var_6 = var_9 - else : - var_7 = var_9 - 1 - return var_6 -",10,2 -1127,0863.All Nodes Distance K in Binary Tree_1.py,"def parents(root, prev): - nonlocal p - if root is None: - return - p[root] = prev - parents(root.left, root) - parents(root.right, root)","def sample_funcname ( var_1 , var_2 ) : - nonlocal var_3 - if var_1 is None : - return - var_3 [ var_1 ] = var_2 - var_0 ( var_1.left , var_1 ) - var_0 ( var_1.right , var_1 ) -",None,1 -1128,1691.Maximum Height by Stacking Cuboids_1.py,"def maxHeight( cuboids: List[List[int]]) -> int: - for c in cuboids: - c.sort() - cuboids.sort() - n = len(cuboids) - dp = [0] * n - for i in range(n): - for j in range(i): - if cuboids[j][1] <= cuboids[i][1] and cuboids[j][2] <= cuboids[i][2]: - dp[i] = max(dp[i], dp[j]) - dp[i] += cuboids[i][2] - return max(dp)","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - for var_3 in var_0 : - var_3.sort ( ) - var_0.sort ( ) - var_6 = len ( var_0 ) - var_8 = [ 0 ] * var_6 - for var_10 in range ( var_6 ) : - for var_11 in range ( var_10 ) : - if var_0 [ var_11 ] [ 1 ] <= var_0 [ var_10 ] [ 1 ] and var_0 [ var_11 ] [ 2 ] <= var_0 [ var_10 ] [ 2 ] : - var_8 [ var_10 ] = max ( var_8 [ var_10 ] , var_8 [ var_11 ] ) - var_8 [ var_10 ] += var_0 [ var_10 ] [ 2 ] - return max ( var_8 ) -",102,3 -1129,1214.Two Sum BSTs_1.py,"def inorder(root, vals): - if root: - inorder(root.left, vals) - vals.append(root.val) - inorder(root.right, vals)","def sample_funcname ( var_1 , var_2 ) : - if var_1 : - var_0 ( var_1.left , var_2 ) - var_2.append ( var_1.val ) - var_0 ( var_1.right , var_2 ) -",,0 -1130,2270.Number of Ways to Split Array_1.py,"def waysToSplitArray( nums: List[int]) -> int: - s = sum(nums) - ans = t = 0 - for v in nums[:-1]: - t += v - if t >= s - t: - ans += 1 - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = sum ( var_0 ) - var_7 = var_5 = 0 - for var_9 in var_0 [ : - 1 ] : - var_5 += var_9 - if var_5 >= var_4 - var_5 : - var_7 += 1 - return var_7 -",10,2 -1131,0053.Maximum Subarray_1.py,"def maxSubArray( nums: List[int]) -> int: - res = f = nums[0] - for num in nums[1:]: - f = num + max(f, 0) - res = max(res, f) - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = var_0 [ 0 ] - for var_7 in var_0 [ 1 : ] : - var_3 = var_7 + max ( var_3 , 0 ) - var_5 = max ( var_5 , var_3 ) - return var_5 -",10,2 -1132,1740.Find Distance in a Binary Tree_1.py,"def dfs(root, v): - if root is None: - return -1 - if root.val == v: - return 0 - left, right = dfs(root.left, v), dfs(root.right, v) - if left == right == -1: - return -1 - return 1 + max(left, right)","def sample_funcname ( var_1 , var_2 ) : - if var_1 is None : - return - 1 - if var_1.val == var_2 : - return 0 - left , right = var_0 ( var_1.left , var_2 ) , var_0 ( var_1.right , var_2 ) - if left == right == - 1 : - return - 1 - return 1 + max ( left , right ) -",1None0,3 -1133,0728.Self Dividing Numbers_1.py,"def selfDividingNumbers( left: int, right: int) -> List[int]: - return [ - num - for num in range(left, right + 1) - if all(i != '0' and num % int(i) == 0 for i in str(num)) - ]","def sample_funcname ( var_0 : int , var_2 : int ) -> List [ int ] : - return [ var_4 for var_4 in range ( var_0 , var_2 + 1 ) if all ( var_8 != '0' and var_4 % int ( var_8 ) == 0 for var_8 in str ( var_4 ) ) ] -",100,3 -1134,1145.Binary Tree Coloring Game_1.py,"def count(root): - if root is None: - return 0 - return 1 + count(root.left) + count(root.right)","def sample_funcname ( var_1 ) : - if var_1 is None : - return 0 - return 1 + var_0 ( var_1.left ) + var_0 ( var_1.right ) -",10None,3 -1135,0583.Delete Operation for Two Strings_1.py,"def minDistance( word1: str, word2: str) -> int: - m, n = len(word1), len(word2) - dp = [[0] * (n + 1) for _ in range(m + 1)] - for i in range(1, m + 1): - dp[i][0] = i - for j in range(1, n + 1): - dp[0][j] = j - for i in range(1, m + 1): - for j in range(1, n + 1): - if word1[i - 1] == word2[j - 1]: - dp[i][j] = dp[i - 1][j - 1] - else: - dp[i][j] = 1 + min(dp[i - 1][j], dp[i][j - 1]) - return dp[-1][-1]","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - var_5 , var_6 = len ( var_0 ) , len ( var_2 ) - var_11 = [ [ 0 ] * ( var_6 + 1 ) for var_9 in range ( var_5 + 1 ) ] - for var_12 in range ( 1 , var_5 + 1 ) : - var_11 [ var_12 ] [ 0 ] = var_12 - for var_13 in range ( 1 , var_6 + 1 ) : - var_11 [ 0 ] [ var_13 ] = var_13 - for var_12 in range ( 1 , var_5 + 1 ) : - for var_13 in range ( 1 , var_6 + 1 ) : - if var_0 [ var_12 - 1 ] == var_2 [ var_13 - 1 ] : - var_11 [ var_12 ] [ var_13 ] = var_11 [ var_12 - 1 ] [ var_13 - 1 ] - else : - var_11 [ var_12 ] [ var_13 ] = 1 + min ( var_11 [ var_12 - 1 ] [ var_13 ] , var_11 [ var_12 ] [ var_13 - 1 ] ) - return var_11 [ - 1 ] [ - 1 ] -",10,2 -1136,1561.Maximum Number of Coins You Can Get_1.py,"def maxCoins( piles: List[int]) -> int: - piles.sort() - return sum(piles[-2 : len(piles) // 3 - 1 : -2])","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( ) - return sum ( var_0 [ - 2 : len ( var_0 ) // 3 - 1 : - 2 ] ) -",312,3 -1137,0848.Shifting Letters_1.py,"def shiftingLetters( S, shifts): - mov = 0 - ans = list(S) - for i in range(len(S) - 1, -1, -1): - mov += shifts[i] - ans[i] = chr((ord(S[i]) - 97 + mov % 26) % 26 + 97) - return ''.join(ans)","def sample_funcname ( var_0 , var_1 ) : - var_3 = 0 - var_5 = list ( var_0 ) - for var_9 in range ( len ( var_0 ) - 1 , - 1 , - 1 ) : - var_3 += var_1 [ var_9 ] - var_5 [ var_9 ] = chr ( ( ord ( var_0 [ var_9 ] ) - 97 + var_3 % 26 ) % 26 + 97 ) - return ''.join ( var_5 ) -",097126,5 -1139,1508.Range Sum of Sorted Subarray Sums_1.py,"def rangeSum( nums: List[int], n: int, left: int, right: int) -> int: - arr = [] - for i in range(n): - s = 0 - for j in range(i, n): - s += nums[j] - arr.append(s) - arr.sort() - MOD = 10**9 + 7 - return sum(arr[left - 1 : right]) % MOD","def sample_funcname ( var_0 : List [ int ] , var_3 : int , var_4 : int , var_5 : int ) -> int : - var_6 = [ ] - for var_8 in range ( var_3 ) : - var_10 = 0 - for var_11 in range ( var_8 , var_3 ) : - var_10 += var_0 [ var_11 ] - var_6.append ( var_10 ) - var_6.sort ( ) - var_17 = 10 ** 9 + 7 - return sum ( var_6 [ var_4 - 1 : var_5 ] ) % var_17 -",100179,5 -1140,1012.Numbers With Repeated Digits_1.py,"def A(m, n): - return 1 if n == 0 else A(m, n - 1) * (m - n + 1)","def sample_funcname ( var_1 , var_2 ) : - return 1 if var_2 == 0 else var_0 ( var_1 , var_2 - 1 ) * ( var_1 - var_2 + 1 ) -",10,2 -1141,1252.Cells with Odd Values in a Matrix_1.py,"def oddCells( m: int, n: int, indices: List[List[int]]) -> int: - row = [0] * m - col = [0] * n - for r, c in indices: - row[r] += 1 - col[c] += 1 - return sum((i + j) % 2 for i in row for j in col)","def sample_funcname ( var_0 : int , var_2 : int , var_3 : List [ List [ int ] ] ) -> int : - var_6 = [ 0 ] * var_0 - var_7 = [ 0 ] * var_2 - for var_8 , var_9 in var_3 : - var_6 [ var_8 ] += 1 - var_7 [ var_9 ] += 1 - return sum ( ( var_12 + var_13 ) % 2 for var_12 in var_6 for var_13 in var_7 ) -",102,3 -1142,0245.Shortest Word Distance III_1.py,"def shortestWordDistance( wordsDict: List[str], word1: str, word2: str) -> int: - i1 = i2 = -1 - shortest_distance = len(wordsDict) - same = word1 == word2 - for i in range(len(wordsDict)): - if same: - if word1 == wordsDict[i]: - if i1 != -1: - shortest_distance = min(shortest_distance, i - i1) - i1 = i - else: - if word1 == wordsDict[i]: - i1 = i - if word2 == wordsDict[i]: - i2 = i - if i1 != -1 and i2 != -1: - shortest_distance = min(shortest_distance, abs(i1 - i2)) - return shortest_distance","def sample_funcname ( var_0 : List [ str ] , var_3 : str , var_4 : str ) -> int : - var_8 = var_6 = - 1 - var_10 = len ( var_0 ) - var_11 = var_3 == var_4 - for var_13 in range ( len ( var_0 ) ) : - if var_11 : - if var_3 == var_0 [ var_13 ] : - if var_8 != - 1 : - var_10 = min ( var_10 , var_13 - var_8 ) - var_8 = var_13 - else : - if var_3 == var_0 [ var_13 ] : - var_8 = var_13 - if var_4 == var_0 [ var_13 ] : - var_6 = var_13 - if var_8 != - 1 and var_6 != - 1 : - var_10 = min ( var_10 , abs ( var_8 - var_6 ) ) - return var_10 -",1,1 -1143,0336.Palindrome Pairs_1.py,"def palindromePairs( words: List[str]) -> List[List[int]]: - d = {w: i for i, w in enumerate(words)} - ans = [] - for i, w in enumerate(words): - for j in range(len(w) + 1): - a, b = w[:j], w[j:] - ra, rb = a[::-1], b[::-1] - if ra in d and d[ra] != i and b == rb: - ans.append([i, d[ra]]) - if j and rb in d and d[rb] != i and a == ra: - ans.append([d[rb], i]) - return ans","def sample_funcname ( var_0 : List [ str ] ) -> List [ List [ int ] ] : - var_7 = { var_4 : var_5 for var_5 , var_4 in enumerate ( var_0 ) } - var_8 = [ ] - for var_5 , var_4 in enumerate ( var_0 ) : - for var_12 in range ( len ( var_4 ) + 1 ) : - var_13 , var_14 = var_4 [ : var_12 ] , var_4 [ var_12 : ] - var_15 , var_16 = var_13 [ : : - 1 ] , var_14 [ : : - 1 ] - if var_15 in var_7 and var_7 [ var_15 ] != var_5 and var_14 == var_16 : - var_8.append ( [ var_5 , var_7 [ var_15 ] ] ) - if var_12 and var_16 in var_7 and var_7 [ var_16 ] != var_5 and var_13 == var_15 : - var_8.append ( [ var_7 [ var_16 ] , var_5 ] ) - return var_8 -",1,1 -1144,2358.Maximum Number of Groups Entering a Competition_1.py,"def maximumGroups( grades: List[int]) -> int: - grades.sort() - ans = 1 - prev = [1, grades[0]] - curr = [0, 0] - for v in grades[1:]: - curr[0] += 1 - curr[1] += v - if prev[0] < curr[0] and prev[1] < curr[1]: - prev = curr - curr = [0, 0] - ans += 1 - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( ) - var_5 = 1 - var_7 = [ 1 , var_0 [ 0 ] ] - var_8 = [ 0 , 0 ] - for var_9 in var_0 [ 1 : ] : - var_8 [ 0 ] += 1 - var_8 [ 1 ] += var_9 - if var_7 [ 0 ] < var_8 [ 0 ] and var_7 [ 1 ] < var_8 [ 1 ] : - var_7 = var_8 - var_8 = [ 0 , 0 ] - var_5 += 1 - return var_5 -",10,2 -1145,0371.Sum of Two Integers_1.py,"def getSum( a: int, b: int) -> int: - a, b = a & 0xFFFFFFFF, b & 0xFFFFFFFF - while b: - carry = ((a & b) << 1) & 0xFFFFFFFF - a, b = a ^ b, carry - return a if a < 0x80000000 else ~(a ^ 0xFFFFFFFF)","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_0 , var_2 = var_0 & 0xFFFFFFFF , var_2 & 0xFFFFFFFF - while var_2 : - var_5 = ( ( var_0 & var_2 ) << 1 ) & 0xFFFFFFFF - var_0 , var_2 = var_0 ^ var_2 , var_5 - return var_0 if var_0 < 0x80000000 else ~ ( var_0 ^ 0xFFFFFFFF ) -",0x8000000010xFFFFFFFF,3 -1146,1952.Three Divisors_1.py,"def isThree( n: int) -> bool: - return sum(n % i == 0 for i in range(2, n)) == 1","def sample_funcname ( var_0 : int ) -> bool : - return sum ( var_0 % var_4 == 0 for var_4 in range ( 2 , var_0 ) ) == 1 -",102,3 -1147,0557.Reverse Words in a String III_1.py,"def reverseWords( s: str) -> str: - return ' '.join([t[::-1] for t in s.split(' ')])","def sample_funcname ( var_0 : str ) -> str : - return ' '.join ( [ var_4 [ : : - 1 ] for var_4 in var_0.split ( ' ' ) ] ) -",1 ,2 -1148,1099.Two Sum Less Than K_1.py,"def twoSumLessThanK( nums: List[int], k: int) -> int: - nums.sort() - low, high = 0, len(nums) - 1 - res = -1 - while low < high: - val = nums[low] + nums[high] - if val < k: - res = max(res, val) - low += 1 - else: - high -= 1 - return res","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_0.sort ( ) - var_6 , var_9 = 0 , len ( var_0 ) - 1 - var_10 = - 1 - while var_6 < var_9 : - var_11 = var_0 [ var_6 ] + var_0 [ var_9 ] - if var_11 < var_3 : - var_10 = max ( var_10 , var_11 ) - var_6 += 1 - else : - var_9 -= 1 - return var_10 -",10,2 -1149,1119.Remove Vowels from a String_1.py,"def removeVowels( s: str) -> str: - res = [] - for c in s: - if c not in {'a', 'e', 'i', 'o', 'u'}: - res.append(c) - return ''.join(res)","def sample_funcname ( var_0 : str ) -> str : - var_2 = [ ] - for var_3 in var_0 : - if var_3 not in { 'a' , 'e' , 'i' , 'o' , 'u' } : - var_2.append ( var_3 ) - return ''.join ( var_2 ) -",euaio,6 -1150,0771.Jewels and Stones_1.py,"def numJewelsInStones( jewels: str, stones: str) -> int: - s = set(jewels) - return sum([1 for c in stones if c in s])","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - var_5 = set ( var_0 ) - return sum ( [ 1 for var_8 in var_2 if var_8 in var_5 ] ) -",1,1 -1151,1033.Moving Stones Until Consecutive_1.py,"def numMovesStones( a: int, b: int, c: int) -> List[int]: - a, b, c = sorted([a, b, c]) - ans = [0] * 2 - if c - a == 2: - return ans - if b - a < 3 or c - b < 3: - ans[0] = 1 - else: - ans[0] = 2 - ans[1] = c - a - 2 - return ans","def sample_funcname ( var_0 : int , var_2 : int , var_3 : int ) -> List [ int ] : - var_0 , var_2 , var_3 = sorted ( [ var_0 , var_2 , var_3 ] ) - var_8 = [ 0 ] * 2 - if var_3 - var_0 == 2 : - return var_8 - if var_2 - var_0 < 3 or var_3 - var_2 < 3 : - var_8 [ 0 ] = 1 - else : - var_8 [ 0 ] = 2 - var_8 [ 1 ] = var_3 - var_0 - 2 - return var_8 -",1302,4 -1152,0448.Find All Numbers Disappeared in an Array_1.py,"def findDisappearedNumbers( nums: List[int]) -> List[int]: - for num in nums: - idx = abs(num) - 1 - if nums[idx] > 0: - nums[idx] *= -1 - return [i + 1 for i, v in enumerate(nums) if v > 0]","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - for var_3 in var_0 : - var_6 = abs ( var_3 ) - 1 - if var_0 [ var_6 ] > 0 : - var_0 [ var_6 ] *= - 1 - return [ var_8 + 1 for var_8 , var_10 in enumerate ( var_0 ) if var_10 > 0 ] -",10,2 -1153,0343.Integer Break_1.py,"def integerBreak( n: int) -> int: - dp = [1] * (n + 1) - for i in range(2, n + 1): - for j in range(1, i): - dp[i] = max(dp[i], dp[i - j] * j, (i - j) * j) - return dp[n]","def sample_funcname ( var_0 : int ) -> int : - var_3 = [ 1 ] * ( var_0 + 1 ) - for var_6 in range ( 2 , var_0 + 1 ) : - for var_7 in range ( 1 , var_6 ) : - var_3 [ var_6 ] = max ( var_3 [ var_6 ] , var_3 [ var_6 - var_7 ] * var_7 , ( var_6 - var_7 ) * var_7 ) - return var_3 [ var_0 ] -",12,2 -1154,2265.Count Nodes Equal to Average of Subtree_1.py,"def dfs(root): - if root is None: - return 0, 0 - ls, ln = dfs(root.left) - rs, rn = dfs(root.right) - s = ls + rs + root.val - n = ln + rn + 1 - if s // n == root.val: - nonlocal ans - ans += 1 - return s, n","def sample_funcname ( var_1 ) : - if var_1 is None : - return 0 , 0 - var_4 , var_6 = var_0 ( var_1.left ) - var_7 , var_9 = var_0 ( var_1.right ) - var_11 = var_4 + var_7 + var_1.val - var_13 = var_6 + var_9 + 1 - if var_11 // var_13 == var_1.val : - nonlocal var_14 - var_14 += 1 - return var_11 , var_13 -",10None,3 -1155,0521.Longest Uncommon Subsequence I_1.py,"def findLUSlength( a: str, b: str) -> int: - return -1 if a == b else max(len(a), len(b))","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - return - 1 if var_0 == var_2 else max ( len ( var_0 ) , len ( var_2 ) ) -",1,1 -1156,2260.Minimum Consecutive Cards to Pick Up_1.py,"def minimumCardPickup( cards: List[int]) -> int: - m = {} - ans = 10**6 - for i, c in enumerate(cards): - if c in m: - ans = min(ans, i - m[c] + 1) - m[c] = i - return -1 if ans == 10**6 else ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_3 = { } - var_6 = 10 ** 6 - for var_8 , var_9 in enumerate ( var_0 ) : - if var_9 in var_3 : - var_6 = min ( var_6 , var_8 - var_3 [ var_9 ] + 1 ) - var_3 [ var_9 ] = var_8 - return - 1 if var_6 == 10 ** 6 else var_6 -",1016,3 -1157,2299.Strong Password Checker II_1.py,"def strongPasswordCheckerII( password: str) -> bool: - if len(password) < 8: - return False - ans = 0 - for i, c in enumerate(password): - if i and password[i - 1] == c: - return False - if c.islower(): - ans |= 1 - elif c.isupper(): - ans |= 2 - elif c.isdigit(): - ans |= 4 - else: - ans |= 8 - return ans == 15","def sample_funcname ( var_0 : str ) -> bool : - if len ( var_0 ) < 8 : - return False - var_7 = 0 - for var_9 , var_10 in enumerate ( var_0 ) : - if var_9 and var_0 [ var_9 - 1 ] == var_10 : - return False - if var_10.islower ( ) : - var_7 |= 1 - elif var_10.isupper ( ) : - var_7 |= 2 - elif var_10.isdigit ( ) : - var_7 |= 4 - else : - var_7 |= 8 - return var_7 == 15 -",0821154,6 -1159,2303.Calculate Amount Paid in Taxes_1.py,"def calculateTax( brackets: List[List[int]], income: int) -> float: - ans = idx = 0 - prev = 0 - while income: - a, b = brackets[idx] - d = a - prev - ans += min(d, income) * b / 100 - if income <= d: - break - income -= d - idx += 1 - prev = a - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : int ) -> float : - var_7 = var_5 = 0 - var_8 = 0 - while var_3 : - var_9 , var_10 = var_0 [ var_5 ] - var_11 = var_9 - var_8 - var_7 += min ( var_11 , var_3 ) * var_10 / 100 - if var_3 <= var_11 : - break - var_3 -= var_11 - var_5 += 1 - var_8 = var_9 - return var_7 -",10001,3 -1160,0302.Smallest Rectangle Enclosing Black Pixels_1.py,"def minArea( image: List[List[str]], x: int, y: int) -> int: - m, n = len(image), len(image[0]) - left, right = 0, x - while left < right: - mid = (left + right) >> 1 - c = 0 - while c < n and image[mid][c] == '0': - c += 1 - if c < n: - right = mid - else: - left = mid + 1 - u = left - left, right = x, m - 1 - while left < right: - mid = (left + right + 1) >> 1 - c = 0 - while c < n and image[mid][c] == '0': - c += 1 - if c < n: - left = mid - else: - right = mid - 1 - d = left - left, right = 0, y - while left < right: - mid = (left + right) >> 1 - r = 0 - while r < m and image[r][mid] == '0': - r += 1 - if r < m: - right = mid - else: - left = mid + 1 - l = left - left, right = y, n - 1 - while left < right: - mid = (left + right + 1) >> 1 - r = 0 - while r < m and image[r][mid] == '0': - r += 1 - if r < m: - left = mid - else: - right = mid - 1 - r = left - return (d - u + 1) * (r - l + 1)","def sample_funcname ( var_0 : List [ List [ str ] ] , var_3 : int , var_5 : int ) -> int : - var_7 , var_9 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_10 , var_11 = 0 , var_3 - while var_10 < var_11 : - var_13 = ( var_10 + var_11 ) >> 1 - var_14 = 0 - while var_14 < var_9 and var_0 [ var_13 ] [ var_14 ] == '0' : - var_14 += 1 - if var_14 < var_9 : - var_11 = var_13 - else : - var_10 = var_13 + 1 - var_16 = var_10 - var_10 , var_11 = var_3 , var_7 - 1 - while var_10 < var_11 : - var_13 = ( var_10 + var_11 + 1 ) >> 1 - var_14 = 0 - while var_14 < var_9 and var_0 [ var_13 ] [ var_14 ] == '0' : - var_14 += 1 - if var_14 < var_9 : - var_10 = var_13 - else : - var_11 = var_13 - 1 - var_17 = var_10 - var_10 , var_11 = 0 , var_5 - while var_10 < var_11 : - var_13 = ( var_10 + var_11 ) >> 1 - var_18 = 0 - while var_18 < var_7 and var_0 [ var_18 ] [ var_13 ] == '0' : - var_18 += 1 - if var_18 < var_7 : - var_11 = var_13 - else : - var_10 = var_13 + 1 - var_19 = var_10 - var_10 , var_11 = var_5 , var_9 - 1 - while var_10 < var_11 : - var_13 = ( var_10 + var_11 + 1 ) >> 1 - var_18 = 0 - while var_18 < var_7 and var_0 [ var_18 ] [ var_13 ] == '0' : - var_18 += 1 - if var_18 < var_7 : - var_10 = var_13 - else : - var_11 = var_13 - 1 - var_18 = var_10 - return ( var_17 - var_16 + 1 ) * ( var_18 - var_19 + 1 ) -",100,3 -1161,0968.Binary Tree Cameras_1.py,"def dfs(root): - nonlocal ans - if root is None: - return 2 - left, right = dfs(root.left), dfs(root.right) - if left == 0 or right == 0: - ans += 1 - return 1 - return 2 if left == 1 or right == 1 else 0","def sample_funcname ( var_1 ) : - nonlocal var_2 - if var_1 is None : - return 2 - left , right = var_0 ( var_1.left ) , var_0 ( var_1.right ) - if left == 0 or right == 0 : - var_2 += 1 - return 1 - return 2 if left == 1 or right == 1 else 0 -",10None2,4 -1162,0483.Smallest Good Base_1.py,"def cal(k, m): - p = s = 1 - for i in range(m): - p *= k - s += p - return s","def sample_funcname ( var_0 , var_1 ) : - var_4 = var_2 = 1 - for var_6 in range ( var_1 ) : - var_4 *= var_0 - var_2 += var_4 - return var_2 -",1,1 -1163,1626.Best Team With No Conflicts_1.py,"def bestTeamScore( scores: List[int], ages: List[int]) -> int: - nums = list(zip(ages, scores)) - nums.sort() - n = len(nums) - dp = [num[1] for num in nums] - for i in range(n): - for j in range(i): - if nums[i][1] >= nums[j][1]: - dp[i] = max(dp[i], dp[j] + nums[i][1]) - return max(dp)","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_6 = list ( zip ( var_3 , var_0 ) ) - var_6.sort ( ) - var_9 = len ( var_6 ) - var_12 = [ var_10 [ 1 ] for var_10 in var_6 ] - for var_14 in range ( var_9 ) : - for var_15 in range ( var_14 ) : - if var_6 [ var_14 ] [ 1 ] >= var_6 [ var_15 ] [ 1 ] : - var_12 [ var_14 ] = max ( var_12 [ var_14 ] , var_12 [ var_15 ] + var_6 [ var_14 ] [ 1 ] ) - return max ( var_12 ) -",1,1 -1164,0773.Sliding Puzzle_1.py,"def check(seq): - n = len(seq) - cnt = sum(seq[i] > seq[j] for i in range(n) for j in range(i, n)) - return cnt % 2 == 0","def sample_funcname ( var_0 ) : - var_2 = len ( var_0 ) - var_7 = sum ( var_0 [ var_4 ] > var_0 [ var_5 ] for var_4 in range ( var_2 ) for var_5 in range ( var_4 , var_2 ) ) - return var_7 % 2 == 0 -",02,2 -1165,2055.Plates Between Candles_1.py,"def platesBetweenCandles( s: str, queries: List[List[int]]) -> List[int]: - n = len(s) - presum = [0] * (n + 1) - for i, c in enumerate(s): - presum[i + 1] = presum[i] + (c == '*') - - left, right = [0] * n, [0] * n - l = r = -1 - for i, c in enumerate(s): - if c == '|': - l = i - left[i] = l - for i in range(n - 1, -1, -1): - if s[i] == '|': - r = i - right[i] = r - - ans = [0] * len(queries) - for k, (l, r) in enumerate(queries): - i, j = right[l], left[r] - if i >= 0 and j >= 0 and i < j: - ans[k] = presum[j] - presum[i + 1] - return ans","def sample_funcname ( var_0 : str , var_2 : List [ List [ int ] ] ) -> List [ int ] : - var_6 = len ( var_0 ) - var_9 = [ 0 ] * ( var_6 + 1 ) - for var_11 , var_12 in enumerate ( var_0 ) : - var_9 [ var_11 + 1 ] = var_9 [ var_11 ] + ( var_12 == '*' ) - var_14 , var_15 = [ 0 ] * var_6 , [ 0 ] * var_6 - var_17 = var_16 = - 1 - for var_11 , var_12 in enumerate ( var_0 ) : - if var_12 == '|' : - var_17 = var_11 - var_14 [ var_11 ] = var_17 - for var_11 in range ( var_6 - 1 , - 1 , - 1 ) : - if var_0 [ var_11 ] == '|' : - var_16 = var_11 - var_15 [ var_11 ] = var_16 - var_20 = [ 0 ] * len ( var_2 ) - for var_21 , ( var_17 , var_16 ) in enumerate ( var_2 ) : - var_11 , var_22 = var_15 [ var_17 ] , var_14 [ var_16 ] - if var_11 >= 0 and var_22 >= 0 and var_11 < var_22 : - var_20 [ var_21 ] = var_9 [ var_22 ] - var_9 [ var_11 + 1 ] - return var_20 -",10|*,4 -1166,0942.DI String Match_1.py,"def diStringMatch( s: str) -> List[int]: - n = len(s) - low, high = 0, n - ans = [] - for i in range(n): - if s[i] == 'I': - ans.append(low) - low += 1 - else: - ans.append(high) - high -= 1 - ans.append(low) - return ans","def sample_funcname ( var_0 : str ) -> List [ int ] : - var_5 = len ( var_0 ) - var_7 , var_8 = 0 , var_5 - var_9 = [ ] - for var_11 in range ( var_5 ) : - if var_0 [ var_11 ] == 'I' : - var_9.append ( var_7 ) - var_7 += 1 - else : - var_9.append ( var_8 ) - var_8 -= 1 - var_9.append ( var_7 ) - return var_9 -",10I,3 -1167,0665.Non-decreasing Array_1.py,"def checkPossibility( nums): - if len(nums) < 2: - return True - count = 0 - for i in range(1, len(nums)): - if nums[i] < nums[i - 1]: - if count == 1: - return False - if not ( - i + 1 == len(nums) - or nums[i + 1] >= nums[i - 1] - or i - 2 < 0 - or nums[i - 2] < nums[i] - ): - return False - else: - count = 1 - return True","def sample_funcname ( var_0 ) : - if len ( var_0 ) < 2 : - return True - var_5 = 0 - for var_8 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_8 ] < var_0 [ var_8 - 1 ] : - if var_5 == 1 : - return False - if not ( var_8 + 1 == len ( var_0 ) or var_0 [ var_8 + 1 ] >= var_0 [ var_8 - 1 ] or var_8 - 2 < 0 or var_0 [ var_8 - 2 ] < var_0 [ var_8 ] ) : - return False - else : - var_5 = 1 - return True -",102,3 -1168,0866.Prime Palindrome_1.py,"def reverse(x): - res = 0 - while x: - res = res * 10 + x % 10 - x //= 10 - return res","def sample_funcname ( var_0 ) : - var_2 = 0 - while var_0 : - var_2 = var_2 * 10 + var_0 % 10 - var_0 //= 10 - return var_2 -",100,2 -1169,0243.Shortest Word Distance_1.py,"def shortestDistance( wordsDict: List[str], word1: str, word2: str) -> int: - i1 = i2 = -1 - shortest_distance = len(wordsDict) - for i in range(len(wordsDict)): - if wordsDict[i] == word1: - i1 = i - elif wordsDict[i] == word2: - i2 = i - if i1 != -1 and i2 != -1: - shortest_distance = min(shortest_distance, abs(i1 - i2)) - return shortest_distance","def sample_funcname ( var_0 : List [ str ] , var_3 : str , var_4 : str ) -> int : - var_8 = var_6 = - 1 - var_10 = len ( var_0 ) - for var_12 in range ( len ( var_0 ) ) : - if var_0 [ var_12 ] == var_3 : - var_8 = var_12 - elif var_0 [ var_12 ] == var_4 : - var_6 = var_12 - if var_8 != - 1 and var_6 != - 1 : - var_10 = min ( var_10 , abs ( var_8 - var_6 ) ) - return var_10 -",1,1 -1170,2165.Smallest Value of the Rearranged Number_1.py,"def smallestNumber( num: int) -> int: - if num == 0: - return 0 - cnt = [0] * 10 - neg = num < 0 - num = abs(num) - while num: - num, v = divmod(num, 10) - cnt[v] += 1 - ans = """" - if neg: - for i in range(9, -1, -1): - if cnt[i]: - ans += str(i) * cnt[i] - return -int(ans) - if cnt[0]: - for i in range(1, 10): - if cnt[i]: - ans += str(i) - cnt[i] -= 1 - break - for i in range(10): - if cnt[i]: - ans += str(i) * cnt[i] - return int(ans)","def sample_funcname ( var_0 : int ) -> int : - if var_0 == 0 : - return 0 - var_4 = [ 0 ] * 10 - var_5 = var_0 < 0 - var_0 = abs ( var_0 ) - while var_0 : - var_0 , var_8 = divmod ( var_0 , 10 ) - var_4 [ var_8 ] += 1 - var_11 = """" - if var_5 : - for var_14 in range ( 9 , - 1 , - 1 ) : - if var_4 [ var_14 ] : - var_11 += str ( var_14 ) * var_4 [ var_14 ] - return - int ( var_11 ) - if var_4 [ 0 ] : - for var_14 in range ( 1 , 10 ) : - if var_4 [ var_14 ] : - var_11 += str ( var_14 ) - var_4 [ var_14 ] -= 1 - break - for var_14 in range ( 10 ) : - if var_4 [ var_14 ] : - var_11 += str ( var_14 ) * var_4 [ var_14 ] - return int ( var_11 ) -",10019,5 -1171,1305.All Elements in Two Binary Search Trees_2.py,"def dfs(root, t): - if root is None: - return - dfs(root.left, t) - t.append(root.val) - dfs(root.right, t)","def sample_funcname ( var_1 , var_2 ) : - if var_1 is None : - return - var_0 ( var_1.left , var_2 ) - var_2.append ( var_1.val ) - var_0 ( var_1.right , var_2 ) -",None,1 -1172,0783.Minimum Distance Between BST Nodes_1.py,"def dfs(root): - if root is None: - return - dfs(root.left) - nonlocal ans, prev - ans = min(ans, abs(prev - root.val)) - prev = root.val - dfs(root.right)","def sample_funcname ( var_1 ) : - if var_1 is None : - return - var_0 ( var_1.left ) - nonlocal var_4 , var_5 - var_4 = min ( var_4 , abs ( var_5 - var_1.val ) ) - var_5 = var_1.val - var_0 ( var_1.right ) -",None,1 -1173,2083.Substrings That Begin and End With the Same Letter_1.py,"def numberOfSubstrings( s: str) -> int: - counter = [0] * 26 - ans = 0 - for c in s: - i = ord(c) - ord('a') - counter[i] += 1 - ans += counter[i] - return ans","def sample_funcname ( var_0 : str ) -> int : - var_5 = [ 0 ] * 26 - var_6 = 0 - for var_7 in var_0 : - var_10 = ord ( var_7 ) - ord ( 'a' ) - var_5 [ var_10 ] += 1 - var_6 += var_5 [ var_10 ] - return var_6 -",a0126,4 -1174,2315.Count Asterisks_1.py,"def countAsterisks( s: str) -> int: - ans = t = 0 - for c in s: - if c == '|': - t ^= 1 - elif c == '*': - if t == 0: - ans += 1 - return ans","def sample_funcname ( var_0 : str ) -> int : - var_5 = var_3 = 0 - for var_6 in var_0 : - if var_6 == '|' : - var_3 ^= 1 - elif var_6 == '*' : - if var_3 == 0 : - var_5 += 1 - return var_5 -",10|*,4 -1175,0463.Island Perimeter_1.py,"def islandPerimeter( grid: List[List[int]]) -> int: - m, n = len(grid), len(grid[0]) - ans = 0 - for i in range(m): - for j in range(n): - if grid[i][j] == 1: - ans += 4 - if i < m - 1 and grid[i + 1][j] == 1: - ans -= 2 - if j < n - 1 and grid[i][j + 1] == 1: - ans -= 2 - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_7 = 0 - for var_9 in range ( var_4 ) : - for var_10 in range ( var_6 ) : - if var_0 [ var_9 ] [ var_10 ] == 1 : - var_7 += 4 - if var_9 < var_4 - 1 and var_0 [ var_9 + 1 ] [ var_10 ] == 1 : - var_7 -= 2 - if var_10 < var_6 - 1 and var_0 [ var_9 ] [ var_10 + 1 ] == 1 : - var_7 -= 2 - return var_7 -",1042,4 -1176,0496.Next Greater Element I_1.py,"def nextGreaterElement( nums1: List[int], nums2: List[int]) -> List[int]: - m = {} - stk = [] - for v in nums2: - while stk and stk[-1] < v: - m[stk.pop()] = v - stk.append(v) - return [m.get(v, -1) for v in nums1]","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> List [ int ] : - var_4 = { } - var_5 = [ ] - for var_6 in var_3 : - while var_5 and var_5 [ - 1 ] < var_6 : - var_4 [ var_5.pop ( ) ] = var_6 - var_5.append ( var_6 ) - return [ var_4.get ( var_6 , - 1 ) for var_6 in var_0 ] -",1,1 -1178,0283.Move Zeroes_1.py,"def moveZeroes( nums: List[int]) -> None: - left, n = 0, len(nums) - for right in range(n): - if nums[right] != 0: - nums[left], nums[right] = nums[right], nums[left] - left += 1","def sample_funcname ( var_0 : List [ int ] ) -> None : - var_5 , var_7 = 0 , len ( var_0 ) - for var_9 in range ( var_7 ) : - if var_0 [ var_9 ] != 0 : - var_0 [ var_5 ] , var_0 [ var_9 ] = var_0 [ var_9 ] , var_0 [ var_5 ] - var_5 += 1 -",10None,3 -1179,1417.Reformat The String_1.py,"def reformat( s: str) -> str: - a = [c for c in s if c.islower()] - b = [c for c in s if c.isdigit()] - if abs(len(a) - len(b)) > 1: - return '' - if len(a) < len(b): - a, b = b, a - ans = [] - for x, y in zip(a, b): - ans.append(x + y) - if len(a) > len(b): - ans.append(a[-1]) - return ''.join(ans)","def sample_funcname ( var_0 : str ) -> str : - var_4 = [ var_2 for var_2 in var_0 if var_2.islower ( ) ] - var_6 = [ var_2 for var_2 in var_0 if var_2.isdigit ( ) ] - if abs ( len ( var_4 ) - len ( var_6 ) ) > 1 : - return '' - if len ( var_4 ) < len ( var_6 ) : - var_4 , var_6 = var_6 , var_4 - var_11 = [ ] - for var_13 , var_14 in zip ( var_4 , var_6 ) : - var_11.append ( var_13 + var_14 ) - if len ( var_4 ) > len ( var_6 ) : - var_11.append ( var_4 [ - 1 ] ) - return ''.join ( var_11 ) -",1,2 -1180,1277.Count Square Submatrices with All Ones_1.py,"def countSquares( matrix: List[List[int]]) -> int: - m, n = len(matrix), len(matrix[0]) - f = [[0] * n for _ in range(m)] - ans = 0 - for i, row in enumerate(matrix): - for j, v in enumerate(row): - if v == 0: - continue - if i == 0 or j == 0: - f[i][j] = 1 - else: - f[i][j] = min(f[i - 1][j - 1], f[i - 1][j], f[i][j - 1]) + 1 - ans += f[i][j] - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_9 = [ [ 0 ] * var_6 for var_7 in range ( var_4 ) ] - var_10 = 0 - for var_12 , var_13 in enumerate ( var_0 ) : - for var_14 , var_15 in enumerate ( var_13 ) : - if var_15 == 0 : - continue - if var_12 == 0 or var_14 == 0 : - var_9 [ var_12 ] [ var_14 ] = 1 - else : - var_9 [ var_12 ] [ var_14 ] = min ( var_9 [ var_12 - 1 ] [ var_14 - 1 ] , var_9 [ var_12 - 1 ] [ var_14 ] , var_9 [ var_12 ] [ var_14 - 1 ] ) + 1 - var_10 += var_9 [ var_12 ] [ var_14 ] - return var_10 -",10,2 -1181,1758.Minimum Changes To Make Alternating Binary String_1.py,"def minOperations( s: str) -> int: - cnt = 0 - for i, c in enumerate(s): - cnt += c == '01'[i & 1] - return min(cnt, len(s) - cnt)","def sample_funcname ( var_0 : str ) -> int : - var_4 = 0 - for var_6 , var_7 in enumerate ( var_0 ) : - var_4 += var_7 == '01' [ var_6 & 1 ] - return min ( var_4 , len ( var_0 ) - var_4 ) -",1001,3 -1182,0006.Zigzag Conversion_1.py,"def convert( s: str, numRows: int) -> str: - if numRows == 1: - return s - group = 2 * numRows - 2 - ans = [] - for i in range(1, numRows + 1): - interval = group if i == numRows else 2 * numRows - 2 * i - idx = i - 1 - while idx < len(s): - ans.append(s[idx]) - idx += interval - interval = group - interval - if interval == 0: - interval = group - return ''.join(ans)","def sample_funcname ( var_0 : str , var_2 : int ) -> str : - if var_2 == 1 : - return var_0 - var_6 = 2 * var_2 - 2 - var_7 = [ ] - for var_9 in range ( 1 , var_2 + 1 ) : - var_10 = var_6 if var_9 == var_2 else 2 * var_2 - 2 * var_9 - var_11 = var_9 - 1 - while var_11 < len ( var_0 ) : - var_7.append ( var_0 [ var_11 ] ) - var_11 += var_10 - var_10 = var_6 - var_10 - if var_10 == 0 : - var_10 = var_6 - return ''.join ( var_7 ) -",102,4 -1183,1437.Check If All 1's Are at Least Length K Places Away_1.py,"def kLengthApart( nums: List[int], k: int) -> bool: - j = -1 - for i, v in enumerate(nums): - if v == 1: - if j > -1 and i - j - 1 < k: - return False - j = i - return True","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> bool : - var_6 = - 1 - for var_8 , var_9 in enumerate ( var_0 ) : - if var_9 == 1 : - if var_6 > - 1 and var_8 - var_6 - 1 < var_3 : - return False - var_6 = var_8 - return True -",1,1 -1184,0268.Missing Number_1.py,"def missingNumber( nums: List[int]) -> int: - res = len(nums) - for i, v in enumerate(nums): - res ^= i ^ v - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - for var_6 , var_7 in enumerate ( var_0 ) : - var_4 ^= var_6 ^ var_7 - return var_4 -",,0 -1185,2048.Next Greater Numerically Balanced Number_1.py,"def check(num): - counter = [0] * 10 - for c in str(num): - counter[int(c)] += 1 - - for c in str(num): - if counter[int(c)] != int(c): - return False - return True","def sample_funcname ( var_0 ) : - var_3 = [ 0 ] * 10 - for var_5 in str ( var_0 ) : - var_3 [ int ( var_5 ) ] += 1 - for var_5 in str ( var_0 ) : - if var_3 [ int ( var_5 ) ] != int ( var_5 ) : - return False - return True -",1001,3 -1186,1914.Cyclically Rotating a Grid_1.py,"def rotate(grid, s1, e1, s2, e2, k): - t = [] - for j in range(e2, e1, -1): - t.append(grid[s1][j]) - for i in range(s1, s2): - t.append(grid[i][e1]) - for j in range(e1, e2): - t.append(grid[s2][j]) - for i in range(s2, s1, -1): - t.append(grid[i][e2]) - k %= len(t) - t = t[-k:] + t[:-k] - k = 0 - for j in range(e2, e1, -1): - grid[s1][j] = t[k] - k += 1 - for i in range(s1, s2): - grid[i][e1] = t[k] - k += 1 - for j in range(e1, e2): - grid[s2][j] = t[k] - k += 1 - for i in range(s2, s1, -1): - grid[i][e2] = t[k] - k += 1","def sample_funcname ( var_0 , var_1 , var_2 , var_3 , var_4 , var_5 ) : - var_6 = [ ] - for var_9 in range ( var_4 , var_2 , - 1 ) : - var_6.append ( var_0 [ var_1 ] [ var_9 ] ) - for var_11 in range ( var_1 , var_3 ) : - var_6.append ( var_0 [ var_11 ] [ var_2 ] ) - for var_9 in range ( var_2 , var_4 ) : - var_6.append ( var_0 [ var_3 ] [ var_9 ] ) - for var_11 in range ( var_3 , var_1 , - 1 ) : - var_6.append ( var_0 [ var_11 ] [ var_4 ] ) - var_5 %= len ( var_6 ) - var_6 = var_6 [ - var_5 : ] + var_6 [ : - var_5 ] - var_5 = 0 - for var_9 in range ( var_4 , var_2 , - 1 ) : - var_0 [ var_1 ] [ var_9 ] = var_6 [ var_5 ] - var_5 += 1 - for var_11 in range ( var_1 , var_3 ) : - var_0 [ var_11 ] [ var_2 ] = var_6 [ var_5 ] - var_5 += 1 - for var_9 in range ( var_2 , var_4 ) : - var_0 [ var_3 ] [ var_9 ] = var_6 [ var_5 ] - var_5 += 1 - for var_11 in range ( var_3 , var_1 , - 1 ) : - var_0 [ var_11 ] [ var_4 ] = var_6 [ var_5 ] - var_5 += 1 -",10,2 -1187,0798.Smallest Rotation with Highest Score_1.py,"def bestRotation( nums: List[int]) -> int: - n = len(nums) - mx, ans = -1, n - d = [0] * n - for i, v in enumerate(nums): - l, r = (i + 1) % n, (n + i + 1 - v) % n - d[l] += 1 - d[r] -= 1 - s = 0 - for k, t in enumerate(d): - s += t - if s > mx: - mx = s - ans = k - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_6 , var_7 = - 1 , var_4 - var_9 = [ 0 ] * var_4 - for var_11 , var_12 in enumerate ( var_0 ) : - var_13 , var_14 = ( var_11 + 1 ) % var_4 , ( var_4 + var_11 + 1 - var_12 ) % var_4 - var_9 [ var_13 ] += 1 - var_9 [ var_14 ] -= 1 - var_15 = 0 - for var_16 , var_17 in enumerate ( var_9 ) : - var_15 += var_17 - if var_15 > var_6 : - var_6 = var_15 - var_7 = var_16 - return var_7 -",10,2 -1188,1980.Find Unique Binary String_1.py,"def findDifferentBinaryString( nums: List[str]) -> str: - s = set(num.count(""1"") for num in nums) - n = len(nums) - for i in range(n + 1): - if i not in s: - return ""1"" * i + ""0"" * (n - i) - return """"","def sample_funcname ( var_0 : List [ str ] ) -> str : - var_7 = set ( var_4.count ( ""1"" ) for var_4 in var_0 ) - var_9 = len ( var_0 ) - for var_12 in range ( var_9 + 1 ) : - if var_12 not in var_7 : - return ""1"" * var_12 + ""0"" * ( var_9 - var_12 ) - return """" -",110,4 -1189,0401.Binary Watch_1.py,"def readBinaryWatch( turnedOn: int) -> List[str]: - return [ - '{:d}:{:02d}'.format(i, j) - for i in range(12) - for j in range(60) - if (bin(i) + bin(j)).count('1') == turnedOn - ]","def sample_funcname ( var_0 : int ) -> List [ str ] : - return [ '{:d}:{:02d}'.format ( var_6 , var_7 ) for var_6 in range ( 12 ) for var_7 in range ( 60 ) if ( bin ( var_6 ) + bin ( var_7 ) ).count ( '1' ) == var_0 ] -",6012{:d}:{:02d}1,4 -1190,2222.Number of Ways to Select Buildings_1.py,"def numberOfWays( s: str) -> int: - n = len(s) - cnt0 = s.count(""0"") - cnt1 = n - cnt0 - c0 = c1 = 0 - ans = 0 - for c in s: - if c == ""0"": - ans += c1 * (cnt1 - c1) - c0 += 1 - else: - ans += c0 * (cnt0 - c0) - c1 += 1 - return ans","def sample_funcname ( var_0 : str ) -> int : - var_4 = len ( var_0 ) - var_7 = var_0.count ( ""0"" ) - var_8 = var_4 - var_7 - var_11 = var_9 = 0 - var_12 = 0 - for var_13 in var_0 : - if var_13 == ""0"" : - var_12 += var_9 * ( var_8 - var_9 ) - var_11 += 1 - else : - var_12 += var_11 * ( var_7 - var_11 ) - var_9 += 1 - return var_12 -",100,3 -1191,0011.Container With Most Water_1.py,"def maxArea( height: List[int]) -> int: - i, j = 0, len(height) - 1 - res = 0 - while i < j: - t = (j - i) * min(height[i], height[j]) - res = max(res, t) - if height[i] < height[j]: - i += 1 - else: - j -= 1 - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_7 = 0 , len ( var_0 ) - 1 - var_8 = 0 - while var_4 < var_7 : - var_10 = ( var_7 - var_4 ) * min ( var_0 [ var_4 ] , var_0 [ var_7 ] ) - var_8 = max ( var_8 , var_10 ) - if var_0 [ var_4 ] < var_0 [ var_7 ] : - var_4 += 1 - else : - var_7 -= 1 - return var_8 -",10,2 -1192,1662.Check If Two String Arrays are Equivalent_1.py,"def arrayStringsAreEqual( word1: List[str], word2: List[str]) -> bool: - s1, s2 = ''.join(word1), ''.join(word2) - return s1 == s2","def sample_funcname ( var_0 : List [ str ] , var_3 : List [ str ] ) -> bool : - var_7 , var_8 = ''.join ( var_0 ) , ''.join ( var_3 ) - return var_7 == var_8 -",,1 -1193,0413.Arithmetic Slices_1.py,"def numberOfArithmeticSlices( nums: List[int]) -> int: - n = len(nums) - dp = [0] * n - for i in range(2, n): - if nums[i] + nums[i - 2] == (nums[i - 1] << 1): - dp[i] = 1 + dp[i - 1] - return sum(dp)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_6 = [ 0 ] * var_4 - for var_9 in range ( 2 , var_4 ) : - if var_0 [ var_9 ] + var_0 [ var_9 - 2 ] == ( var_0 [ var_9 - 1 ] << 1 ) : - var_6 [ var_9 ] = 1 + var_6 [ var_9 - 1 ] - return sum ( var_6 ) -",102,3 -1194,1833.Maximum Ice Cream Bars_1.py,"def maxIceCream( costs: List[int], coins: int) -> int: - costs.sort() - ans = 0 - for c in costs: - if coins < c: - break - else: - ans += 1 - coins -= c - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_0.sort ( ) - var_6 = 0 - for var_7 in var_0 : - if var_3 < var_7 : - break - else : - var_6 += 1 - var_3 -= var_7 - return var_6 -",10,2 -1195,0420.Strong Password Checker_1.py,"def countTypes(s): - a = b = c = 0 - for ch in s: - if ch.islower(): - a = 1 - elif ch.isupper(): - b = 1 - elif ch.isdigit(): - c = 1 - return a + b + c","def sample_funcname ( var_0 ) : - var_4 = var_1 = var_2 = 0 - for var_5 in var_0 : - if var_5.islower ( ) : - var_4 = 1 - elif var_5.isupper ( ) : - var_1 = 1 - elif var_5.isdigit ( ) : - var_2 = 1 - return var_4 + var_1 + var_2 -",10,2 -1196,1869.Longer Contiguous Segments of Ones than Zeros_1.py,"def checkZeroOnes( s: str) -> bool: - n0 = n1 = 0 - t0 = t1 = 0 - for c in s: - if c == '0': - t0 += 1 - t1 = 0 - else: - t0 = 0 - t1 += 1 - n0 = max(n0, t0) - n1 = max(n1, t1) - return n1 > n0","def sample_funcname ( var_0 : str ) -> bool : - var_5 = var_3 = 0 - var_7 = var_6 = 0 - for var_8 in var_0 : - if var_8 == '0' : - var_7 += 1 - var_6 = 0 - else : - var_7 = 0 - var_6 += 1 - var_5 = max ( var_5 , var_7 ) - var_3 = max ( var_3 , var_6 ) - return var_3 > var_5 -",100,3 -1197,2126.Destroying Asteroids_1.py,"def asteroidsDestroyed( mass: int, asteroids: List[int]) -> bool: - asteroids.sort() - for v in asteroids: - if mass < v: - return False - mass += v - return True","def sample_funcname ( var_0 : int , var_2 : List [ int ] ) -> bool : - var_2.sort ( ) - for var_6 in var_2 : - if var_0 < var_6 : - return False - var_0 += var_6 - return True -",,0 -1198,2352.Equal Row and Column Pairs_1.py,"def equalPairs( grid: List[List[int]]) -> int: - n = len(grid) - g = [] - for j in range(n): - t = [] - for i in range(n): - t.append(grid[i][j]) - g.append(t) - return sum(row == col for row in grid for col in g)","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 = len ( var_0 ) - var_5 = [ ] - for var_7 in range ( var_4 ) : - var_8 = [ ] - for var_9 in range ( var_4 ) : - var_8.append ( var_0 [ var_9 ] [ var_7 ] ) - var_5.append ( var_8 ) - return sum ( var_12 == var_13 for var_12 in var_0 for var_13 in var_5 ) -",,0 -1199,1180.Count Substrings with Only One Distinct Letter_1.py,"def countLetters( s: str) -> int: - n = len(s) - i = ans = 0 - while i < n: - j = i - while j < n and s[j] == s[i]: - j += 1 - ans += (1 + j - i) * (j - i) // 2 - i = j - return ans","def sample_funcname ( var_0 : str ) -> int : - var_4 = len ( var_0 ) - var_7 = var_5 = 0 - while var_7 < var_4 : - var_8 = var_7 - while var_8 < var_4 and var_0 [ var_8 ] == var_0 [ var_7 ] : - var_8 += 1 - var_5 += ( 1 + var_8 - var_7 ) * ( var_8 - var_7 ) // 2 - var_7 = var_8 - return var_5 -",102,3 -1200,2180.Count Integers With Even Digit Sum_1.py,"def countEven( num: int) -> int: - ans = 0 - for i in range(1, num + 1): - t = 0 - while i: - t += i % 10 - i //= 10 - if t % 2 == 0: - ans += 1 - return ans","def sample_funcname ( var_0 : int ) -> int : - var_3 = 0 - for var_6 in range ( 1 , var_0 + 1 ) : - var_7 = 0 - while var_6 : - var_7 += var_6 % 10 - var_6 //= 10 - if var_7 % 2 == 0 : - var_3 += 1 - return var_3 -",10102,4 -1201,0115.Distinct Subsequences_1.py,"def numDistinct( s: str, t: str) -> int: - m, n = len(s), len(t) - dp = [[0] * n + 1 for _ in range(m + 1)] - for i in range(m + 1): - dp[i][0] = 1 - for i in range(1, m + 1): - for j in range(1, n + 1): - dp[i][j] = dp[i - 1][j] - if s[i - 1] == s[j - 1]: - dp[i][j] += dp[i - 1][j - 1] - return dp[m][n]","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - var_5 , var_6 = len ( var_0 ) , len ( var_2 ) - var_11 = [ [ 0 ] * var_6 + 1 for var_9 in range ( var_5 + 1 ) ] - for var_12 in range ( var_5 + 1 ) : - var_11 [ var_12 ] [ 0 ] = 1 - for var_12 in range ( 1 , var_5 + 1 ) : - for var_13 in range ( 1 , var_6 + 1 ) : - var_11 [ var_12 ] [ var_13 ] = var_11 [ var_12 - 1 ] [ var_13 ] - if var_0 [ var_12 - 1 ] == var_0 [ var_13 - 1 ] : - var_11 [ var_12 ] [ var_13 ] += var_11 [ var_12 - 1 ] [ var_13 - 1 ] - return var_11 [ var_5 ] [ var_6 ] -",10,2 -1202,0747.Largest Number At Least Twice of Others_1.py,"def dominantIndex( nums: List[int]) -> int: - mx = mid = 0 - ans = -1 - for i, v in enumerate(nums): - if v > mx: - mid, mx = mx, v - ans = i - elif v > mid: - mid = v - return ans if mx >= 2 * mid else -1","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - var_7 = - 1 - for var_9 , var_10 in enumerate ( var_0 ) : - if var_10 > var_5 : - var_3 , var_5 = var_5 , var_10 - var_7 = var_9 - elif var_10 > var_3 : - var_3 = var_10 - return var_7 if var_5 >= 2 * var_3 else - 1 -",102,3 -1203,1888.Minimum Number of Flips to Make the Binary String Alternating_1.py,"def minFlips( s: str) -> int: - n = len(s) - target = '01' - cnt = 0 - for i, c in enumerate(s): - cnt += c != target[i & 1] - res = min(cnt, n - cnt) - for i in range(n): - cnt -= s[i] != target[i & 1] - cnt += s[i] != target[(i + n) & 1] - res = min(res, cnt, n - cnt) - return res","def sample_funcname ( var_0 : str ) -> int : - var_4 = len ( var_0 ) - var_6 = '01' - var_8 = 0 - for var_10 , var_11 in enumerate ( var_0 ) : - var_8 += var_11 != var_6 [ var_10 & 1 ] - var_14 = min ( var_8 , var_4 - var_8 ) - for var_10 in range ( var_4 ) : - var_8 -= var_0 [ var_10 ] != var_6 [ var_10 & 1 ] - var_8 += var_0 [ var_10 ] != var_6 [ ( var_10 + var_4 ) & 1 ] - var_14 = min ( var_14 , var_8 , var_4 - var_8 ) - return var_14 -",1001,3 -1204,0929.Unique Email Addresses_1.py,"def numUniqueEmails( emails: List[str]) -> int: - s = set() - for email in emails: - local, domain = email.split('@') - local = local.replace('.', '') - if (i := local.find('+')) != -1: - local = local[:i] - s.add(local + '@' + domain) - return len(s)","def sample_funcname ( var_0 : List [ str ] ) -> int : - var_5 = set ( ) - for var_6 in var_0 : - var_8 , var_10 = var_6.split ( '@' ) - var_8 = var_8.replace ( '.' , '' ) - if ( var_14 := var_8.find ( '+' ) ) != - 1 : - var_8 = var_8 [ : var_14 ] - var_5.add ( var_8 + '@' + var_10 ) - return len ( var_5 ) -",@+.1,5 -1205,1329.Sort the Matrix Diagonally_1.py,"def diagonalSort( mat: List[List[int]]) -> List[List[int]]: - m, n = len(mat), len(mat[0]) - for k in range(min(m, n) - 1): - for i in range(m - 1): - for j in range(n - 1): - if mat[i][j] > mat[i + 1][j + 1]: - mat[i][j], mat[i + 1][j + 1] = mat[i + 1][j + 1], mat[i][j] - return mat","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ List [ int ] ] : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - for var_10 in range ( min ( var_4 , var_6 ) - 1 ) : - for var_11 in range ( var_4 - 1 ) : - for var_12 in range ( var_6 - 1 ) : - if var_0 [ var_11 ] [ var_12 ] > var_0 [ var_11 + 1 ] [ var_12 + 1 ] : - var_0 [ var_11 ] [ var_12 ] , var_0 [ var_11 + 1 ] [ var_12 + 1 ] = var_0 [ var_11 + 1 ] [ var_12 + 1 ] , var_0 [ var_11 ] [ var_12 ] - return var_0 -",10,2 -1206,0188.Best Time to Buy and Sell Stock IV_1.py,"def maxProfit( k: int, prices: List[int]) -> int: - n = len(prices) - if n < 2: - return 0 - dp = [[[0] * 2 for _ in range(k + 1)] for _ in range(n)] - for i in range(1, k + 1): - dp[0][i][1] = -prices[0] - for i in range(1, n): - for j in range(1, k + 1): - dp[i][j][0] = max(dp[i - 1][j][1] + prices[i], dp[i - 1][j][0]) - dp[i][j][1] = max(dp[i - 1][j - 1][0] - prices[i], dp[i - 1][j][1]) - return dp[-1][k][0]","def sample_funcname ( var_0 : int , var_2 : List [ int ] ) -> int : - var_5 = len ( var_2 ) - if var_5 < 2 : - return 0 - var_11 = [ [ [ 0 ] * 2 for var_8 in range ( var_0 + 1 ) ] for var_8 in range ( var_5 ) ] - for var_12 in range ( 1 , var_0 + 1 ) : - var_11 [ 0 ] [ var_12 ] [ 1 ] = - var_2 [ 0 ] - for var_12 in range ( 1 , var_5 ) : - for var_13 in range ( 1 , var_0 + 1 ) : - var_11 [ var_12 ] [ var_13 ] [ 0 ] = max ( var_11 [ var_12 - 1 ] [ var_13 ] [ 1 ] + var_2 [ var_12 ] , var_11 [ var_12 - 1 ] [ var_13 ] [ 0 ] ) - var_11 [ var_12 ] [ var_13 ] [ 1 ] = max ( var_11 [ var_12 - 1 ] [ var_13 - 1 ] [ 0 ] - var_2 [ var_12 ] , var_11 [ var_12 - 1 ] [ var_13 ] [ 1 ] ) - return var_11 [ - 1 ] [ var_0 ] [ 0 ] -",102,3 -1207,0628.Maximum Product of Three Numbers_1.py,"def maximumProduct( nums: List[int]) -> int: - n = len(nums) - nums.sort() - return max( - nums[0] * nums[1] * nums[n - 1], nums[n - 1] * nums[n - 2] * nums[n - 3] - )","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_0.sort ( ) - return max ( var_0 [ 0 ] * var_0 [ 1 ] * var_0 [ var_4 - 1 ] , var_0 [ var_4 - 1 ] * var_0 [ var_4 - 2 ] * var_0 [ var_4 - 3 ] ) -",1302,4 -1208,0812.Largest Triangle Area_1.py,"def largestTriangleArea( points: List[List[int]]) -> float: - ans = 0 - for x1, y1 in points: - for x2, y2 in points: - for x3, y3 in points: - u1, v1 = x2 - x1, y2 - y1 - u2, v2 = x3 - x1, y3 - y1 - t = abs(u1 * v2 - u2 * v1) / 2 - ans = max(ans, t) - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> float : - var_5 = 0 - for var_6 , var_7 in var_0 : - for var_8 , var_9 in var_0 : - for var_10 , var_11 in var_0 : - var_12 , var_13 = var_8 - var_6 , var_9 - var_7 - var_14 , var_15 = var_10 - var_6 , var_11 - var_7 - var_18 = abs ( var_12 * var_15 - var_14 * var_13 ) / 2 - var_5 = max ( var_5 , var_18 ) - return var_5 -",02,2 -1209,0186.Reverse Words in a String II_1.py,"def reverse(s, i, j): - while i < j: - s[i], s[j] = s[j], s[i] - i += 1 - j -= 1","def sample_funcname ( var_0 , var_1 , var_2 ) : - while var_1 < var_2 : - var_0 [ var_1 ] , var_0 [ var_2 ] = var_0 [ var_2 ] , var_0 [ var_1 ] - var_1 += 1 - var_2 -= 1 -",1,1 -1210,0189.Rotate Array_1.py,"def rotate( nums: List[int], k: int) -> None: - n = len(nums) - k %= n - if n < 2 or k == 0: - return - nums[:] = nums[::-1] - nums[:k] = nums[:k][::-1] - nums[k:] = nums[k:][::-1]","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> None : - var_6 = len ( var_0 ) - var_3 %= var_6 - if var_6 < 2 or var_3 == 0 : - return - var_0 [ : ] = var_0 [ : : - 1 ] - var_0 [ : var_3 ] = var_0 [ : var_3 ] [ : : - 1 ] - var_0 [ var_3 : ] = var_0 [ var_3 : ] [ : : - 1 ] -",10None2,4 -1211,0872.Leaf-Similar Trees_1.py,"def dfs(root): - if root is None: - return [] - ans = dfs(root.left) + dfs(root.right) - return ans or [root.val]","def sample_funcname ( var_1 ) : - if var_1 is None : - return [ ] - var_5 = var_0 ( var_1.left ) + var_0 ( var_1.right ) - return var_5 or [ var_1.val ] -",None,1 -1212,0238.Product of Array Except Self_1.py,"def productExceptSelf( nums: List[int]) -> List[int]: - n = len(nums) - ans = [1] * n - left = right = 1 - for i in range(n): - ans[i] = left - left *= nums[i] - for i in range(n - 1, -1, -1): - ans[i] *= right - right *= nums[i] - return ans","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 = len ( var_0 ) - var_6 = [ 1 ] * var_4 - var_8 = var_7 = 1 - for var_10 in range ( var_4 ) : - var_6 [ var_10 ] = var_8 - var_8 *= var_0 [ var_10 ] - for var_10 in range ( var_4 - 1 , - 1 , - 1 ) : - var_6 [ var_10 ] *= var_7 - var_7 *= var_0 [ var_10 ] - return var_6 -",1,1 -1213,1496.Path Crossing_1.py,"def isPathCrossing( path: str) -> bool: - x = y = 0 - vis = {(x, y)} - for c in path: - if c == 'N': - y += 1 - elif c == 'S': - y -= 1 - elif c == 'E': - x += 1 - else: - x -= 1 - if (x, y) in vis: - return True - vis.add((x, y)) - return False","def sample_funcname ( var_0 : str ) -> bool : - var_5 = var_3 = 0 - var_6 = { ( var_5 , var_3 ) } - for var_7 in var_0 : - if var_7 == 'N' : - var_3 += 1 - elif var_7 == 'S' : - var_3 -= 1 - elif var_7 == 'E' : - var_5 += 1 - else : - var_5 -= 1 - if ( var_5 , var_3 ) in var_6 : - return True - var_6.add ( ( var_5 , var_3 ) ) - return False -",0SE1N,5 -1214,0298.Binary Tree Longest Consecutive Sequence_1.py,"def dfs(root, p, t): - nonlocal ans - if root is None: - return - t = t + 1 if p is not None and p.val + 1 == root.val else 1 - ans = max(ans, t) - dfs(root.left, root, t) - dfs(root.right, root, t)","def sample_funcname ( var_1 , var_2 , var_3 ) : - nonlocal var_4 - if var_1 is None : - return - var_3 = var_3 + 1 if var_2 is not None and var_2.val + 1 == var_1.val else 1 - var_4 = max ( var_4 , var_3 ) - var_0 ( var_1.left , var_1 , var_3 ) - var_0 ( var_1.right , var_1 , var_3 ) -",1None,2 -1215,2182.Construct String With Repeat Limit_1.py,"def repeatLimitedString( s: str, repeatLimit: int) -> str: - cnt = [0] * 26 - for c in s: - cnt[ord(c) - ord('a')] += 1 - ans = [] - for i in range(25, -1, -1): - j = i - 1 - while 1: - for _ in range(min(repeatLimit, cnt[i])): - cnt[i] -= 1 - ans.append(chr(ord('a') + i)) - if cnt[i] == 0: - break - while j >= 0 and cnt[j] == 0: - j -= 1 - if j < 0: - break - cnt[j] -= 1 - ans.append(chr(ord('a') + j)) - return ''.join(ans)","def sample_funcname ( var_0 : str , var_2 : int ) -> str : - var_6 = [ 0 ] * 26 - for var_7 in var_0 : - var_6 [ ord ( var_7 ) - ord ( 'a' ) ] += 1 - var_11 = [ ] - for var_14 in range ( 25 , - 1 , - 1 ) : - var_15 = var_14 - 1 - while 1 : - for var_17 in range ( min ( var_2 , var_6 [ var_14 ] ) ) : - var_6 [ var_14 ] -= 1 - var_11.append ( chr ( ord ( 'a' ) + var_14 ) ) - if var_6 [ var_14 ] == 0 : - break - while var_15 >= 0 and var_6 [ var_15 ] == 0 : - var_15 -= 1 - if var_15 < 0 : - break - var_6 [ var_15 ] -= 1 - var_11.append ( chr ( ord ( 'a' ) + var_15 ) ) - return ''.join ( var_11 ) -",0a12526,6 -1216,0201.Bitwise AND of Numbers Range_1.py,"def rangeBitwiseAnd( left: int, right: int) -> int: - while left < right: - right &= right - 1 - return right","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - while var_0 < var_2 : - var_2 &= var_2 - 1 - return var_2 -",1,1 -1217,1455.Check If a Word Occurs As a Prefix of Any Word in a Sentence_1.py,"def isPrefixOfWord( sentence: str, searchWord: str) -> int: - for i, s in enumerate(sentence.split(), 1): - if s.startswith(searchWord): - return i - return -1","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - for var_5 , var_8 in enumerate ( var_0.split ( ) , 1 ) : - if var_8.startswith ( var_2 ) : - return var_5 - return - 1 -",1,1 -1218,1432.Max Difference You Can Get From Changing an Integer_1.py,"def maxDiff( num: int) -> int: - a, b = str(num), str(num) - for c in a: - if c != '9': - a = a.replace(c, '9') - break - for i, c in enumerate(b): - if i == 0: - if c != '1': - b = b.replace(c, '1') - break - else: - if c != '0' and c != b[0]: - b = b.replace(c, '0') - break - return int(a) - int(b)","def sample_funcname ( var_0 : int ) -> int : - var_3 , var_4 = str ( var_0 ) , str ( var_0 ) - for var_5 in var_3 : - if var_5 != '9' : - var_3 = var_3.replace ( var_5 , '9' ) - break - for var_9 , var_5 in enumerate ( var_4 ) : - if var_9 == 0 : - if var_5 != '1' : - var_4 = var_4.replace ( var_5 , '1' ) - break - else : - if var_5 != '0' and var_5 != var_4 [ 0 ] : - var_4 = var_4.replace ( var_5 , '0' ) - break - return int ( var_3 ) - int ( var_4 ) -",0091,4 -1219,0029.Divide Two Integers_1.py,"def divide( a: int, b: int) -> int: - INT_MAX = (1 << 31) - 1 - INT_MIN = -(1 << 31) - sign = -1 if a * b < 0 else 1 - a = abs(a) - b = abs(b) - tot = 0 - while a >= b: - cnt = 0 - while a >= (b << (cnt + 1)): - cnt += 1 - tot += 1 << cnt - a -= b << cnt - return sign * tot if INT_MIN <= sign * tot <= INT_MAX else INT_MAX","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_5 = ( 1 << 31 ) - 1 - var_6 = - ( 1 << 31 ) - var_8 = - 1 if var_0 * var_2 < 0 else 1 - var_0 = abs ( var_0 ) - var_2 = abs ( var_2 ) - var_10 = 0 - while var_0 >= var_2 : - var_11 = 0 - while var_0 >= ( var_2 << ( var_11 + 1 ) ) : - var_11 += 1 - var_10 += 1 << var_11 - var_0 -= var_2 << var_11 - return var_8 * var_10 if var_6 <= var_8 * var_10 <= var_5 else var_5 -",1310,3 -1220,1974.Minimum Time to Type Word Using Special Typewriter_1.py,"def minTimeToType( word: str) -> int: - ans = prev = 0 - for c in word: - curr = ord(c) - ord('a') - t = abs(prev - curr) - t = min(t, 26 - t) - ans += t + 1 - prev = curr - return ans","def sample_funcname ( var_0 : str ) -> int : - var_5 = var_3 = 0 - for var_6 in var_0 : - var_9 = ord ( var_6 ) - ord ( 'a' ) - var_11 = abs ( var_3 - var_9 ) - var_11 = min ( var_11 , 26 - var_11 ) - var_5 += var_11 + 1 - var_3 = var_9 - return var_5 -",a0126,4 -1222,1370.Increasing Decreasing String_1.py,"def sortString( s: str) -> str: - counter = [0] * 26 - for c in s: - counter[ord(c) - ord('a')] += 1 - ans = [] - while len(ans) < len(s): - for i in range(26): - if counter[i]: - ans.append(chr(i + ord('a'))) - counter[i] -= 1 - for i in range(25, -1, -1): - if counter[i]: - ans.append(chr(i + ord('a'))) - counter[i] -= 1 - return ''.join(ans)","def sample_funcname ( var_0 : str ) -> str : - var_4 = [ 0 ] * 26 - for var_5 in var_0 : - var_4 [ ord ( var_5 ) - ord ( 'a' ) ] += 1 - var_9 = [ ] - while len ( var_9 ) < len ( var_0 ) : - for var_12 in range ( 26 ) : - if var_4 [ var_12 ] : - var_9.append ( chr ( var_12 + ord ( 'a' ) ) ) - var_4 [ var_12 ] -= 1 - for var_12 in range ( 25 , - 1 , - 1 ) : - if var_4 [ var_12 ] : - var_9.append ( chr ( var_12 + ord ( 'a' ) ) ) - var_4 [ var_12 ] -= 1 - return ''.join ( var_9 ) -",0a12526,6 -1223,1100.Find K-Length Substrings With No Repeated Characters_1.py,"def numKLenSubstrNoRepeats( s: str, k: int) -> int: - ans = j = 0 - mp = {} - for i, c in enumerate(s): - if c in mp: - j = max(j, mp[c] + 1) - mp[c] = i - if i - j + 1 >= k: - ans += 1 - return ans","def sample_funcname ( var_0 : str , var_2 : int ) -> int : - var_6 = var_4 = 0 - var_7 = { } - for var_9 , var_10 in enumerate ( var_0 ) : - if var_10 in var_7 : - var_4 = max ( var_4 , var_7 [ var_10 ] + 1 ) - var_7 [ var_10 ] = var_9 - if var_9 - var_4 + 1 >= var_2 : - var_6 += 1 - return var_6 -",10,2 -1224,2138.Divide a String Into Groups of Size k_1.py,"def divideString( s: str, k: int, fill: str) -> List[str]: - return [s[i : i + k].ljust(k, fill) for i in range(0, len(s), k)]","def sample_funcname ( var_0 : str , var_2 : int , var_4 : str ) -> List [ str ] : - return [ var_0 [ var_6 : var_6 + var_2 ].ljust ( var_2 , var_4 ) for var_6 in range ( 0 , len ( var_0 ) , var_2 ) ] -",0,1 -1225,0087.Scramble String_1.py,"def isScramble( s1: str, s2: str) -> bool: - n = len(s1) - dp = [[[False] * (n + 1) for _ in range(n)] for _ in range(n)] - for i in range(n): - for j in range(n): - dp[i][j][1] = s1[i] == s2[j] - for l in range(2, n + 1): - for i1 in range(n - l + 1): - for i2 in range(n - l + 1): - for i in range(1, l): - if dp[i1][i2][i] and dp[i1 + i][i2 + i][l - i]: - dp[i1][i2][l] = True - break - if dp[i1][i2 + l - i][i] and dp[i1 + i][i2][l - i]: - dp[i1][i2][l] = True - break - return dp[0][0][n]","def sample_funcname ( var_0 : str , var_2 : str ) -> bool : - var_5 = len ( var_0 ) - var_10 = [ [ [ False ] * ( var_5 + 1 ) for var_8 in range ( var_5 ) ] for var_8 in range ( var_5 ) ] - for var_11 in range ( var_5 ) : - for var_12 in range ( var_5 ) : - var_10 [ var_11 ] [ var_12 ] [ 1 ] = var_0 [ var_11 ] == var_2 [ var_12 ] - for var_14 in range ( 2 , var_5 + 1 ) : - for var_15 in range ( var_5 - var_14 + 1 ) : - for var_16 in range ( var_5 - var_14 + 1 ) : - for var_11 in range ( 1 , var_14 ) : - if var_10 [ var_15 ] [ var_16 ] [ var_11 ] and var_10 [ var_15 + var_11 ] [ var_16 + var_11 ] [ var_14 - var_11 ] : - var_10 [ var_15 ] [ var_16 ] [ var_14 ] = True - break - if var_10 [ var_15 ] [ var_16 + var_14 - var_11 ] [ var_11 ] and var_10 [ var_15 + var_11 ] [ var_16 ] [ var_14 - var_11 ] : - var_10 [ var_15 ] [ var_16 ] [ var_14 ] = True - break - return var_10 [ 0 ] [ 0 ] [ var_5 ] -",102,3 -1226,0443.String Compression_1.py,"def compress( chars: List[str]) -> int: - i, k, n = 0, 0, len(chars) - while i < n: - j = i + 1 - while j < n and chars[j] == chars[i]: - j += 1 - chars[k] = chars[i] - k += 1 - if j - i > 1: - cnt = str(j - i) - for c in cnt: - chars[k] = c - k += 1 - i = j - return k","def sample_funcname ( var_0 : List [ str ] ) -> int : - var_5 , var_6 , var_8 = 0 , 0 , len ( var_0 ) - while var_5 < var_8 : - var_10 = var_5 + 1 - while var_10 < var_8 and var_0 [ var_10 ] == var_0 [ var_5 ] : - var_10 += 1 - var_0 [ var_6 ] = var_0 [ var_5 ] - var_6 += 1 - if var_10 - var_5 > 1 : - var_11 = str ( var_10 - var_5 ) - for var_12 in var_11 : - var_0 [ var_6 ] = var_12 - var_6 += 1 - var_5 = var_10 - return var_6 -",10,2 -1227,2042.Check if Numbers Are Ascending in a Sentence_1.py,"def areNumbersAscending( s: str) -> bool: - curr = 0 - for t in s.split(' '): - if t[0].isdigit(): - if curr >= int(t): - return False - curr = int(t) - return True","def sample_funcname ( var_0 : str ) -> bool : - var_4 = 0 - for var_7 in var_0.split ( ' ' ) : - if var_7 [ 0 ].isdigit ( ) : - if var_4 >= int ( var_7 ) : - return False - var_4 = int ( var_7 ) - return True -",0 ,2 -1228,2274.Maximum Consecutive Floors Without Special Floors_1.py,"def maxConsecutive( bottom: int, top: int, special: List[int]) -> int: - special.sort() - ans = max(special[0] - bottom, top - special[-1]) - for i in range(1, len(special)): - ans = max(ans, special[i] - special[i - 1] - 1) - return ans","def sample_funcname ( var_0 : int , var_2 : int , var_3 : List [ int ] ) -> int : - var_3.sort ( ) - var_9 = max ( var_3 [ 0 ] - var_0 , var_2 - var_3 [ - 1 ] ) - for var_12 in range ( 1 , len ( var_3 ) ) : - var_9 = max ( var_9 , var_3 [ var_12 ] - var_3 [ var_12 - 1 ] - 1 ) - return var_9 -",10,2 -1229,0025.Reverse Nodes in k-Group_1.py,"def reverseList(head): - pre, p = None, head - while p: - q = p.next - p.next = pre - pre = p - p = q - return pre","def sample_funcname ( var_0 ) : - var_2 , var_3 = None , var_0 - while var_3 : - var_5 = var_3.next - var_3.next = var_2 - var_2 = var_3 - var_3 = var_5 - return var_2 -",None,1 -1230,1027.Longest Arithmetic Subsequence_1.py,"def longestArithSeqLength( nums: List[int]) -> int: - n = len(nums) - dp = [[1] * 1001 for _ in range(n)] - ans = 0 - for i in range(1, n): - for j in range(i): - d = nums[i] - nums[j] + 500 - dp[i][d] = max(dp[i][d], dp[j][d] + 1) - ans = max(ans, dp[i][d]) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_9 = [ [ 1 ] * 1001 for var_7 in range ( var_4 ) ] - var_11 = 0 - for var_12 in range ( 1 , var_4 ) : - for var_13 in range ( var_12 ) : - var_15 = var_0 [ var_12 ] - var_0 [ var_13 ] + 500 - var_9 [ var_12 ] [ var_15 ] = max ( var_9 [ var_12 ] [ var_15 ] , var_9 [ var_13 ] [ var_15 ] + 1 ) - var_11 = max ( var_11 , var_9 [ var_12 ] [ var_15 ] ) - return var_11 -",110010500,4 -1231,1025.Divisor Game_1.py,"def divisorGame( n: int) -> bool: - return n % 2 == 0","def sample_funcname ( var_0 : int ) -> bool : - return var_0 % 2 == 0 -",02,2 -1232,0702.Search in a Sorted Array of Unknown Size_1.py,"def search( reader, target): - left, right = 0, 20000 - while left < right: - mid = (left + right) >> 1 - if reader.get(mid) >= target: - right = mid - else: - left = mid + 1 - return left if reader.get(left) == target else -1","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_5 = 0 , 20000 - while var_3 < var_5 : - var_7 = ( var_3 + var_5 ) >> 1 - if var_0.get ( var_7 ) >= var_1 : - var_5 = var_7 - else : - var_3 = var_7 + 1 - return var_3 if var_0.get ( var_3 ) == var_1 else - 1 -",1200000,3 -1233,0293.Flip Game_1.py,"def generatePossibleNextMoves( currentState: str) -> List[str]: - s = list(currentState) - ans = [] - for i, c in enumerate(s[:-1]): - if c == ""+"" and s[i + 1] == ""+"": - s[i] = s[i + 1] = ""-"" - ans.append("""".join(s)) - s[i] = s[i + 1] = ""+"" - return ans","def sample_funcname ( var_0 : str ) -> List [ str ] : - var_4 = list ( var_0 ) - var_5 = [ ] - for var_7 , var_9 in enumerate ( var_4 [ : - 1 ] ) : - if var_9 == ""+"" and var_4 [ var_7 + 1 ] == ""+"" : - var_4 [ var_7 ] = var_4 [ var_7 + 1 ] = ""-"" - var_5.append ( """".join ( var_4 ) ) - var_4 [ var_7 ] = var_4 [ var_7 + 1 ] = ""+"" - return var_5 -",+1-,4 -1234,0675.Cut Off Trees for Golf Event_1.py,"def f(i, j, x, y): - return abs(i - x) + abs(j - y)","def sample_funcname ( var_0 , var_1 , var_2 , var_3 ) : - return abs ( var_0 - var_2 ) + abs ( var_1 - var_3 ) -",,0 -1235,2381.Shifting Letters II_1.py,"def shiftingLetters( s: str, shifts: List[List[int]]) -> str: - n = len(s) - d = [0] * (n + 1) - for i, j, v in shifts: - if v == 0: - v = -1 - d[i] += v - d[j + 1] -= v - for i in range(1, n + 1): - d[i] += d[i - 1] - return ''.join( - chr(ord('a') + (ord(s[i]) - ord('a') + d[i] + 26) % 26) for i in range(n) - )","def sample_funcname ( var_0 : str , var_2 : List [ List [ int ] ] ) -> str : - var_6 = len ( var_0 ) - var_9 = [ 0 ] * ( var_6 + 1 ) - for var_10 , var_11 , var_12 in var_2 : - if var_12 == 0 : - var_12 = - 1 - var_9 [ var_10 ] += var_12 - var_9 [ var_11 + 1 ] -= var_12 - for var_10 in range ( 1 , var_6 + 1 ) : - var_9 [ var_10 ] += var_9 [ var_10 - 1 ] - return ''.join ( chr ( ord ( 'a' ) + ( ord ( var_0 [ var_10 ] ) - ord ( 'a' ) + var_9 [ var_10 ] + 26 ) % 26 ) for var_10 in range ( var_6 ) ) -",0a126,5 -1236,0162.Find Peak Element_1.py,"def findPeakElement( nums: List[int]) -> int: - left, right = 0, len(nums) - 1 - while left < right: - mid = (left + right) >> 1 - if nums[mid] > nums[mid + 1]: - right = mid - else: - left = mid + 1 - return left","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_7 = 0 , len ( var_0 ) - 1 - while var_4 < var_7 : - var_8 = ( var_4 + var_7 ) >> 1 - if var_0 [ var_8 ] > var_0 [ var_8 + 1 ] : - var_7 = var_8 - else : - var_4 = var_8 + 1 - return var_4 -",10,2 -1237,0415.Add Strings_1.py,"def addStrings( num1: str, num2: str) -> str: - i, j, carry = len(num1) - 1, len(num2) - 1, 0 - ans = [] - while i >= 0 or j >= 0 or carry: - carry += (0 if i < 0 else int(num1[i])) + (0 if j < 0 else int(num2[j])) - carry, v = divmod(carry, 10) - ans.append(str(v)) - i, j = i - 1, j - 1 - return ''.join(ans[::-1])","def sample_funcname ( var_0 : str , var_2 : str ) -> str : - var_5 , var_6 , var_8 = len ( var_0 ) - 1 , len ( var_2 ) - 1 , 0 - var_9 = [ ] - while var_5 >= 0 or var_6 >= 0 or var_8 : - var_8 += ( 0 if var_5 < 0 else int ( var_0 [ var_5 ] ) ) + ( 0 if var_6 < 0 else int ( var_2 [ var_6 ] ) ) - var_8 , var_13 = divmod ( var_8 , 10 ) - var_9.append ( str ( var_13 ) ) - var_5 , var_6 = var_5 - 1 , var_6 - 1 - return ''.join ( var_9 [ : : - 1 ] ) -",1010,4 -1238,1295.Find Numbers with Even Number of Digits_1.py,"def findNumbers( nums: List[int]) -> int: - return sum(1 for num in nums if (len(str(num)) & 1) == 0)","def sample_funcname ( var_0 : List [ int ] ) -> int : - return sum ( 1 for var_5 in var_0 if ( len ( str ( var_5 ) ) & 1 ) == 0 ) -",10,2 -1239,1846.Maximum Element After Decreasing and Rearranging_1.py,"def maximumElementAfterDecrementingAndRearranging( arr: List[int]) -> int: - arr.sort() - arr[0] = 1 - for i in range(1, len(arr)): - d = max(0, arr[i] - arr[i - 1] - 1) - arr[i] -= d - return max(arr)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( ) - var_0 [ 0 ] = 1 - for var_8 in range ( 1 , len ( var_0 ) ) : - var_10 = max ( 0 , var_0 [ var_8 ] - var_0 [ var_8 - 1 ] - 1 ) - var_0 [ var_8 ] -= var_10 - return max ( var_0 ) -",10,2 -1240,0525.Contiguous Array_1.py,"def findMaxLength( nums: List[int]) -> int: - s = ans = 0 - mp = {0: -1} - for i, v in enumerate(nums): - s += 1 if v == 1 else -1 - if s in mp: - ans = max(ans, i - mp[s]) - else: - mp[s] = i - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - var_7 = { 0 : - 1 } - for var_9 , var_10 in enumerate ( var_0 ) : - var_5 += 1 if var_10 == 1 else - 1 - if var_5 in var_7 : - var_3 = max ( var_3 , var_9 - var_7 [ var_5 ] ) - else : - var_7 [ var_5 ] = var_9 - return var_3 -",10,2 -1241,0593.Valid Square_1.py,"def check(a, b, c): - (x1, y1), (x2, y2), (x3, y3) = a, b, c - d1 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) - d2 = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3) - d3 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3) - return any( - [ - d1 == d2 and d1 + d2 == d3 and d1, - d2 == d3 and d2 + d3 == d1 and d2, - d1 == d3 and d1 + d3 == d2 and d1, - ] - )","def sample_funcname ( var_0 , var_1 , var_2 ) : - ( var_3 , var_4 ) , ( var_5 , var_6 ) , ( var_7 , var_8 ) = var_0 , var_1 , var_2 - var_9 = ( var_3 - var_5 ) * ( var_3 - var_5 ) + ( var_4 - var_6 ) * ( var_4 - var_6 ) - var_10 = ( var_3 - var_7 ) * ( var_3 - var_7 ) + ( var_4 - var_8 ) * ( var_4 - var_8 ) - var_11 = ( var_5 - var_7 ) * ( var_5 - var_7 ) + ( var_6 - var_8 ) * ( var_6 - var_8 ) - return any ( [ var_9 == var_10 and var_9 + var_10 == var_11 and var_9 , var_10 == var_11 and var_10 + var_11 == var_9 and var_10 , var_9 == var_11 and var_9 + var_11 == var_10 and var_9 , ] ) -",,0 -1242,0976.Largest Perimeter Triangle_1.py,"def largestPerimeter( nums: List[int]) -> int: - nums.sort() - for i in range(len(nums) - 1, 1, -1): - if (c := nums[i - 1] + nums[i - 2]) > nums[i]: - return c + nums[i] - return 0","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( ) - for var_7 in range ( len ( var_0 ) - 1 , 1 , - 1 ) : - if ( var_8 := var_0 [ var_7 - 1 ] + var_0 [ var_7 - 2 ] ) > var_0 [ var_7 ] : - return var_8 + var_0 [ var_7 ] - return 0 -",102,3 -1243,2379.Minimum Recolors to Get K Consecutive Black Blocks_1.py,"def minimumRecolors( blocks: str, k: int) -> int: - cnt = blocks[:k].count('W') - ans = cnt - i, n = k, len(blocks) - while i < n: - cnt += blocks[i] == 'W' - cnt -= blocks[i - k] == 'W' - ans = min(ans, cnt) - i += 1 - return ans","def sample_funcname ( var_0 : str , var_2 : int ) -> int : - var_6 = var_0 [ : var_2 ].count ( 'W' ) - var_7 = var_6 - var_8 , var_10 = var_2 , len ( var_0 ) - while var_8 < var_10 : - var_6 += var_0 [ var_8 ] == 'W' - var_6 -= var_0 [ var_8 - var_2 ] == 'W' - var_7 = min ( var_7 , var_6 ) - var_8 += 1 - return var_7 -",1W,2 -1245,1309.Decrypt String from Alphabet to Integer Mapping_1.py,"def get(s): - return chr(ord('a') + int(s) - 1)","def sample_funcname ( var_0 ) : - return chr ( ord ( 'a' ) + int ( var_0 ) - 1 ) -",a1,2 -1246,2320.Count Number of Ways to Place Houses_1.py,"def countHousePlacements( n: int) -> int: - mod = 10**9 + 7 - f = [[0] * 2 for _ in range(n)] - f[0] = [1, 1] - for i in range(1, n): - f[i][0] = f[i - 1][0] + f[i - 1][1] - f[i][1] = f[i - 1][0] - s = sum(f[-1]) - return (s * s) % mod","def sample_funcname ( var_0 : int ) -> int : - var_5 = 10 ** 9 + 7 - var_10 = [ [ 0 ] * 2 for var_8 in range ( var_0 ) ] - var_10 [ 0 ] = [ 1 , 1 ] - for var_12 in range ( 1 , var_0 ) : - var_10 [ var_12 ] [ 0 ] = var_10 [ var_12 - 1 ] [ 0 ] + var_10 [ var_12 - 1 ] [ 1 ] - var_10 [ var_12 ] [ 1 ] = var_10 [ var_12 - 1 ] [ 0 ] - var_14 = sum ( var_10 [ - 1 ] ) - return ( var_14 * var_14 ) % var_5 -",1002719,6 -1247,0395.Longest Substring with At Least K Repeating Characters_1.py,"def longestSubstring( s: str, k: int) -> int: - n = len(s) - maxLength = 0 - - for i in range(1, 27): - counter = dict() - left = 0 - right = 0 - unique = 0 - kCount = 0 - - while right < n: - if unique <= i: - r = s[right] - counter[r] = counter.get(r, 0) + 1 - - if counter[r] == 1: - unique += 1 - if counter[r] == k: - kCount += 1 - - right += 1 - - else: - l = s[left] - counter[l] = counter.get(l, 0) - 1 - - if counter[l] == 0: - unique -= 1 - if counter[l] == k - 1: - kCount -= 1 - - left += 1 - - if unique == i and kCount == i: - maxLength = max(maxLength, right - left) - - return maxLength","def sample_funcname ( var_0 : str , var_2 : int ) -> int : - var_5 = len ( var_0 ) - var_7 = 0 - for var_11 in range ( 1 , 27 ) : - var_13 = dict ( ) - var_14 = 0 - var_15 = 0 - var_16 = 0 - var_17 = 0 - while var_15 < var_5 : - if var_16 <= var_11 : - var_18 = var_0 [ var_15 ] - var_13 [ var_18 ] = var_13.get ( var_18 , 0 ) + 1 - if var_13 [ var_18 ] == 1 : - var_16 += 1 - if var_13 [ var_18 ] == var_2 : - var_17 += 1 - var_15 += 1 - else : - var_20 = var_0 [ var_14 ] - var_13 [ var_20 ] = var_13.get ( var_20 , 0 ) - 1 - if var_13 [ var_20 ] == 0 : - var_16 -= 1 - if var_13 [ var_20 ] == var_2 - 1 : - var_17 -= 1 - var_14 += 1 - if var_16 == var_11 and var_17 == var_11 : - var_7 = max ( var_7 , var_15 - var_14 ) - return var_7 -",1027,3 -1248,2262.Total Appeal of A String_1.py,"def appealSum( s: str) -> int: - ans = t = 0 - pos = [-1] * 26 - for i, c in enumerate(s): - c = ord(c) - ord('a') - t += i - pos[c] - ans += t - pos[c] = i - return ans","def sample_funcname ( var_0 : str ) -> int : - var_5 = var_3 = 0 - var_8 = [ - 1 ] * 26 - for var_10 , var_11 in enumerate ( var_0 ) : - var_11 = ord ( var_11 ) - ord ( 'a' ) - var_3 += var_10 - var_8 [ var_11 ] - var_5 += var_3 - var_8 [ var_11 ] = var_10 - return var_5 -",10a26,4 -1249,0005.Longest Palindromic Substring_1.py,"def longestPalindrome( s: str) -> str: - n = len(s) - dp = [[False] * n for _ in range(n)] - start, mx = 0, 1 - for j in range(n): - for i in range(j + 1): - if j - i < 2: - dp[i][j] = s[i] == s[j] - else: - dp[i][j] = dp[i + 1][j - 1] and s[i] == s[j] - if dp[i][j] and mx < j - i + 1: - start, mx = i, j - i + 1 - return s[start : start + mx]","def sample_funcname ( var_0 : str ) -> str : - var_3 = len ( var_0 ) - var_7 = [ [ False ] * var_3 for var_5 in range ( var_3 ) ] - var_9 , var_11 = 0 , 1 - for var_12 in range ( var_3 ) : - for var_13 in range ( var_12 + 1 ) : - if var_12 - var_13 < 2 : - var_7 [ var_13 ] [ var_12 ] = var_0 [ var_13 ] == var_0 [ var_12 ] - else : - var_7 [ var_13 ] [ var_12 ] = var_7 [ var_13 + 1 ] [ var_12 - 1 ] and var_0 [ var_13 ] == var_0 [ var_12 ] - if var_7 [ var_13 ] [ var_12 ] and var_11 < var_12 - var_13 + 1 : - var_9 , var_11 = var_13 , var_12 - var_13 + 1 - return var_0 [ var_9 : var_9 + var_11 ] -",102,3 -1250,1864.Minimum Number of Swaps to Make the Binary String Alternating_1.py,"def minSwaps( s: str) -> int: - s0n0 = s0n1 = s1n0 = s1n1 = 0 - for i in range(len(s)): - if (i & 1) == 0: - if s[i] != '0': - s0n0 += 1 - else: - s1n1 += 1 - else: - if s[i] != '0': - s1n0 += 1 - else: - s0n1 += 1 - if s0n0 != s0n1 and s1n0 != s1n1: - return -1 - if s0n0 != s0n1: - return s1n0 - if s1n0 != s1n1: - return s0n0 - return min(s0n0, s1n0)","def sample_funcname ( var_0 : str ) -> int : - var_7 = var_3 = var_4 = var_5 = 0 - for var_10 in range ( len ( var_0 ) ) : - if ( var_10 & 1 ) == 0 : - if var_0 [ var_10 ] != '0' : - var_7 += 1 - else : - var_5 += 1 - else : - if var_0 [ var_10 ] != '0' : - var_4 += 1 - else : - var_3 += 1 - if var_7 != var_3 and var_4 != var_5 : - return - 1 - if var_7 != var_3 : - return var_4 - if var_4 != var_5 : - return var_7 - return min ( var_7 , var_4 ) -",100,3 -1251,0072.Edit Distance_1.py,"def minDistance( word1: str, word2: str) -> int: - m, n = len(word1), len(word2) - dp = [[0] * (n + 1) for _ in range(m + 1)] - for i in range(m + 1): - dp[i][0] = i - for j in range(n + 1): - dp[0][j] = j - for i in range(1, m + 1): - for j in range(1, n + 1): - if word1[i - 1] == word2[j - 1]: - dp[i][j] = dp[i - 1][j - 1] - else: - dp[i][j] = min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1 - return dp[-1][-1]","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - var_5 , var_6 = len ( var_0 ) , len ( var_2 ) - var_11 = [ [ 0 ] * ( var_6 + 1 ) for var_9 in range ( var_5 + 1 ) ] - for var_12 in range ( var_5 + 1 ) : - var_11 [ var_12 ] [ 0 ] = var_12 - for var_13 in range ( var_6 + 1 ) : - var_11 [ 0 ] [ var_13 ] = var_13 - for var_12 in range ( 1 , var_5 + 1 ) : - for var_13 in range ( 1 , var_6 + 1 ) : - if var_0 [ var_12 - 1 ] == var_2 [ var_13 - 1 ] : - var_11 [ var_12 ] [ var_13 ] = var_11 [ var_12 - 1 ] [ var_13 - 1 ] - else : - var_11 [ var_12 ] [ var_13 ] = min ( var_11 [ var_12 ] [ var_13 - 1 ] , var_11 [ var_12 - 1 ] [ var_13 ] , var_11 [ var_12 - 1 ] [ var_13 - 1 ] ) + 1 - return var_11 [ - 1 ] [ - 1 ] -",10,2 -1252,1832.Check if the Sentence Is Pangram_1.py,"def checkIfPangram( sentence: str) -> bool: - res = 0 - for c in sentence: - res |= 1 << (ord(c) - ord('a')) - if res == 0x3FFFFFF: - return True - return False","def sample_funcname ( var_0 : str ) -> bool : - var_4 = 0 - for var_5 in var_0 : - var_4 |= 1 << ( ord ( var_5 ) - ord ( 'a' ) ) - if var_4 == 0x3FFFFFF : - return True - return False -",100x3FFFFFFa,4 -1253,2158.Amount of New Area Painted Each Day_1.py,"def pushup( node): - node.v = node.left.v + node.right.v","def sample_funcname ( var_0 ) : - var_0.v = var_0.var_1.v + var_0.var_3.v -",,0 -1254,1245.Tree Diameter_1.py,"def dfs(u, t): - nonlocal ans, vis, d, next - if vis[u]: - return - vis[u] = True - for v in d[u]: - dfs(v, t + 1) - if ans < t: - ans = t - next = u","def sample_funcname ( var_1 , var_2 ) : - nonlocal var_3 , var_4 , var_5 , var_6 - if var_4 [ var_1 ] : - return - var_4 [ var_1 ] = True - for var_8 in var_5 [ var_1 ] : - var_0 ( var_8 , var_2 + 1 ) - if var_3 < var_2 : - var_3 = var_2 - var_6 = var_1 -",1,1 -1255,2323.Find Minimum Time to Finish All Jobs II_1.py,"def minimumTime( jobs: List[int], workers: List[int]) -> int: - jobs.sort() - workers.sort() - return max((a + b - 1) // b for a, b in zip(jobs, workers))","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_0.sort ( ) - var_3.sort ( ) - return max ( ( var_6 + var_7 - 1 ) // var_7 for var_6 , var_7 in zip ( var_0 , var_3 ) ) -",1,1 -1256,1725.Number Of Rectangles That Can Form The Largest Square_1.py,"def countGoodRectangles( rectangles: List[List[int]]) -> int: - ans = mx = 0 - for l, w in rectangles: - t = min(l, w) - if mx < t: - mx, ans = t, 1 - elif mx == t: - ans += 1 - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_5 = var_3 = 0 - for var_6 , var_7 in var_0 : - var_9 = min ( var_6 , var_7 ) - if var_3 < var_9 : - var_3 , var_5 = var_9 , 1 - elif var_3 == var_9 : - var_5 += 1 - return var_5 -",10,2 -1257,0459.Repeated Substring Pattern_1.py,"def repeatedSubstringPattern( s: str) -> bool: - return (s + s).index(s, 1) < len(s)","def sample_funcname ( var_0 : str ) -> bool : - return ( var_0 + var_0 ).index ( var_0 , 1 ) < len ( var_0 ) -",1,1 -1258,0523.Continuous Subarray Sum_1.py,"def checkSubarraySum( nums: List[int], k: int) -> bool: - s = 0 - mp = {0: -1} - for i, v in enumerate(nums): - s += v - r = s % k - if r in mp and i - mp[r] >= 2: - return True - if r not in mp: - mp[r] = i - return False","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> bool : - var_6 = 0 - var_8 = { 0 : - 1 } - for var_10 , var_11 in enumerate ( var_0 ) : - var_6 += var_11 - var_12 = var_6 % var_3 - if var_12 in var_8 and var_10 - var_8 [ var_12 ] >= 2 : - return True - if var_12 not in var_8 : - var_8 [ var_12 ] = var_10 - return False -",102,3 -1259,0128.Longest Consecutive Sequence_1.py,"def longestConsecutive( nums: List[int]) -> int: - s, res = set(nums), 0 - for num in nums: - if num - 1 not in s: - t, next = 1, num + 1 - while next in s: - t, next = t + 1, next + 1 - res = max(res, t) - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_6 = set ( var_0 ) , 0 - for var_7 in var_0 : - if var_7 - 1 not in var_4 : - var_9 , var_10 = 1 , var_7 + 1 - while var_10 in var_4 : - var_9 , var_10 = var_9 + 1 , var_10 + 1 - var_6 = max ( var_6 , var_9 ) - return var_6 -",10,2 -1260,1921.Eliminate Maximum Number of Monsters_1.py,"def eliminateMaximum( dist: List[int], speed: List[int]) -> int: - n = len(dist) - times = [(dist[i] - 1) // speed[i] for i in range(n)] - times.sort() - for i in range(n): - if times[i] < i: - return i - return n","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_5 = len ( var_0 ) - var_9 = [ ( var_0 [ var_6 ] - 1 ) // var_3 [ var_6 ] for var_6 in range ( var_5 ) ] - var_9.sort ( ) - for var_6 in range ( var_5 ) : - if var_9 [ var_6 ] < var_6 : - return var_6 - return var_5 -",1,1 -1261,0655.Print Binary Tree_1.py,"def height(root): - if root is None: - return -1 - return 1 + max(height(root.left), height(root.right))","def sample_funcname ( var_1 ) : - if var_1 is None : - return - 1 - return 1 + max ( var_0 ( var_1.left ) , var_0 ( var_1.right ) ) -",1None,2 -1262,0377.Combination Sum IV_1.py,"def combinationSum4( nums: List[int], target: int) -> int: - dp = [0] * (target + 1) - dp[0] = 1 - for i in range(1, target + 1): - for num in nums: - if i >= num: - dp[i] += dp[i - num] - return dp[-1]","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_6 = [ 0 ] * ( var_3 + 1 ) - var_6 [ 0 ] = 1 - for var_8 in range ( 1 , var_3 + 1 ) : - for var_9 in var_0 : - if var_8 >= var_9 : - var_6 [ var_8 ] += var_6 [ var_8 - var_9 ] - return var_6 [ - 1 ] -",10,2 -1263,1288.Remove Covered Intervals_1.py,"def removeCoveredIntervals( intervals: List[List[int]]) -> int: - intervals.sort(key=lambda x: (x[0], -x[1])) - cnt, pre = 1, intervals[0] - for e in intervals[1:]: - if pre[1] < e[1]: - cnt += 1 - pre = e - return cnt","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_0.sort ( var_4 = lambda var_5 : ( var_5 [ 0 ] , - var_5 [ 1 ] ) ) - var_8 , var_9 = 1 , var_0 [ 0 ] - for var_10 in var_0 [ 1 : ] : - if var_9 [ 1 ] < var_10 [ 1 ] : - var_8 += 1 - var_9 = var_10 - return var_8 -",10,2 -1264,0288.Unique Word Abbreviation_1.py,"def word_abbr( s): - return s if len(s) < 3 else f'{s[0]}{len(s) - 2}{s[-1]}'","def sample_funcname ( var_0 ) : - return var_0 if len ( var_0 ) < 3 else f'{var_0[0]}{len(var_0) - 2}{var_0[-1]}' -",3f{var_0[0]}{len(var_0) - 2}{var_0[-1]},2 -1265,2057.Smallest Index With Equal Value_1.py,"def smallestEqual( nums: List[int]) -> int: - for i, v in enumerate(nums): - if i % 10 == v: - return i - return -1","def sample_funcname ( var_0 : List [ int ] ) -> int : - for var_4 , var_5 in enumerate ( var_0 ) : - if var_4 % 10 == var_5 : - return var_4 - return - 1 -",101,2 -1266,0591.Tag Validator_1.py,"def check(tag): - return 1 <= len(tag) <= 9 and all(c.isupper() for c in tag)","def sample_funcname ( var_0 ) : - return 1 <= len ( var_0 ) <= 9 and all ( var_5.isupper ( ) for var_5 in var_0 ) -",91,2 -1267,2075.Decode the Slanted Ciphertext_1.py,"def decodeCiphertext( encodedText: str, rows: int) -> str: - ans = [] - cols = len(encodedText) // rows - for j in range(cols): - x, y = 0, j - while x < rows and y < cols: - ans.append(encodedText[x * cols + y]) - x, y = x + 1, y + 1 - return ''.join(ans).rstrip()","def sample_funcname ( var_0 : str , var_2 : int ) -> str : - var_4 = [ ] - var_6 = len ( var_0 ) // var_2 - for var_8 in range ( var_6 ) : - var_10 , var_11 = 0 , var_8 - while var_10 < var_2 and var_11 < var_6 : - var_4.append ( var_0 [ var_10 * var_6 + var_11 ] ) - var_10 , var_11 = var_10 + 1 , var_11 + 1 - return ''.var_15 ( var_4 ).rstrip ( ) -",10,3 -1268,1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K_1.py,"def dfs(k): - if k < 2: - return k - a = b = 1 - while b <= k: - a, b = b, a + b - return 1 + dfs(k - a)","def sample_funcname ( var_1 ) : - if var_1 < 2 : - return var_1 - var_5 = var_3 = 1 - while var_3 <= var_1 : - var_5 , var_3 = var_3 , var_5 + var_3 - return 1 + var_0 ( var_1 - var_5 ) -",12,2 -1269,2164.Sort Even and Odd Indices Independently_1.py,"def sortEvenOdd( nums: List[int]) -> List[int]: - a = sorted(nums[::2]) - b = sorted(nums[1::2], reverse=True) - nums[::2] = a - nums[1::2] = b - return nums","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_5 = sorted ( var_0 [ : : 2 ] ) - var_9 = sorted ( var_0 [ 1 : : 2 ] , var_7 = True ) - var_0 [ : : 2 ] = var_5 - var_0 [ 1 : : 2 ] = var_9 - return var_0 -",12,2 -1270,1502.Can Make Arithmetic Progression From Sequence_1.py,"def canMakeArithmeticProgression( arr: List[int]) -> bool: - arr.sort() - for i in range(1, len(arr) - 1): - if (arr[i] << 1) != arr[i - 1] + arr[i + 1]: - return False - return True","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_0.sort ( ) - for var_8 in range ( 1 , len ( var_0 ) - 1 ) : - if ( var_0 [ var_8 ] << 1 ) != var_0 [ var_8 - 1 ] + var_0 [ var_8 + 1 ] : - return False - return True -",1,1 -1271,1392.Longest Happy Prefix_1.py,"def longestPrefix( s: str) -> str: - for i in range(1, len(s)): - if s[:-i] == s[i:]: - return s[i:] - return ''","def sample_funcname ( var_0 : str ) -> str : - for var_5 in range ( 1 , len ( var_0 ) ) : - if var_0 [ : - var_5 ] == var_0 [ var_5 : ] : - return var_0 [ var_5 : ] - return '' -",1,2 -1272,0789.Escape The Ghosts_1.py,"def escapeGhosts( ghosts, target): - flag = abs(target[0]) + abs(target[1]) - for i in ghosts: - if abs(i[0] - target[0]) + abs(i[1] - target[1]) <= flag: - return False - else: - return True","def sample_funcname ( var_0 , var_1 ) : - var_5 = abs ( var_1 [ 0 ] ) + abs ( var_1 [ 1 ] ) - for var_6 in var_0 : - if abs ( var_6 [ 0 ] - var_1 [ 0 ] ) + abs ( var_6 [ 1 ] - var_1 [ 1 ] ) <= var_5 : - return False - else : - return True -",10,2 -1273,2289.Steps to Make Array Non-decreasing_1.py,"def totalSteps( nums: List[int]) -> int: - stk = [] - ans, n = 0, len(nums) - dp = [0] * n - for i in range(n - 1, -1, -1): - while stk and nums[i] > nums[stk[-1]]: - dp[i] = max(dp[i] + 1, dp[stk.pop()]) - stk.append(i) - return max(dp)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_3 = [ ] - var_5 , var_7 = 0 , len ( var_0 ) - var_8 = [ 0 ] * var_7 - for var_11 in range ( var_7 - 1 , - 1 , - 1 ) : - while var_3 and var_0 [ var_11 ] > var_0 [ var_3 [ - 1 ] ] : - var_8 [ var_11 ] = max ( var_8 [ var_11 ] + 1 , var_8 [ var_3.pop ( ) ] ) - var_3.append ( var_11 ) - return max ( var_8 ) -",10,2 -1274,1560.Most Visited Sector in a Circular Track_1.py,"def mostVisited( n: int, rounds: List[int]) -> List[int]: - if rounds[0] <= rounds[-1]: - return list(range(rounds[0], rounds[-1] + 1)) - return list(range(1, rounds[-1] + 1)) + list(range(rounds[0], n + 1))","def sample_funcname ( var_0 : int , var_2 : List [ int ] ) -> List [ int ] : - if var_2 [ 0 ] <= var_2 [ - 1 ] : - return list ( range ( var_2 [ 0 ] , var_2 [ - 1 ] + 1 ) ) - return list ( range ( 1 , var_2 [ - 1 ] + 1 ) ) + list ( range ( var_2 [ 0 ] , var_0 + 1 ) ) -",10,2 -1275,1899.Merge Triplets to Form Target Triplet_1.py,"def mergeTriplets( triplets: List[List[int]], target: List[int]) -> bool: - maxA = maxB = maxC = 0 - tA, tB, tC = target - for a, b, c in triplets: - if a <= tA and b <= tB and c <= tC: - maxA = max(maxA, a) - maxB = max(maxB, b) - maxC = max(maxC, c) - return (maxA, maxB, maxC) == (tA, tB, tC)","def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : List [ int ] ) -> bool : - var_8 = var_5 = var_6 = 0 - var_9 , var_10 , var_11 = var_3 - for var_12 , var_13 , var_14 in var_0 : - if var_12 <= var_9 and var_13 <= var_10 and var_14 <= var_11 : - var_8 = max ( var_8 , var_12 ) - var_5 = max ( var_5 , var_13 ) - var_6 = max ( var_6 , var_14 ) - return ( var_8 , var_5 , var_6 ) == ( var_9 , var_10 , var_11 ) -",0,1 -1276,2167.Minimum Time to Remove All Cars Containing Illegal Goods_1.py,"def minimumTime( s: str) -> int: - n = len(s) - pre = [0] * (n + 1) - suf = [0] * (n + 1) - for i, c in enumerate(s): - pre[i + 1] = pre[i] if c == '0' else min(pre[i] + 2, i + 1) - for i in range(n - 1, -1, -1): - suf[i] = suf[i + 1] if s[i] == '0' else min(suf[i + 1] + 2, n - i) - return min(a + b for a, b in zip(pre[1:], suf[1:]))","def sample_funcname ( var_0 : str ) -> int : - var_4 = len ( var_0 ) - var_7 = [ 0 ] * ( var_4 + 1 ) - var_8 = [ 0 ] * ( var_4 + 1 ) - for var_10 , var_11 in enumerate ( var_0 ) : - var_7 [ var_10 + 1 ] = var_7 [ var_10 ] if var_11 == '0' else min ( var_7 [ var_10 ] + 2 , var_10 + 1 ) - for var_10 in range ( var_4 - 1 , - 1 , - 1 ) : - var_8 [ var_10 ] = var_8 [ var_10 + 1 ] if var_0 [ var_10 ] == '0' else min ( var_8 [ var_10 + 1 ] + 2 , var_4 - var_10 ) - return min ( var_16 + var_17 for var_16 , var_17 in zip ( var_7 [ 1 : ] , var_8 [ 1 : ] ) ) -",1002,4 -1277,1505.Minimum Possible Integer After at Most K Adjacent Swaps On Digits_1.py,"def lowbit(x): - return x & -x","def sample_funcname ( var_0 ) : - return var_0 & - var_0 -",,0 -1278,1227.Airplane Seat Assignment Probability_1.py,"def nthPersonGetsNthSeat( n: int) -> float: - return 1 if n == 1 else 0.5","def sample_funcname ( var_0 : int ) -> float : - return 1 if var_0 == 1 else 0.5 -",10.5,2 -1279,0861.Score After Flipping Matrix_1.py,"def matrixScore( grid: List[List[int]]) -> int: - m, n = len(grid), len(grid[0]) - for i in range(m): - if grid[i][0] == 0: - for j in range(n): - grid[i][j] ^= 1 - - res = 0 - for j in range(n): - cnt = 0 - for i in range(m): - cnt += grid[i][j] - res += max(cnt, m - cnt) * (1 << (n - j - 1)) - return res","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - for var_8 in range ( var_4 ) : - if var_0 [ var_8 ] [ 0 ] == 0 : - for var_9 in range ( var_6 ) : - var_0 [ var_8 ] [ var_9 ] ^= 1 - var_11 = 0 - for var_9 in range ( var_6 ) : - var_12 = 0 - for var_8 in range ( var_4 ) : - var_12 += var_0 [ var_8 ] [ var_9 ] - var_11 += max ( var_12 , var_4 - var_12 ) * ( 1 << ( var_6 - var_9 - 1 ) ) - return var_11 -",10,2 -1280,1964.Find the Longest Valid Obstacle Course at Each Position_1.py,"def lowbit(x): - return x & -x","def sample_funcname ( var_0 ) : - return var_0 & - var_0 -",,0 -1281,2177.Find Three Consecutive Integers That Sum to a Given Number_1.py,"def sumOfThree( num: int) -> List[int]: - a, b = divmod(num, 3) - return [] if b else [a - 1, a, a + 1]","def sample_funcname ( var_0 : int ) -> List [ int ] : - var_4 , var_6 = divmod ( var_0 , 3 ) - return [ ] if var_6 else [ var_4 - 1 , var_4 , var_4 + 1 ] -",31,2 -1282,0434.Number of Segments in a String_1.py,"def countSegments( s: str) -> int: - res = 0 - for i in range(len(s)): - if s[i] != ' ' and (i == 0 or s[i - 1] == ' '): - res += 1 - return res","def sample_funcname ( var_0 : str ) -> int : - var_4 = 0 - for var_7 in range ( len ( var_0 ) ) : - if var_0 [ var_7 ] != ' ' and ( var_7 == 0 or var_0 [ var_7 - 1 ] == ' ' ) : - var_4 += 1 - return var_4 -",10 ,3 -1283,0048.Rotate Image_1.py,"def rotate( matrix: List[List[int]]) -> None: - s, n = 0, len(matrix) - while s < (n >> 1): - e = n - s - 1 - for i in range(s, e): - t = matrix[i][e] - matrix[i][e] = matrix[s][i] - matrix[s][i] = matrix[n - i - 1][s] - matrix[n - i - 1][s] = matrix[e][n - i - 1] - matrix[e][n - i - 1] = t - s += 1","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> None : - var_5 , var_7 = 0 , len ( var_0 ) - while var_5 < ( var_7 >> 1 ) : - var_9 = var_7 - var_5 - 1 - for var_11 in range ( var_5 , var_9 ) : - var_12 = var_0 [ var_11 ] [ var_9 ] - var_0 [ var_11 ] [ var_9 ] = var_0 [ var_5 ] [ var_11 ] - var_0 [ var_5 ] [ var_11 ] = var_0 [ var_7 - var_11 - 1 ] [ var_5 ] - var_0 [ var_7 - var_11 - 1 ] [ var_5 ] = var_0 [ var_9 ] [ var_7 - var_11 - 1 ] - var_0 [ var_9 ] [ var_7 - var_11 - 1 ] = var_12 - var_5 += 1 -",10None,3 -1284,0397.Integer Replacement_1.py,"def integerReplacement( n: int) -> int: - ans = 0 - while n != 1: - if (n & 1) == 0: - n >>= 1 - elif n != 3 and (n & 3) == 3: - n += 1 - else: - n -= 1 - ans += 1 - return ans","def sample_funcname ( var_0 : int ) -> int : - var_3 = 0 - while var_0 != 1 : - if ( var_0 & 1 ) == 0 : - var_0 >>= 1 - elif var_0 != 3 and ( var_0 & 3 ) == 3 : - var_0 += 1 - else : - var_0 -= 1 - var_3 += 1 - return var_3 -",130,3 -1285,1903.Largest Odd Number in String_1.py,"def largestOddNumber( num: str) -> str: - for i in range(len(num) - 1, -1, -1): - if (int(num[i]) & 1) == 1: - return num[: i + 1] - return ''","def sample_funcname ( var_0 : str ) -> str : - for var_5 in range ( len ( var_0 ) - 1 , - 1 , - 1 ) : - if ( int ( var_0 [ var_5 ] ) & 1 ) == 1 : - return var_0 [ : var_5 + 1 ] - return '' -",1,2 -1286,1464.Maximum Product of Two Elements in an Array_1.py,"def maxProduct( nums: List[int]) -> int: - a = b = 0 - for v in nums: - if v > a: - a, b = v, a - elif v > b: - b = v - return (a - 1) * (b - 1)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - for var_6 in var_0 : - if var_6 > var_5 : - var_5 , var_3 = var_6 , var_5 - elif var_6 > var_3 : - var_3 = var_6 - return ( var_5 - 1 ) * ( var_3 - 1 ) -",10,2 -1287,0693.Binary Number with Alternating Bits_1.py,"def hasAlternatingBits( n: int) -> bool: - n ^= n >> 1 - return (n & (n + 1)) == 0","def sample_funcname ( var_0 : int ) -> bool : - var_0 ^= var_0 >> 1 - return ( var_0 & ( var_0 + 1 ) ) == 0 -",10,2 -1288,2136.Earliest Possible Day of Full Bloom_1.py,"def earliestFullBloom( plantTime: List[int], growTime: List[int]) -> int: - ans = t = 0 - for a, b in sorted(zip(plantTime, growTime), key=lambda x: -x[1]): - t += a - ans = max(ans, t + b) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_6 = var_4 = 0 - for var_8 , var_13 in sorted ( zip ( var_0 , var_3 ) , var_11 = lambda var_12 : - var_12 [ 1 ] ) : - var_4 += var_8 - var_6 = max ( var_6 , var_4 + var_13 ) - return var_6 -",10,2 -1289,0325.Maximum Size Subarray Sum Equals k_1.py,"def maxSubArrayLen( nums: List[int], k: int) -> int: - mp = {0: -1} - s = ans = 0 - for i, v in enumerate(nums): - s += v - if s - k in mp: - ans = max(ans, i - mp[s - k]) - if s not in mp: - mp[s] = i - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_6 = { 0 : - 1 } - var_8 = var_7 = 0 - for var_10 , var_11 in enumerate ( var_0 ) : - var_8 += var_11 - if var_8 - var_3 in var_6 : - var_7 = max ( var_7 , var_10 - var_6 [ var_8 - var_3 ] ) - if var_8 not in var_6 : - var_6 [ var_8 ] = var_10 - return var_7 -",10,2 -1290,0564.Find the Closest Palindrome_1.py,"def nearestPalindromic( n: str) -> str: - x = int(n) - l = len(n) - res = {10 ** (l - 1) - 1, 10**l + 1} - left = int(n[: (l + 1) >> 1]) - for i in range(left - 1, left + 2): - j = i if l % 2 == 0 else i // 10 - while j: - i = i * 10 + j % 10 - j //= 10 - res.add(i) - res.discard(x) - - ans = -1 - for t in res: - if ( - ans == -1 - or abs(t - x) < abs(ans - x) - or (abs(t - x) == abs(ans - x) and t < ans) - ): - ans = t - return str(ans)","def sample_funcname ( var_0 : str ) -> str : - var_3 = int ( var_0 ) - var_5 = len ( var_0 ) - var_8 = { 10 ** ( var_5 - 1 ) - 1 , 10 ** var_5 + 1 } - var_9 = int ( var_0 [ : ( var_5 + 1 ) >> 1 ] ) - for var_12 in range ( var_9 - 1 , var_9 + 2 ) : - var_14 = var_12 if var_5 % 2 == 0 else var_12 // 10 - while var_14 : - var_12 = var_12 * 10 + var_14 % 10 - var_14 //= 10 - var_8.add ( var_12 ) - var_8.discard ( var_3 ) - var_17 = - 1 - for var_18 in var_8 : - if ( var_17 == - 1 or abs ( var_18 - var_3 ) < abs ( var_17 - var_3 ) or ( abs ( var_18 - var_3 ) == abs ( var_17 - var_3 ) and var_18 < var_17 ) ) : - var_17 = var_18 - return str ( var_17 ) -",10102,4 -1291,1880.Check if Word Equals Summation of Two Words_1.py,"def f(s): - res = 0 - for c in s: - res = res * 10 + (ord(c) - ord('a')) - return res","def sample_funcname ( var_0 ) : - var_2 = 0 - for var_3 in var_0 : - var_2 = var_2 * 10 + ( ord ( var_3 ) - ord ( 'a' ) ) - return var_2 -",100a,3 -1292,1619.Mean of Array After Removing Some Elements_1.py,"def trimMean( arr: List[int]) -> float: - n = len(arr) - start, end = int(n * 0.05), int(n * 0.95) - arr.sort() - t = arr[start:end] - return round(sum(t) / len(t), 5)","def sample_funcname ( var_0 : List [ int ] ) -> float : - var_5 = len ( var_0 ) - var_7 , var_9 = int ( var_5 * 0.05 ) , int ( var_5 * 0.95 ) - var_0.sort ( ) - var_11 = var_0 [ var_7 : var_9 ] - return round ( sum ( var_11 ) / len ( var_11 ) , 5 ) -",50.050.95,3 -1293,1557.Minimum Number of Vertices to Reach All Nodes_1.py,"def findSmallestSetOfVertices( n: int, edges: List[List[int]]) -> List[int]: - s = {to for _, to in edges} - return [i for i in range(n) if i not in s]","def sample_funcname ( var_0 : int , var_2 : List [ List [ int ] ] ) -> List [ int ] : - var_6 = { var_4 for var_5 , var_4 in var_2 } - return [ var_7 for var_7 in range ( var_0 ) if var_7 not in var_6 ] -",,0 -1295,1984.Minimum Difference Between Highest and Lowest of K Scores_1.py,"def minimumDifference( nums: List[int], k: int) -> int: - nums.sort() - return min(nums[i + k - 1] - nums[i] for i in range(len(nums) - k + 1))","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_0.sort ( ) - return min ( var_0 [ var_6 + var_3 - 1 ] - var_0 [ var_6 ] for var_6 in range ( len ( var_0 ) - var_3 + 1 ) ) -",1,1 -1296,1588.Sum of All Odd Length Subarrays_1.py,"def sumOddLengthSubarrays( arr: List[int]) -> int: - n = len(arr) - presum = [0] * (n + 1) - for i in range(n): - presum[i + 1] = presum[i] + arr[i] - - res = 0 - for i in range(n): - for j in range(0, n, 2): - if i + j < n: - res += presum[i + j + 1] - presum[i] - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_7 = [ 0 ] * ( var_4 + 1 ) - for var_9 in range ( var_4 ) : - var_7 [ var_9 + 1 ] = var_7 [ var_9 ] + var_0 [ var_9 ] - var_10 = 0 - for var_9 in range ( var_4 ) : - for var_12 in range ( 0 , var_4 , 2 ) : - if var_9 + var_12 < var_4 : - var_10 += var_7 [ var_9 + var_12 + 1 ] - var_7 [ var_9 ] - return var_10 -",102,3 -1298,2215.Find the Difference of Two Arrays_1.py,"def findDifference( nums1: List[int], nums2: List[int]) -> List[List[int]]: - s1, s2 = set(nums1), set(nums2) - return [list(s1 - s2), list(s2 - s1)]","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> List [ List [ int ] ] : - var_5 , var_6 = set ( var_0 ) , set ( var_3 ) - return [ list ( var_5 - var_6 ) , list ( var_6 - var_5 ) ] -",,0 -1299,0945.Minimum Increment to Make Array Unique_1.py,"def minIncrementForUnique( nums: List[int]) -> int: - nums.sort() - ans = 0 - for i in range(1, len(nums)): - if nums[i] <= nums[i - 1]: - d = nums[i - 1] - nums[i] + 1 - nums[i] += d - ans += d - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( ) - var_5 = 0 - for var_9 in range ( 1 , len ( var_0 ) ) : - if var_0 [ var_9 ] <= var_0 [ var_9 - 1 ] : - var_10 = var_0 [ var_9 - 1 ] - var_0 [ var_9 ] + 1 - var_0 [ var_9 ] += var_10 - var_5 += var_10 - return var_5 -",10,2 -1300,2148.Count Elements With Strictly Smaller and Greater Elements_1.py,"def countElements( nums: List[int]) -> int: - mi, mx = min(nums), max(nums) - return sum(mi < num < mx for num in nums)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_6 = min ( var_0 ) , max ( var_0 ) - return sum ( var_4 < var_8 < var_6 for var_8 in var_0 ) -",,0 -1301,1592.Rearrange Spaces Between Words_1.py,"def reorderSpaces( text: str) -> str: - cnt = text.count(' ') - words = text.split() - m = len(words) - 1 - if m == 0: - return words[0] + ' ' * cnt - return (' ' * (cnt // m)).join(words) + ' ' * (cnt % m)","def sample_funcname ( var_0 : str ) -> str : - var_4 = var_0.count ( ' ' ) - var_6 = var_0.split ( ) - var_9 = len ( var_6 ) - 1 - if var_9 == 0 : - return var_6 [ 0 ] + ' ' * var_4 - return ( ' ' * ( var_4 // var_9 ) ).join ( var_6 ) + ' ' * ( var_4 % var_9 ) -",1 0,3 -1302,2288.Apply Discount to Prices_1.py,"def discountPrices( sentence: str, discount: int) -> str: - ans = [] - for w in sentence.split(): - if w[0] == '$' and w[1:].isdigit(): - t = int(w[1:]) * (1 - discount / 100) - ans.append('$' + '{:.2f}'.format(t)) - else: - ans.append(w) - return ' '.join(ans)","def sample_funcname ( var_0 : str , var_2 : int ) -> str : - var_4 = [ ] - for var_6 in var_0.split ( ) : - if var_6 [ 0 ] == '$' and var_6 [ 1 : ].isdigit ( ) : - var_12 = int ( var_6 [ 1 : ] ) * ( 1 - var_2 / 100 ) - var_4.append ( '$' + '{:.2f}'.format ( var_12 ) ) - else : - var_4.append ( var_6 ) - return ' '.join ( var_4 ) -",0$1{:.2f}100 ,6 -1303,0327.Count of Range Sum_1.py,"def lowbit(x): - return x & -x","def sample_funcname ( var_0 ) : - return var_0 & - var_0 -",,0 -1304,0292.Nim Game_1.py,"def canWinNim( n: int) -> bool: - return n % 4 != 0","def sample_funcname ( var_0 : int ) -> bool : - return var_0 % 4 != 0 -",04,2 -1305,0643.Maximum Average Subarray I_1.py,"def findMaxAverage( nums: List[int], k: int) -> float: - s = sum(nums[:k]) - ans = s - for i in range(k, len(nums)): - s += nums[i] - nums[i - k] - ans = max(ans, s) - return ans / k","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> float : - var_6 = sum ( var_0 [ : var_3 ] ) - var_7 = var_6 - for var_10 in range ( var_3 , len ( var_0 ) ) : - var_6 += var_0 [ var_10 ] - var_0 [ var_10 - var_3 ] - var_7 = max ( var_7 , var_6 ) - return var_7 / var_3 -",,0 -1306,1996.The Number of Weak Characters in the Game_1.py,"def numberOfWeakCharacters( properties: List[List[int]]) -> int: - properties.sort(key=lambda x: (-x[0], x[1])) - ans = mx = 0 - for _, d in properties: - if mx > d: - ans += 1 - mx = max(mx, d) - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_0.sort ( var_4 = lambda var_5 : ( - var_5 [ 0 ] , var_5 [ 1 ] ) ) - var_9 = var_8 = 0 - for var_10 , var_11 in var_0 : - if var_8 > var_11 : - var_9 += 1 - var_8 = max ( var_8 , var_11 ) - return var_9 -",10,2 -1307,2105.Watering Plants II_1.py,"def minimumRefill( plants: List[int], capacityA: int, capacityB: int) -> int: - i, j = 0, len(plants) - 1 - ans = 0 - a, b = capacityA, capacityB - while i <= j: - if i == j: - if max(capacityA, capacityB) < plants[i]: - ans += 1 - break - if capacityA < plants[i]: - capacityA = a - plants[i] - ans += 1 - else: - capacityA -= plants[i] - if capacityB < plants[j]: - capacityB = b - plants[j] - ans += 1 - else: - capacityB -= plants[j] - i += 1 - j -= 1 - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int , var_4 : int ) -> int : - var_6 , var_9 = 0 , len ( var_0 ) - 1 - var_10 = 0 - var_11 , var_12 = var_3 , var_4 - while var_6 <= var_9 : - if var_6 == var_9 : - if max ( var_3 , var_4 ) < var_0 [ var_6 ] : - var_10 += 1 - break - if var_3 < var_0 [ var_6 ] : - var_3 = var_11 - var_0 [ var_6 ] - var_10 += 1 - else : - var_3 -= var_0 [ var_6 ] - if var_4 < var_0 [ var_9 ] : - var_4 = var_12 - var_0 [ var_9 ] - var_10 += 1 - else : - var_4 -= var_0 [ var_9 ] - var_6 += 1 - var_9 -= 1 - return var_10 -",10,2 -1308,0484.Find Permutation_1.py,"def findPermutation( s: str) -> List[int]: - n = len(s) - ans = list(range(1, n + 2)) - i = 0 - while i < n: - j = i - while j < n and s[j] == 'D': - j += 1 - ans[i: j + 1] = ans[i: j + 1][::-1] - i = max(i + 1, j) - return ans","def sample_funcname ( var_0 : str ) -> List [ int ] : - var_5 = len ( var_0 ) - var_10 = list ( range ( 1 , var_5 + 2 ) ) - var_12 = 0 - while var_12 < var_5 : - var_13 = var_12 - while var_13 < var_5 and var_0 [ var_13 ] == 'D' : - var_13 += 1 - var_10 [ var_12 : var_13 + 1 ] = var_10 [ var_12 : var_13 + 1 ] [ : : - 1 ] - var_12 = max ( var_12 + 1 , var_13 ) - return var_10 -",1D02,4 -1309,1452.People Whose List of Favorite Companies Is Not a Subset of Another List_1.py,"def peopleIndexes( favoriteCompanies: List[List[str]]) -> List[int]: - d = {} - idx = 0 - t = [] - for v in favoriteCompanies: - for c in v: - if c not in d: - d[c] = idx - idx += 1 - t.append({d[c] for c in v}) - ans = [] - for i, nums1 in enumerate(t): - ok = True - for j, nums2 in enumerate(t): - if i == j: - continue - if not (nums1 - nums2): - ok = False - break - if ok: - ans.append(i) - return ans","def sample_funcname ( var_0 : List [ List [ str ] ] ) -> List [ int ] : - var_4 = { } - var_6 = 0 - var_7 = [ ] - for var_8 in var_0 : - for var_9 in var_8 : - if var_9 not in var_4 : - var_4 [ var_9 ] = var_6 - var_6 += 1 - var_7.append ( { var_4 [ var_9 ] for var_9 in var_8 } ) - var_12 = [ ] - for var_14 , var_15 in enumerate ( var_7 ) : - var_17 = True - for var_18 , var_19 in enumerate ( var_7 ) : - if var_14 == var_18 : - continue - if not ( var_15 - var_19 ) : - var_17 = False - break - if var_17 : - var_12.append ( var_14 ) - return var_12 -",10,2 -1310,2120.Execution of All Suffix Instructions Staying in a Grid_1.py,"def executeInstructions( n: int, startPos: List[int], s: str) -> List[int]: - ans = [] - m = len(s) - mp = {""L"": [0, -1], ""R"": [0, 1], ""U"": [-1, 0], ""D"": [1, 0]} - for i in range(m): - x, y = startPos - t = 0 - for j in range(i, m): - a, b = mp[s[j]] - if 0 <= x + a < n and 0 <= y + b < n: - x, y, t = x + a, y + b, t + 1 - else: - break - ans.append(t) - return ans","def sample_funcname ( var_0 : int , var_2 : List [ int ] , var_4 : str ) -> List [ int ] : - var_6 = [ ] - var_8 = len ( var_4 ) - var_15 = { ""L"" : [ 0 , - 1 ] , ""R"" : [ 0 , 1 ] , ""U"" : [ - 1 , 0 ] , ""D"" : [ 1 , 0 ] } - for var_17 in range ( var_8 ) : - var_18 , var_19 = var_2 - var_20 = 0 - for var_21 in range ( var_17 , var_8 ) : - var_22 , var_23 = var_15 [ var_4 [ var_21 ] ] - if 0 <= var_18 + var_22 < var_0 and 0 <= var_19 + var_23 < var_0 : - var_18 , var_19 , var_20 = var_18 + var_22 , var_19 + var_23 , var_20 + 1 - else : - break - var_6.append ( var_20 ) - return var_6 -",DL0U1R,6 -1311,1122.Relative Sort Array_1.py,"def relativeSortArray( arr1: List[int], arr2: List[int]) -> List[int]: - mp = [0] * 1001 - for x in arr1: - mp[x] += 1 - i = 0 - for x in arr2: - while mp[x] > 0: - arr1[i] = x - mp[x] -= 1 - i += 1 - for x, cnt in enumerate(mp): - for _ in range(cnt): - arr1[i] = x - i += 1 - return arr1","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> List [ int ] : - var_6 = [ 0 ] * 1001 - for var_7 in var_0 : - var_6 [ var_7 ] += 1 - var_9 = 0 - for var_7 in var_3 : - while var_6 [ var_7 ] > 0 : - var_0 [ var_9 ] = var_7 - var_6 [ var_7 ] -= 1 - var_9 += 1 - for var_7 , var_11 in enumerate ( var_6 ) : - for var_13 in range ( var_11 ) : - var_0 [ var_9 ] = var_7 - var_9 += 1 - return var_0 -",101001,3 -1312,0219.Contains Duplicate II_1.py,"def containsNearbyDuplicate( nums: List[int], k: int) -> bool: - mp = {} - for i, v in enumerate(nums): - if v in mp and i - mp[v] <= k: - return True - mp[v] = i - return False","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> bool : - var_5 = { } - for var_7 , var_8 in enumerate ( var_0 ) : - if var_8 in var_5 and var_7 - var_5 [ var_8 ] <= var_3 : - return True - var_5 [ var_8 ] = var_7 - return False -",,0 -1313,0796.Rotate String_1.py,"def rotateString( s: str, goal: str) -> bool: - return len(s) == len(goal) and goal in s + s","def sample_funcname ( var_0 : str , var_2 : str ) -> bool : - return len ( var_0 ) == len ( var_2 ) and var_2 in var_0 + var_0 -",,0 -1314,2397.Maximum Rows Covered by Columns_1.py,"def maximumRows( mat: List[List[int]], cols: int) -> int: - arr = [] - for i, row in enumerate(mat): - x = 0 - for j, v in enumerate(row): - x |= v << j - arr.append(x) - ans, n = 0, len(mat[0]) - for mask in range(1, 1 << n | 1): - if mask.bit_count() > cols: - continue - t = sum((v & mask) == v for v in arr) - ans = max(ans, t) - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : int ) -> int : - var_4 = [ ] - for var_6 , var_7 in enumerate ( var_0 ) : - var_9 = 0 - for var_10 , var_11 in enumerate ( var_7 ) : - var_9 |= var_11 << var_10 - var_4.append ( var_9 ) - var_13 , var_15 = 0 , len ( var_0 [ 0 ] ) - for var_18 in range ( 1 , 1 << var_15 | 1 ) : - if var_18.bit_count ( ) > var_3 : - continue - var_21 = sum ( ( var_11 & var_18 ) == var_11 for var_11 in var_4 ) - var_13 = max ( var_13 , var_21 ) - return var_13 -",10,2 -1315,1582.Special Positions in a Binary Matrix_1.py,"def numSpecial( mat: List[List[int]]) -> int: - m, n = len(mat), len(mat[0]) - r = [0] * m - c = [0] * n - for i, row in enumerate(mat): - for j, v in enumerate(row): - r[i] += v - c[j] += v - ans = 0 - for i in range(m): - for j in range(n): - if mat[i][j] == 1 and r[i] == 1 and c[j] == 1: - ans += 1 - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_7 = [ 0 ] * var_4 - var_8 = [ 0 ] * var_6 - for var_10 , var_11 in enumerate ( var_0 ) : - for var_12 , var_13 in enumerate ( var_11 ) : - var_7 [ var_10 ] += var_13 - var_8 [ var_12 ] += var_13 - var_14 = 0 - for var_10 in range ( var_4 ) : - for var_12 in range ( var_6 ) : - if var_0 [ var_10 ] [ var_12 ] == 1 and var_7 [ var_10 ] == 1 and var_8 [ var_12 ] == 1 : - var_14 += 1 - return var_14 -",10,2 -1316,2062.Count Vowel Substrings of a String_1.py,"def countVowelSubstrings( word: str) -> int: - n = len(word) - s = set('aeiou') - return sum(set(word[i:j]) == s for i in range(n) for j in range(i + 1, n + 1))","def sample_funcname ( var_0 : str ) -> int : - var_4 = len ( var_0 ) - var_7 = set ( 'aeiou' ) - return sum ( set ( var_0 [ var_9 : var_10 ] ) == var_7 for var_9 in range ( var_4 ) for var_10 in range ( var_9 + 1 , var_4 + 1 ) ) -",aeiou1,2 -1317,0453.Minimum Moves to Equal Array Elements_1.py,"def minMoves( nums: List[int]) -> int: - return sum(nums) - min(nums) * len(nums)","def sample_funcname ( var_0 : List [ int ] ) -> int : - return sum ( var_0 ) - min ( var_0 ) * len ( var_0 ) -",,0 -1318,0018.4Sum_1.py,"def fourSum( nums: List[int], target: int) -> List[List[int]]: - n, res = len(nums), [] - if n < 4: - return [] - nums.sort() - for i in range(n - 3): - if i > 0 and nums[i] == nums[i - 1]: - continue - for j in range(i + 1, n - 2): - if j > i + 1 and nums[j] == nums[j - 1]: - continue - k, l = j + 1, n - 1 - while k < l: - if nums[i] + nums[j] + nums[k] + nums[l] == target: - res.append([nums[i], nums[j], nums[k], nums[l]]) - k += 1 - l -= 1 - while k < n and nums[k] == nums[k - 1]: - k += 1 - while l > j and nums[l] == nums[l + 1]: - l -= 1 - elif nums[i] + nums[j] + nums[k] + nums[l] < target: - k += 1 - else: - l -= 1 - return res","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ List [ int ] ] : - var_5 , var_6 = len ( var_0 ) , [ ] - if var_5 < 4 : - return [ ] - var_0.sort ( ) - for var_11 in range ( var_5 - 3 ) : - if var_11 > 0 and var_0 [ var_11 ] == var_0 [ var_11 - 1 ] : - continue - for var_15 in range ( var_11 + 1 , var_5 - 2 ) : - if var_15 > var_11 + 1 and var_0 [ var_15 ] == var_0 [ var_15 - 1 ] : - continue - var_16 , var_17 = var_15 + 1 , var_5 - 1 - while var_16 < var_17 : - if var_0 [ var_11 ] + var_0 [ var_15 ] + var_0 [ var_16 ] + var_0 [ var_17 ] == var_3 : - var_6.append ( [ var_0 [ var_11 ] , var_0 [ var_15 ] , var_0 [ var_16 ] , var_0 [ var_17 ] ] ) - var_16 += 1 - var_17 -= 1 - while var_16 < var_5 and var_0 [ var_16 ] == var_0 [ var_16 - 1 ] : - var_16 += 1 - while var_17 > var_15 and var_0 [ var_17 ] == var_0 [ var_17 + 1 ] : - var_17 -= 1 - elif var_0 [ var_11 ] + var_0 [ var_15 ] + var_0 [ var_16 ] + var_0 [ var_17 ] < var_3 : - var_16 += 1 - else : - var_17 -= 1 - return var_6 -",02134,5 -1319,1630.Arithmetic Subarrays_1.py,"def check(nums, l, r): - if r - l < 2: - return True - s = set(nums[l : r + 1]) - mx = max(nums[l : r + 1]) - mi = min(nums[l : r + 1]) - if (mx - mi) % (r - l) != 0: - return False - delta = (mx - mi) / (r - l) - for i in range(1, r - l + 1): - if (mi + delta * i) not in s: - return False - return True","def sample_funcname ( var_0 , var_1 , var_2 ) : - if var_2 - var_1 < 2 : - return True - var_7 = set ( var_0 [ var_1 : var_2 + 1 ] ) - var_9 = max ( var_0 [ var_1 : var_2 + 1 ] ) - var_11 = min ( var_0 [ var_1 : var_2 + 1 ] ) - if ( var_9 - var_11 ) % ( var_2 - var_1 ) != 0 : - return False - var_14 = ( var_9 - var_11 ) / ( var_2 - var_1 ) - for var_16 in range ( 1 , var_2 - var_1 + 1 ) : - if ( var_11 + var_14 * var_16 ) not in var_7 : - return False - return True -",102,3 -1320,2335.Minimum Amount of Time to Fill Cups_1.py,"def fillCups( amount: List[int]) -> int: - ans = 0 - while sum(amount): - amount.sort() - ans += 1 - amount[2] -= 1 - amount[1] = max(0, amount[1] - 1) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 0 - while sum ( var_0 ) : - var_0.sort ( ) - var_4 += 1 - var_0 [ 2 ] -= 1 - var_0 [ 1 ] = max ( 0 , var_0 [ 1 ] - 1 ) - return var_4 -",102,3 -1321,0962.Maximum Width Ramp_1.py,"def maxWidthRamp( nums: List[int]) -> int: - stk = [] - for i, v in enumerate(nums): - if not stk or nums[stk[-1]] > v: - stk.append(i) - ans = 0 - for i in range(len(nums) - 1, -1, -1): - while stk and nums[stk[-1]] <= nums[i]: - ans = max(ans, i - stk.pop()) - if not stk: - break - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_3 = [ ] - for var_5 , var_6 in enumerate ( var_0 ) : - if not var_3 or var_0 [ var_3 [ - 1 ] ] > var_6 : - var_3.append ( var_5 ) - var_10 = 0 - for var_5 in range ( len ( var_0 ) - 1 , - 1 , - 1 ) : - while var_3 and var_0 [ var_3 [ - 1 ] ] <= var_0 [ var_5 ] : - var_10 = max ( var_10 , var_5 - var_3.pop ( ) ) - if not var_3 : - break - return var_10 -",10,2 -1322,0028.Find the Index of the First Occurrence in a String_1.py,"def strStr( haystack, needle): - for i in range(len(haystack) - len(needle) + 1): - p = i - q = 0 - while p < len(haystack) and q < len(needle) and haystack[p] == needle[q]: - p += 1 - q += 1 - - if q == len(needle): - return i - - return -1","def sample_funcname ( var_0 , var_1 ) : - for var_5 in range ( len ( var_0 ) - len ( var_1 ) + 1 ) : - var_6 = var_5 - var_8 = 0 - while var_6 < len ( var_0 ) and var_8 < len ( var_1 ) and var_0 [ var_6 ] == var_1 [ var_8 ] : - var_6 += 1 - var_8 += 1 - if var_8 == len ( var_1 ) : - return var_5 - return - 1 -",10,2 -1323,0888.Fair Candy Swap_1.py,"def fairCandySwap( aliceSizes: List[int], bobSizes: List[int]) -> List[int]: - diff = (sum(aliceSizes) - sum(bobSizes)) >> 1 - s = set(bobSizes) - for a in aliceSizes: - target = a - diff - if target in s: - return [a, target]","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> List [ int ] : - var_6 = ( sum ( var_0 ) - sum ( var_3 ) ) >> 1 - var_8 = set ( var_3 ) - for var_9 in var_0 : - var_10 = var_9 - var_6 - if var_10 in var_8 : - return [ var_9 , var_10 ] -",1,1 -1324,0287.Find the Duplicate Number_1.py,"def findDuplicate( nums: List[int]) -> int: - left, right = 1, len(nums) - 1 - while left < right: - mid = (left + right) >> 1 - cnt = sum(v <= mid for v in nums) - if cnt > mid: - right = mid - else: - left = mid + 1 - return left","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_6 = 1 , len ( var_0 ) - 1 - while var_4 < var_6 : - var_7 = ( var_4 + var_6 ) >> 1 - var_10 = sum ( var_8 <= var_7 for var_8 in var_0 ) - if var_10 > var_7 : - var_6 = var_7 - else : - var_4 = var_7 + 1 - return var_4 -",1,1 -1325,2012.Sum of Beauty in the Array_1.py,"def sumOfBeauties( nums: List[int]) -> int: - n = len(nums) - lmx = [0] * n - for i in range(1, n): - lmx[i] = max(lmx[i - 1], nums[i - 1]) - rmi = [100001] * n - for i in range(n - 2, -1, -1): - rmi[i] = min(rmi[i + 1], nums[i + 1]) - ans = 0 - for i in range(1, n - 1): - if lmx[i] < nums[i] < rmi[i]: - ans += 2 - elif nums[i - 1] < nums[i] < nums[i + 1]: - ans += 1 - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_6 = [ 0 ] * var_4 - for var_9 in range ( 1 , var_4 ) : - var_6 [ var_9 ] = max ( var_6 [ var_9 - 1 ] , var_0 [ var_9 - 1 ] ) - var_12 = [ 100001 ] * var_4 - for var_9 in range ( var_4 - 2 , - 1 , - 1 ) : - var_12 [ var_9 ] = min ( var_12 [ var_9 + 1 ] , var_0 [ var_9 + 1 ] ) - var_15 = 0 - for var_9 in range ( 1 , var_4 - 1 ) : - if var_6 [ var_9 ] < var_0 [ var_9 ] < var_12 [ var_9 ] : - var_15 += 2 - elif var_0 [ var_9 - 1 ] < var_0 [ var_9 ] < var_0 [ var_9 + 1 ] : - var_15 += 1 - return var_15 -",101000012,4 -1326,0873.Length of Longest Fibonacci Subsequence_1.py,"def lenLongestFibSubseq( arr: List[int]) -> int: - mp = {v: i for i, v in enumerate(arr)} - n = len(arr) - dp = [[0] * n for _ in range(n)] - for i in range(n): - for j in range(i): - dp[j][i] = 2 - ans = 0 - for i in range(n): - for j in range(i): - d = arr[i] - arr[j] - if d in mp and (k := mp[d]) < j: - dp[j][i] = max(dp[j][i], dp[k][j] + 1) - ans = max(ans, dp[j][i]) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_6 = { var_3 : var_4 for var_4 , var_3 in enumerate ( var_0 ) } - var_8 = len ( var_0 ) - var_12 = [ [ 0 ] * var_8 for var_10 in range ( var_8 ) ] - for var_4 in range ( var_8 ) : - for var_13 in range ( var_4 ) : - var_12 [ var_13 ] [ var_4 ] = 2 - var_15 = 0 - for var_4 in range ( var_8 ) : - for var_13 in range ( var_4 ) : - var_16 = var_0 [ var_4 ] - var_0 [ var_13 ] - if var_16 in var_6 and ( var_17 := var_6 [ var_16 ] ) < var_13 : - var_12 [ var_13 ] [ var_4 ] = max ( var_12 [ var_13 ] [ var_4 ] , var_12 [ var_17 ] [ var_13 ] + 1 ) - var_15 = max ( var_15 , var_12 [ var_13 ] [ var_4 ] ) - return var_15 -",102,3 -1327,1760.Minimum Limit of Balls in a Bag_1.py,"def minimumSize( nums: List[int], maxOperations: int) -> int: - left, right = 1, max(nums) - while left < right: - mid = (left + right) >> 1 - ops = sum((num - 1) // mid for num in nums) - if ops <= maxOperations: - right = mid - else: - left = mid + 1 - return left","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 , var_7 = 1 , max ( var_0 ) - while var_5 < var_7 : - var_8 = ( var_5 + var_7 ) >> 1 - var_11 = sum ( ( var_10 - 1 ) // var_8 for var_10 in var_0 ) - if var_11 <= var_3 : - var_7 = var_8 - else : - var_5 = var_8 + 1 - return var_5 -",1,1 -1328,2327.Number of People Aware of a Secret_1.py,"def peopleAwareOfSecret( n: int, delay: int, forget: int) -> int: - m = (n << 1) + 10 - d = [0] * m - cnt = [0] * m - cnt[1] = 1 - for i in range(1, n + 1): - if cnt[i]: - d[i] += cnt[i] - d[i + forget] -= cnt[i] - nxt = i + delay - while nxt < i + forget: - cnt[nxt] += cnt[i] - nxt += 1 - mod = 10**9 + 7 - return sum(d[: n + 1]) % mod","def sample_funcname ( var_0 : int , var_2 : int , var_3 : int ) -> int : - var_6 = ( var_0 << 1 ) + 10 - var_8 = [ 0 ] * var_6 - var_9 = [ 0 ] * var_6 - var_9 [ 1 ] = 1 - for var_11 in range ( 1 , var_0 + 1 ) : - if var_9 [ var_11 ] : - var_8 [ var_11 ] += var_9 [ var_11 ] - var_8 [ var_11 + var_3 ] -= var_9 [ var_11 ] - var_12 = var_11 + var_2 - while var_12 < var_11 + var_3 : - var_9 [ var_12 ] += var_9 [ var_11 ] - var_12 += 1 - var_15 = 10 ** 9 + 7 - return sum ( var_8 [ : var_0 + 1 ] ) % var_15 -",100179,5 -1329,1812.Determine Color of a Chessboard Square_1.py,"def squareIsWhite( coordinates: str) -> bool: - x = ord(coordinates[0]) - ord('a') + 1 - y = int(coordinates[1]) - return ((x + y) & 1) == 1","def sample_funcname ( var_0 : str ) -> bool : - var_7 = ord ( var_0 [ 0 ] ) - ord ( 'a' ) + 1 - var_9 = int ( var_0 [ 1 ] ) - return ( ( var_7 + var_9 ) & 1 ) == 1 -",a01,3 -1330,2311.Longest Binary Subsequence Less Than or Equal to K_1.py,"def longestSubsequence( s: str, k: int) -> int: - n = len(s) - ans = s.count('0') - v = 0 - for i in range(n - 1, -1, -1): - if s[i] == '1': - if v + (1 << (n - i - 1)) > k: - break - ans += 1 - v += 1 << (n - i - 1) - return ans","def sample_funcname ( var_0 : str , var_2 : int ) -> int : - var_5 = len ( var_0 ) - var_8 = var_0.count ( '0' ) - var_10 = 0 - for var_13 in range ( var_5 - 1 , - 1 , - 1 ) : - if var_0 [ var_13 ] == '1' : - if var_10 + ( 1 << ( var_5 - var_13 - 1 ) ) > var_2 : - break - var_8 += 1 - var_10 += 1 << ( var_5 - var_13 - 1 ) - return var_8 -",1001,4 -1331,1213.Intersection of Three Sorted Arrays_1.py,"def find(arr, val): - left, right = 0, len(arr) - 1 - while left < right: - mid = (left + right) >> 1 - if arr[mid] >= val: - right = mid - else: - left = mid + 1 - return arr[left] == val","def sample_funcname ( var_0 , var_1 ) : - var_3 , var_6 = 0 , len ( var_0 ) - 1 - while var_3 < var_6 : - var_7 = ( var_3 + var_6 ) >> 1 - if var_0 [ var_7 ] >= var_1 : - var_6 = var_7 - else : - var_3 = var_7 + 1 - return var_0 [ var_3 ] == var_1 -",10,2 -1332,0549.Binary Tree Longest Consecutive Sequence II_1.py,"def dfs(root): - if root is None: - return [0, 0] - nonlocal ans - incr = decr = 1 - i1, d1 = dfs(root.left) - i2, d2 = dfs(root.right) - if root.left: - if root.left.val + 1 == root.val: - incr = i1 + 1 - if root.left.val - 1 == root.val: - decr = d1 + 1 - if root.right: - if root.right.val + 1 == root.val: - incr = max(incr, i2 + 1) - if root.right.val - 1 == root.val: - decr = max(decr, d2 + 1) - ans = max(ans, incr + decr - 1) - return [incr, decr]","def sample_funcname ( var_1 ) : - if var_1 is None : - return [ 0 , 0 ] - nonlocal var_4 - var_7 = var_5 = 1 - var_8 , var_10 = var_0 ( var_1.left ) - var_11 , var_13 = var_0 ( var_1.right ) - if var_1.left : - if var_1.left.val + 1 == var_1.val : - var_7 = var_8 + 1 - if var_1.left.val - 1 == var_1.val : - var_5 = var_10 + 1 - if var_1.right : - if var_1.right.val + 1 == var_1.val : - var_7 = max ( var_7 , var_11 + 1 ) - if var_1.right.val - 1 == var_1.val : - var_5 = max ( var_5 , var_13 + 1 ) - var_4 = max ( var_4 , var_7 + var_5 - 1 ) - return [ var_7 , var_5 ] -",10None,3 -1333,1108.Defanging an IP Address_1.py,"def defangIPaddr( address: str) -> str: - return address.replace('.', '[.]')","def sample_funcname ( var_0 : str ) -> str : - return var_0.replace ( '.' , '[.]' ) -",[.].,2 -1334,2337.Move Pieces to Obtain a String_1.py,"def canChange( start: str, target: str) -> bool: - a = [(v, i) for i, v in enumerate(start) if v != '_'] - b = [(v, i) for i, v in enumerate(target) if v != '_'] - if len(a) != len(b): - return False - for (c, i), (d, j) in zip(a, b): - if c != d: - return False - if c == 'L' and i < j: - return False - if c == 'R' and i > j: - return False - return True","def sample_funcname ( var_0 : str , var_2 : str ) -> bool : - var_8 = [ ( var_4 , var_5 ) for var_5 , var_4 in enumerate ( var_0 ) if var_4 != '_' ] - var_9 = [ ( var_4 , var_5 ) for var_5 , var_4 in enumerate ( var_2 ) if var_4 != '_' ] - if len ( var_8 ) != len ( var_9 ) : - return False - for ( var_13 , var_5 ) , ( var_14 , var_15 ) in zip ( var_8 , var_9 ) : - if var_13 != var_14 : - return False - if var_13 == 'L' and var_5 < var_15 : - return False - if var_13 == 'R' and var_5 > var_15 : - return False - return True -",_LR,3 -1335,0676.Implement Magic Dictionary_1.py,"def gen( word): - return [word[:i] + '*' + word[i + 1 :] for i in range(len(word))]","def sample_funcname ( var_0 ) : - return [ var_0 [ : var_1 ] + '*' + var_0 [ var_1 + 1 : ] for var_1 in range ( len ( var_0 ) ) ] -",1*,2 -1336,0063.Unique Paths II_1.py,"def uniquePathsWithObstacles( obstacleGrid: List[List[int]]) -> int: - m, n = len(obstacleGrid), len(obstacleGrid[0]) - dp = [[0] * n for _ in range(m)] - for i in range(m): - if obstacleGrid[i][0] == 1: - break - dp[i][0] = 1 - for j in range(n): - if obstacleGrid[0][j] == 1: - break - dp[0][j] = 1 - for i in range(1, m): - for j in range(1, n): - if obstacleGrid[i][j] == 0: - dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - return dp[-1][-1]","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_9 = [ [ 0 ] * var_6 for var_7 in range ( var_4 ) ] - for var_10 in range ( var_4 ) : - if var_0 [ var_10 ] [ 0 ] == 1 : - break - var_9 [ var_10 ] [ 0 ] = 1 - for var_12 in range ( var_6 ) : - if var_0 [ 0 ] [ var_12 ] == 1 : - break - var_9 [ 0 ] [ var_12 ] = 1 - for var_10 in range ( 1 , var_4 ) : - for var_12 in range ( 1 , var_6 ) : - if var_0 [ var_10 ] [ var_12 ] == 0 : - var_9 [ var_10 ] [ var_12 ] = var_9 [ var_10 - 1 ] [ var_12 ] + var_9 [ var_10 ] [ var_12 - 1 ] - return var_9 [ - 1 ] [ - 1 ] -",10,2 -1337,0250.Count Univalue Subtrees_1.py,"def dfs(root): - if root is None: - return True - left, right = dfs(root.left), dfs(root.right) - t = True - if root.left and root.left.val != root.val: - t = False - if root.right and root.right.val != root.val: - t = False - nonlocal ans - if left and t and right: - ans += 1 - return left and t and right","def sample_funcname ( var_1 ) : - if var_1 is None : - return True - left , right = var_0 ( var_1.left ) , var_0 ( var_1.right ) - var_6 = True - if var_1.left and var_1.left.val != var_1.val : - var_6 = False - if var_1.right and var_1.right.val != var_1.val : - var_6 = False - nonlocal var_9 - if left and var_6 and right : - var_9 += 1 - return left and var_6 and right -",1None,2 -1338,2160.Minimum Sum of Four Digit Number After Splitting Digits_1.py,"def minimumSum( num: int) -> int: - nums = [] - while num: - nums.append(num % 10) - num //= 10 - nums.sort() - return 10 * (nums[0] + nums[1]) + nums[2] + nums[3]","def sample_funcname ( var_0 : int ) -> int : - var_2 = [ ] - while var_0 : - var_2.append ( var_0 % 10 ) - var_0 //= 10 - var_2.sort ( ) - return 10 * ( var_2 [ 0 ] + var_2 [ 1 ] ) + var_2 [ 2 ] + var_2 [ 3 ] -",100213,5 -1339,1402.Reducing Dishes_1.py,"def maxSatisfaction( satisfaction: List[int]) -> int: - satisfaction.sort(reverse=True) - ans = presum = 0 - for v in satisfaction: - presum += v - if presum > 0: - ans += presum - else: - break - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( var_4 = True ) - var_8 = var_6 = 0 - for var_9 in var_0 : - var_6 += var_9 - if var_6 > 0 : - var_8 += var_6 - else : - break - return var_8 -",0,1 -1340,0217.Contains Duplicate_1.py,"def containsDuplicate( nums: List[int]) -> bool: - return len(set(nums)) < len(nums)","def sample_funcname ( var_0 : List [ int ] ) -> bool : - return len ( set ( var_0 ) ) < len ( var_0 ) -",,0 -1341,0917.Reverse Only Letters_1.py,"def reverseOnlyLetters( s: str) -> str: - s = list(s) - i, j = 0, len(s) - 1 - while i < j: - while i < j and not s[i].isalpha(): - i += 1 - while i < j and not s[j].isalpha(): - j -= 1 - if i < j: - s[i], s[j] = s[j], s[i] - i, j = i + 1, j - 1 - return ''.join(s)","def sample_funcname ( var_0 : str ) -> str : - var_0 = list ( var_0 ) - var_4 , var_7 = 0 , len ( var_0 ) - 1 - while var_4 < var_7 : - while var_4 < var_7 and not var_0 [ var_4 ].isalpha ( ) : - var_4 += 1 - while var_4 < var_7 and not var_0 [ var_7 ].isalpha ( ) : - var_7 -= 1 - if var_4 < var_7 : - var_0 [ var_4 ] , var_0 [ var_7 ] = var_0 [ var_7 ] , var_0 [ var_4 ] - var_4 , var_7 = var_4 + 1 , var_7 - 1 - return ''.join ( var_0 ) -",10,3 -1342,1887.Reduction Operations to Make the Array Elements Equal_1.py,"def reductionOperations( nums: List[int]) -> int: - nums.sort() - ans = cnt = 0 - for i, v in enumerate(nums[1:]): - if v != nums[i]: - cnt += 1 - ans += cnt - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( ) - var_6 = var_4 = 0 - for var_8 , var_10 in enumerate ( var_0 [ 1 : ] ) : - if var_10 != var_0 [ var_8 ] : - var_4 += 1 - var_6 += var_4 - return var_6 -",10,2 -1344,1470.Shuffle the Array_1.py,"def shuffle( nums: List[int], n: int) -> List[int]: - ans = [] - for i in range(n): - ans.append(nums[i]) - ans.append(nums[i + n]) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_4 = [ ] - for var_6 in range ( var_3 ) : - var_4.append ( var_0 [ var_6 ] ) - var_4.append ( var_0 [ var_6 + var_3 ] ) - return var_4 -",,0 -1345,1947.Maximum Compatibility Score Sum_1.py,"def score(s, m): - res = 0 - for i in range(len(s)): - res += 1 if s[i] == m[i] else 0 - return res","def sample_funcname ( var_0 , var_1 ) : - var_3 = 0 - for var_6 in range ( len ( var_0 ) ) : - var_3 += 1 if var_0 [ var_6 ] == var_1 [ var_6 ] else 0 - return var_3 -",10,2 -1346,1048.Longest String Chain_1.py,"def check(w1, w2): - if len(w2) - len(w1) != 1: - return False - i = j = cnt = 0 - while i < len(w1) and j < len(w2): - if w1[i] != w2[j]: - cnt += 1 - else: - i += 1 - j += 1 - return cnt < 2 and i == len(w1)","def sample_funcname ( var_0 , var_1 ) : - if len ( var_1 ) - len ( var_0 ) != 1 : - return False - var_8 = var_5 = var_6 = 0 - while var_8 < len ( var_0 ) and var_5 < len ( var_1 ) : - if var_0 [ var_8 ] != var_1 [ var_5 ] : - var_6 += 1 - else : - var_8 += 1 - var_5 += 1 - return var_6 < 2 and var_8 == len ( var_0 ) -",102,3 -1347,2273.Find Resultant Array After Removing Anagrams_1.py,"def removeAnagrams( words: List[str]) -> List[str]: - return [ - w - for i, w in enumerate(words) - if i == 0 or sorted(w) != sorted(words[i - 1]) - ]","def sample_funcname ( var_0 : List [ str ] ) -> List [ str ] : - return [ var_3 for var_5 , var_3 in enumerate ( var_0 ) if var_5 == 0 or sorted ( var_3 ) != sorted ( var_0 [ var_5 - 1 ] ) ] -",10,2 -1348,0860.Lemonade Change_1.py,"def lemonadeChange( bills: List[int]) -> bool: - five = ten = 0 - for v in bills: - if v == 5: - five += 1 - elif v == 10: - ten += 1 - five -= 1 - else: - if ten: - ten -= 1 - five -= 1 - else: - five -= 3 - if five < 0: - return False - return True","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_6 = var_4 = 0 - for var_7 in var_0 : - if var_7 == 5 : - var_6 += 1 - elif var_7 == 10 : - var_4 += 1 - var_6 -= 1 - else : - if var_4 : - var_4 -= 1 - var_6 -= 1 - else : - var_6 -= 3 - if var_6 < 0 : - return False - return True -",105013,5 -1349,0274.H-Index_1.py,"def hIndex( citations: List[int]) -> int: - n = len(citations) - cnt = [0] * (n + 1) - for c in citations: - if c <= n: - cnt[c] += 1 - else: - cnt[n] += 1 - sum = 0 - for i in range(n, -1, -1): - sum += cnt[i] - if sum >= i: - return i - return 0","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_7 = [ 0 ] * ( var_4 + 1 ) - for var_8 in var_0 : - if var_8 <= var_4 : - var_7 [ var_8 ] += 1 - else : - var_7 [ var_4 ] += 1 - var_9 = 0 - for var_11 in range ( var_4 , - 1 , - 1 ) : - var_9 += var_7 [ var_11 ] - if var_9 >= var_11 : - return var_11 - return 0 -",10,2 -1350,0989.Add to Array-Form of Integer_1.py,"def addToArrayForm( num: List[int], k: int) -> List[int]: - i, carry = len(num) - 1, 0 - ans = [] - while i >= 0 or k or carry: - carry += (0 if i < 0 else num[i]) + (k % 10) - carry, v = divmod(carry, 10) - ans.append(v) - k //= 10 - i -= 1 - return ans[::-1]","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_6 , var_8 = len ( var_0 ) - 1 , 0 - var_9 = [ ] - while var_6 >= 0 or var_3 or var_8 : - var_8 += ( 0 if var_6 < 0 else var_0 [ var_6 ] ) + ( var_3 % 10 ) - var_8 , var_12 = divmod ( var_8 , 10 ) - var_9.append ( var_12 ) - var_3 //= 10 - var_6 -= 1 - return var_9 [ : : - 1 ] -",1010,3 -1351,0064.Minimum Path Sum_1.py,"def minPathSum( grid: List[List[int]]) -> int: - m, n = len(grid), len(grid[0]) - dp = [[grid[0][0]] * n for _ in range(m)] - for i in range(1, m): - dp[i][0] = dp[i - 1][0] + grid[i][0] - for j in range(1, n): - dp[0][j] = dp[0][j - 1] + grid[0][j] - for i in range(1, m): - for j in range(1, n): - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + grid[i][j] - return dp[-1][-1]","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_9 = [ [ var_0 [ 0 ] [ 0 ] ] * var_6 for var_7 in range ( var_4 ) ] - for var_11 in range ( 1 , var_4 ) : - var_9 [ var_11 ] [ 0 ] = var_9 [ var_11 - 1 ] [ 0 ] + var_0 [ var_11 ] [ 0 ] - for var_12 in range ( 1 , var_6 ) : - var_9 [ 0 ] [ var_12 ] = var_9 [ 0 ] [ var_12 - 1 ] + var_0 [ 0 ] [ var_12 ] - for var_11 in range ( 1 , var_4 ) : - for var_12 in range ( 1 , var_6 ) : - var_9 [ var_11 ] [ var_12 ] = min ( var_9 [ var_11 - 1 ] [ var_12 ] , var_9 [ var_11 ] [ var_12 - 1 ] ) + var_0 [ var_11 ] [ var_12 ] - return var_9 [ - 1 ] [ - 1 ] -",10,2 -1353,1646.Get Maximum in Generated Array_1.py,"def getMaximumGenerated( n: int) -> int: - if n == 0: - return 0 - nums = [0] * (n + 1) - nums[1] = 1 - for i in range(2, n + 1): - nums[i] = nums[i >> 1] if i % 2 == 0 else nums[i >> 1] + nums[(i >> 1) + 1] - return max(nums)","def sample_funcname ( var_0 : int ) -> int : - if var_0 == 0 : - return 0 - var_4 = [ 0 ] * ( var_0 + 1 ) - var_4 [ 1 ] = 1 - for var_7 in range ( 2 , var_0 + 1 ) : - var_4 [ var_7 ] = var_4 [ var_7 >> 1 ] if var_7 % 2 == 0 else var_4 [ var_7 >> 1 ] + var_4 [ ( var_7 >> 1 ) + 1 ] - return max ( var_4 ) -",102,3 -1354,2038.Remove Colored Pieces if Both Neighbors are the Same Color_1.py,"def winnerOfGame( colors: str) -> bool: - a = b = 0 - cnt1 = cnt2 = 0 - for c in colors: - if c == 'A': - a += 1 - if a > 2: - cnt1 += 1 - b = 0 - else: - b += 1 - if b > 2: - cnt2 += 1 - a = 0 - return cnt1 > cnt2","def sample_funcname ( var_0 : str ) -> bool : - var_5 = var_3 = 0 - var_7 = var_6 = 0 - for var_8 in var_0 : - if var_8 == 'A' : - var_5 += 1 - if var_5 > 2 : - var_7 += 1 - var_3 = 0 - else : - var_3 += 1 - if var_3 > 2 : - var_6 += 1 - var_5 = 0 - return var_7 > var_6 -",A012,4 -1355,1266.Minimum Time Visiting All Points_1.py,"def minTimeToVisitAllPoints( points: List[List[int]]) -> int: - res = 0 - x0, y0 = points[0][0], points[0][1] - for x1, y1 in points[1:]: - res += max(abs(x0 - x1), abs(y0 - y1)) - x0, y0 = x1, y1 - return res","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 = 0 - var_5 , var_7 = var_0 [ 0 ] [ 0 ] , var_0 [ 0 ] [ 1 ] - for var_8 , var_9 in var_0 [ 1 : ] : - var_4 += max ( abs ( var_5 - var_8 ) , abs ( var_7 - var_9 ) ) - var_5 , var_7 = var_8 , var_9 - return var_4 -",10,2 -1356,0112.Path Sum_1.py,"def dfs(root, sum): - if root is None: - return False - if root.val == sum and root.left is None and root.right is None: - return True - return dfs(root.left, sum - root.val) or dfs(root.right, sum - root.val)","def sample_funcname ( var_1 , var_2 ) : - if var_1 is None : - return False - if var_1.val == var_2 and var_1.left is None and var_1.right is None : - return True - return var_0 ( var_1.left , var_2 - var_1.val ) or var_0 ( var_1.right , var_2 - var_1.val ) -",None,1 -1357,0712.Minimum ASCII Delete Sum for Two Strings_1.py,"def minimumDeleteSum( s1: str, s2: str) -> int: - m, n = len(s1), len(s2) - dp = [[0] * (n + 1) for _ in range(m + 1)] - for i in range(1, m + 1): - dp[i][0] = dp[i - 1][0] + ord(s1[i - 1]) - for j in range(1, n + 1): - dp[0][j] = dp[0][j - 1] + ord(s2[j - 1]) - for i in range(1, m + 1): - for j in range(1, n + 1): - if s1[i - 1] == s2[j - 1]: - dp[i][j] = dp[i - 1][j - 1] - else: - dp[i][j] = min( - dp[i - 1][j] + ord(s1[i - 1]), dp[i][j - 1] + ord(s2[j - 1]) - ) - return dp[-1][-1]","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - var_5 , var_6 = len ( var_0 ) , len ( var_2 ) - var_11 = [ [ 0 ] * ( var_6 + 1 ) for var_9 in range ( var_5 + 1 ) ] - for var_12 in range ( 1 , var_5 + 1 ) : - var_11 [ var_12 ] [ 0 ] = var_11 [ var_12 - 1 ] [ 0 ] + ord ( var_0 [ var_12 - 1 ] ) - for var_14 in range ( 1 , var_6 + 1 ) : - var_11 [ 0 ] [ var_14 ] = var_11 [ 0 ] [ var_14 - 1 ] + ord ( var_2 [ var_14 - 1 ] ) - for var_12 in range ( 1 , var_5 + 1 ) : - for var_14 in range ( 1 , var_6 + 1 ) : - if var_0 [ var_12 - 1 ] == var_2 [ var_14 - 1 ] : - var_11 [ var_12 ] [ var_14 ] = var_11 [ var_12 - 1 ] [ var_14 - 1 ] - else : - var_11 [ var_12 ] [ var_14 ] = min ( var_11 [ var_12 - 1 ] [ var_14 ] + ord ( var_0 [ var_12 - 1 ] ) , var_11 [ var_12 ] [ var_14 - 1 ] + ord ( var_2 [ var_14 - 1 ] ) ) - return var_11 [ - 1 ] [ - 1 ] -",10,2 -1358,0263.Ugly Number_1.py,"def isUgly( n: int) -> bool: - if n < 1: - return False - for x in [2, 3, 5]: - while n % x == 0: - n //= x - return n == 1","def sample_funcname ( var_0 : int ) -> bool : - if var_0 < 1 : - return False - for var_8 in [ 2 , 3 , 5 ] : - while var_0 % var_8 == 0 : - var_0 //= var_8 - return var_0 == 1 -",50213,5 -1359,1409.Queries on a Permutation With Key_1.py,"def processQueries( queries: List[int], m: int) -> List[int]: - p = list(range(1, m + 1)) - ans = [] - for v in queries: - j = p.index(v) - ans.append(j) - p.pop(j) - p.insert(0, v) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_7 = list ( range ( 1 , var_3 + 1 ) ) - var_8 = [ ] - for var_9 in var_0 : - var_11 = var_7.index ( var_9 ) - var_8.append ( var_11 ) - var_7.pop ( var_11 ) - var_7.insert ( 0 , var_9 ) - return var_8 -",10,2 -1360,1871.Jump Game VII_1.py,"def canReach( s: str, minJump: int, maxJump: int) -> bool: - n = len(s) - dp = [False] * n - dp[0] = True - pre_sum = [0] * (n + 1) - pre_sum[1] = 1 - for i in range(1, n): - if s[i] == '0': - l = max(0, i - maxJump) - r = i - minJump - if r >= l and pre_sum[r + 1] - pre_sum[l] > 0: - dp[i] = True - pre_sum[i + 1] = pre_sum[i] + dp[i] - return dp[n - 1]","def sample_funcname ( var_0 : str , var_2 : int , var_4 : int ) -> bool : - var_7 = len ( var_0 ) - var_9 = [ False ] * var_7 - var_9 [ 0 ] = True - var_13 = [ 0 ] * ( var_7 + 1 ) - var_13 [ 1 ] = 1 - for var_15 in range ( 1 , var_7 ) : - if var_0 [ var_15 ] == '0' : - var_18 = max ( 0 , var_15 - var_4 ) - var_19 = var_15 - var_2 - if var_19 >= var_18 and var_13 [ var_19 + 1 ] - var_13 [ var_18 ] > 0 : - var_9 [ var_15 ] = True - var_13 [ var_15 + 1 ] = var_13 [ var_15 ] + var_9 [ var_15 ] - return var_9 [ var_7 - 1 ] -",100,3 -1361,2235.Add Two Integers_1.py,"def sum( num1: int, num2: int) -> int: - return num1 + num2","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - return var_0 + var_2 -",,0 -1362,0271.Encode and Decode Strings_2.py,"def decode( s: str) -> List[str]: - ans = [] - i, n = 0, len(s) - while i < n: - size = int(s[i : i + 4]) - i += 4 - ans.append(s[i : i + size]) - i += size - return ans","def sample_funcname ( var_0 : str ) -> List [ str ] : - var_3 = [ ] - var_5 , var_7 = 0 , len ( var_0 ) - while var_5 < var_7 : - var_10 = int ( var_0 [ var_5 : var_5 + 4 ] ) - var_5 += 4 - var_3.append ( var_0 [ var_5 : var_5 + var_10 ] ) - var_5 += var_10 - return var_3 -",04,2 -1363,0204.Count Primes_1.py,"def countPrimes( n: int) -> int: - primes = [True] * n - ans = 0 - for i in range(2, n): - if primes[i]: - ans += 1 - for j in range(i + i, n, i): - primes[j] = False - return ans","def sample_funcname ( var_0 : int ) -> int : - var_3 = [ True ] * var_0 - var_5 = 0 - for var_8 in range ( 2 , var_0 ) : - if var_3 [ var_8 ] : - var_5 += 1 - for var_10 in range ( var_8 + var_8 , var_0 , var_8 ) : - var_3 [ var_10 ] = False - return var_5 -",102,3 -1364,0556.Next Greater Element III_1.py,"def nextGreaterElement( n: int) -> int: - cs = list(str(n)) - n = len(cs) - i, j = n - 2, n - 1 - while i >= 0 and cs[i] >= cs[i + 1]: - i -= 1 - if i < 0: - return -1 - while cs[i] >= cs[j]: - j -= 1 - cs[i], cs[j] = cs[j], cs[i] - cs[i + 1 :] = cs[i + 1 :][::-1] - ans = int(''.join(cs)) - return -1 if ans > 2**31 - 1 else ans","def sample_funcname ( var_0 : int ) -> int : - var_4 = list ( str ( var_0 ) ) - var_0 = len ( var_4 ) - var_7 , var_9 = var_0 - 2 , var_0 - 1 - while var_7 >= 0 and var_4 [ var_7 ] >= var_4 [ var_7 + 1 ] : - var_7 -= 1 - if var_7 < 0 : - return - 1 - while var_4 [ var_7 ] >= var_4 [ var_9 ] : - var_9 -= 1 - var_4 [ var_7 ] , var_4 [ var_9 ] = var_4 [ var_9 ] , var_4 [ var_7 ] - var_4 [ var_7 + 1 : ] = var_4 [ var_7 + 1 : ] [ : : - 1 ] - var_13 = int ( ''.join ( var_4 ) ) - return - 1 if var_13 > 2 ** 31 - 1 else var_13 -",03121,5 -1365,0099.Recover Binary Search Tree_1.py,"def dfs(root): - nonlocal prev, first, second - if root: - dfs(root.left) - if prev: - if first is None and root.val < prev.val: - first = prev - if first and root.val < prev.val: - second = root - prev = root - dfs(root.right)","def sample_funcname ( var_1 ) : - nonlocal var_2 , var_3 , var_4 - if var_1 : - var_0 ( var_1.left ) - if var_2 : - if var_3 is None and var_1.val < var_2.val : - var_3 = var_2 - if var_3 and var_1.val < var_2.val : - var_4 = var_1 - var_2 = var_1 - var_0 ( var_1.right ) -",None,1 -1366,0366.Find Leaves of Binary Tree_1.py,"def dfs(root, prev, t): - if root is None: - return - if root.left is None and root.right is None: - t.append(root.val) - if prev.left == root: - prev.left = None - else: - prev.right = None - dfs(root.left, root, t) - dfs(root.right, root, t)","def sample_funcname ( var_1 , var_2 , var_3 ) : - if var_1 is None : - return - if var_1.left is None and var_1.right is None : - var_3.append ( var_1.val ) - if var_2.left == var_1 : - var_2.left = None - else : - var_2.right = None - var_0 ( var_1.left , var_1 , var_3 ) - var_0 ( var_1.right , var_1 , var_3 ) -",None,1 -1367,0503.Next Greater Element II_1.py,"def nextGreaterElements( nums: List[int]) -> List[int]: - n = len(nums) - ans = [-1] * n - stk = [] - for i in range(n << 1): - while stk and nums[stk[-1]] < nums[i % n]: - ans[stk.pop()] = nums[i % n] - stk.append(i % n) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 = len ( var_0 ) - var_6 = [ - 1 ] * var_4 - var_7 = [ ] - for var_9 in range ( var_4 << 1 ) : - while var_7 and var_0 [ var_7 [ - 1 ] ] < var_0 [ var_9 % var_4 ] : - var_6 [ var_7.pop ( ) ] = var_0 [ var_9 % var_4 ] - var_7.append ( var_9 % var_4 ) - return var_6 -",1,1 -1368,0416.Partition Equal Subset Sum_1.py,"def canPartition( nums: List[int]) -> bool: - s = sum(nums) - if s % 2 != 0: - return False - n = s >> 1 - dp = [False] * (n + 1) - dp[0] = True - for v in nums: - for j in range(n, v - 1, -1): - dp[j] = dp[j] or dp[j - v] - return dp[-1]","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_5 = sum ( var_0 ) - if var_5 % 2 != 0 : - return False - var_10 = var_5 >> 1 - var_11 = [ False ] * ( var_10 + 1 ) - var_11 [ 0 ] = True - for var_13 in var_0 : - for var_15 in range ( var_10 , var_13 - 1 , - 1 ) : - var_11 [ var_15 ] = var_11 [ var_15 ] or var_11 [ var_15 - var_13 ] - return var_11 [ - 1 ] -",102,3 -1369,0674.Longest Continuous Increasing Subsequence_1.py,"def findLengthOfLCIS( nums: List[int]) -> int: - n = len(nums) - res = f = 1 - for i in range(1, n): - f = 1 + (f if nums[i - 1] < nums[i] else 0) - res = max(res, f) - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_7 = var_5 = 1 - for var_9 in range ( 1 , var_4 ) : - var_5 = 1 + ( var_5 if var_0 [ var_9 - 1 ] < var_0 [ var_9 ] else 0 ) - var_7 = max ( var_7 , var_5 ) - return var_7 -",10,2 -1370,1554.Strings Differ by One Character_1.py,"def differByOne( dict: List[str]) -> bool: - s = set() - for word in dict: - for i in range(len(word)): - t = word[:i] + ""*"" + word[i + 1 :] - if t in s: - return True - s.add(t) - return False","def sample_funcname ( var_0 : List [ str ] ) -> bool : - var_5 = set ( ) - for var_6 in var_0 : - for var_9 in range ( len ( var_6 ) ) : - var_12 = var_6 [ : var_9 ] + ""*"" + var_6 [ var_9 + 1 : ] - if var_12 in var_5 : - return True - var_5.add ( var_12 ) - return False -",*1,2 -1371,1111.Maximum Nesting Depth of Two Valid Parentheses Strings_1.py,"def maxDepthAfterSplit( seq: str) -> List[int]: - ans = [0] * len(seq) - a = b = 0 - for i, c in enumerate(seq): - if c == ""("": - if a < b: - a += 1 - else: - b += 1 - ans[i] = 1 - else: - if a > b: - a -= 1 - else: - b -= 1 - ans[i] = 1 - return ans","def sample_funcname ( var_0 : str ) -> List [ int ] : - var_6 = [ 0 ] * len ( var_0 ) - var_8 = var_7 = 0 - for var_10 , var_11 in enumerate ( var_0 ) : - if var_11 == ""("" : - if var_8 < var_7 : - var_8 += 1 - else : - var_7 += 1 - var_6 [ var_10 ] = 1 - else : - if var_8 > var_7 : - var_8 -= 1 - else : - var_7 -= 1 - var_6 [ var_10 ] = 1 - return var_6 -",(01,3 -1373,2161.Partition Array According to Given Pivot_1.py,"def pivotArray( nums: List[int], pivot: int) -> List[int]: - a, b, c = [], [], [] - for x in nums: - if x < pivot: - a.append(x) - elif x == pivot: - b.append(x) - else: - c.append(x) - return a + b + c","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_4 , var_5 , var_6 = [ ] , [ ] , [ ] - for var_7 in var_0 : - if var_7 < var_3 : - var_4.append ( var_7 ) - elif var_7 == var_3 : - var_5.append ( var_7 ) - else : - var_6.append ( var_7 ) - return var_4 + var_5 + var_6 -",,0 -1374,0969.Pancake Sorting_1.py,"def reverse(arr, j): - i = 0 - while i < j: - arr[i], arr[j] = arr[j], arr[i] - i, j = i + 1, j - 1","def sample_funcname ( var_0 , var_1 ) : - var_3 = 0 - while var_3 < var_1 : - var_0 [ var_3 ] , var_0 [ var_1 ] = var_0 [ var_1 ] , var_0 [ var_3 ] - var_3 , var_1 = var_3 + 1 , var_1 - 1 -",10,2 -1375,0252.Meeting Rooms_1.py,"def canAttendMeetings( intervals: List[List[int]]) -> bool: - intervals.sort(key=lambda x: x[0]) - for i in range(len(intervals) - 1): - if intervals[i][1] > intervals[i + 1][0]: - return False - return True","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> bool : - var_0.sort ( var_5 = lambda var_6 : var_6 [ 0 ] ) - for var_11 in range ( len ( var_0 ) - 1 ) : - if var_0 [ var_11 ] [ 1 ] > var_0 [ var_11 + 1 ] [ 0 ] : - return False - return True -",10,2 -1376,2122.Recover the Original Array_1.py,"def recoverArray( nums: List[int]) -> List[int]: - nums.sort() - n = len(nums) - for i in range(1, n): - d = nums[i] - nums[0] - if d == 0 or d % 2 == 1: - continue - vis = [False] * n - vis[i] = True - ans = [(nums[0] + nums[i]) >> 1] - l, r = 1, i + 1 - while r < n: - while l < n and vis[l]: - l += 1 - while r < n and nums[r] - nums[l] < d: - r += 1 - if r == n or nums[r] - nums[l] > d: - break - vis[r] = True - ans.append((nums[l] + nums[r]) >> 1) - l, r = l + 1, r + 1 - if len(ans) == (n >> 1): - return ans - return []","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_0.sort ( ) - var_5 = len ( var_0 ) - for var_8 in range ( 1 , var_5 ) : - var_10 = var_0 [ var_8 ] - var_0 [ 0 ] - if var_10 == 0 or var_10 % 2 == 1 : - continue - var_13 = [ False ] * var_5 - var_13 [ var_8 ] = True - var_15 = [ ( var_0 [ 0 ] + var_0 [ var_8 ] ) >> 1 ] - var_16 , var_17 = 1 , var_8 + 1 - while var_17 < var_5 : - while var_16 < var_5 and var_13 [ var_16 ] : - var_16 += 1 - while var_17 < var_5 and var_0 [ var_17 ] - var_0 [ var_16 ] < var_10 : - var_17 += 1 - if var_17 == var_5 or var_0 [ var_17 ] - var_0 [ var_16 ] > var_10 : - break - var_13 [ var_17 ] = True - var_15.append ( ( var_0 [ var_16 ] + var_0 [ var_17 ] ) >> 1 ) - var_16 , var_17 = var_16 + 1 , var_17 + 1 - if len ( var_15 ) == ( var_5 >> 1 ) : - return var_15 - return [ ] -",102,3 -1377,0724.Find Pivot Index_1.py,"def pivotIndex( nums: List[int]) -> int: - s, presum = sum(nums), 0 - for i, v in enumerate(nums): - if (presum << 1) == s - v: - return i - presum += v - return -1","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_6 = sum ( var_0 ) , 0 - for var_8 , var_9 in enumerate ( var_0 ) : - if ( var_6 << 1 ) == var_4 - var_9 : - return var_8 - var_6 += var_9 - return - 1 -",10,2 -1378,0007.Reverse Integer_1.py,"def reverse( x: int) -> int: - y = int(str(abs(x))[::-1]) - res = -y if x < 0 else y - return 0 if res < -(2**31) or res > 2**31 - 1 else res","def sample_funcname ( var_0 : int ) -> int : - var_5 = int ( str ( abs ( var_0 ) ) [ : : - 1 ] ) - var_7 = - var_5 if var_0 < 0 else var_5 - return 0 if var_7 < - ( 2 ** 31 ) or var_7 > 2 ** 31 - 1 else var_7 -",13102,4 -1379,1243.Array Transformation_1.py,"def transformArray( arr: List[int]) -> List[int]: - copy = [e for e in arr] - has_change, n = True, len(arr) - while has_change: - has_change = False - for i in range(1, n - 1): - if arr[i] < copy[i - 1] and arr[i] < copy[i + 1]: - arr[i] += 1 - has_change = True - elif arr[i] > copy[i - 1] and arr[i] > copy[i + 1]: - arr[i] -= 1 - has_change = True - copy = [e for e in arr] - return arr","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 = [ var_3 for var_3 in var_0 ] - var_6 , var_8 = True , len ( var_0 ) - while var_6 : - var_6 = False - for var_12 in range ( 1 , var_8 - 1 ) : - if var_0 [ var_12 ] < var_4 [ var_12 - 1 ] and var_0 [ var_12 ] < var_4 [ var_12 + 1 ] : - var_0 [ var_12 ] += 1 - var_6 = True - elif var_0 [ var_12 ] > var_4 [ var_12 - 1 ] and var_0 [ var_12 ] > var_4 [ var_12 + 1 ] : - var_0 [ var_12 ] -= 1 - var_6 = True - var_4 = [ var_3 for var_3 in var_0 ] - return var_0 -",1,1 -1380,0357.Count Numbers with Unique Digits_1.py,"def countNumbersWithUniqueDigits( n: int) -> int: - if n == 0: - return 1 - if n == 1: - return 10 - ans, cur = 10, 9 - for i in range(n - 1): - cur *= 9 - i - ans += cur - return ans","def sample_funcname ( var_0 : int ) -> int : - if var_0 == 0 : - return 1 - if var_0 == 1 : - return 10 - var_5 , var_7 = 10 , 9 - for var_9 in range ( var_0 - 1 ) : - var_7 *= 9 - var_9 - var_5 += var_7 - return var_5 -",10109,4 -1382,1837.Sum of Digits in Base K_1.py,"def sumBase( n: int, k: int) -> int: - res = 0 - while n != 0: - n, t = divmod(n, k) - res += t - return res","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_4 = 0 - while var_0 != 0 : - var_0 , var_6 = divmod ( var_0 , var_2 ) - var_4 += var_6 - return var_4 -",0,1 -1383,1791.Find Center of Star Graph_1.py,"def findCenter( edges: List[List[int]]) -> int: - return edges[0][0] if edges[0][0] in edges[1] else edges[0][1]","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - return var_0 [ 0 ] [ 0 ] if var_0 [ 0 ] [ 0 ] in var_0 [ 1 ] else var_0 [ 0 ] [ 1 ] -",10,2 -1384,0896.Monotonic Array_1.py,"def isMonotonic( nums: List[int]) -> bool: - isIncr = isDecr = False - for i, v in enumerate(nums[1:]): - if v < nums[i]: - isIncr = True - elif v > nums[i]: - isDecr = True - if isIncr and isDecr: - return False - return True","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_6 = var_4 = False - for var_8 , var_10 in enumerate ( var_0 [ 1 : ] ) : - if var_10 < var_0 [ var_8 ] : - var_6 = True - elif var_10 > var_0 [ var_8 ] : - var_4 = True - if var_6 and var_4 : - return False - return True -",1,1 -1385,0537.Complex Number Multiplication_1.py,"def complexNumberMultiply( num1: str, num2: str) -> str: - a, b = map(int, num1[:-1].split('+')) - c, d = map(int, num2[:-1].split('+')) - return f'{a * c - b * d}+{a * d + c * b}i'","def sample_funcname ( var_0 : str , var_2 : str ) -> str : - var_4 , var_9 = map ( int , var_0 [ : - 1 ].split ( '+' ) ) - var_10 , var_11 = map ( int , var_2 [ : - 1 ].split ( '+' ) ) - return f'{var_4 * var_10 - var_9 * var_11}+{var_4 * var_11 + var_10 * var_9}i' -",f{var_4 * var_10 - var_9 * var_11}+{var_4 * var_11 + var_10 * var_9}i1+,3 -1386,1137.N-th Tribonacci Number_1.py,"def tribonacci( n: int) -> int: - a, b, c = 0, 1, 1 - for _ in range(n): - a, b, c = b, c, a + b + c - return a","def sample_funcname ( var_0 : int ) -> int : - var_3 , var_5 , var_6 = 0 , 1 , 1 - for var_8 in range ( var_0 ) : - var_3 , var_5 , var_6 = var_5 , var_6 , var_3 + var_5 + var_6 - return var_3 -",10,2 -1387,1475.Final Prices With a Special Discount in a Shop_1.py,"def finalPrices( prices: List[int]) -> List[int]: - stk = [] - ans = prices[:] - for i, v in enumerate(prices): - while stk and prices[stk[-1]] >= v: - ans[stk.pop()] -= v - stk.append(i) - return ans","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_3 = [ ] - var_4 = var_0 [ : ] - for var_6 , var_7 in enumerate ( var_0 ) : - while var_3 and var_0 [ var_3 [ - 1 ] ] >= var_7 : - var_4 [ var_3.pop ( ) ] -= var_7 - var_3.append ( var_6 ) - return var_4 -",1,1 -1388,0344.Reverse String_1.py,"def reverseString( s: List[str]) -> None: - s[:] = s[::-1]","def sample_funcname ( var_0 : List [ str ] ) -> None : - var_0 [ : ] = var_0 [ : : - 1 ] -",1None,2 -1389,1422.Maximum Score After Splitting a String_1.py,"def maxScore( s: str) -> int: - ans = t = (s[0] == '0') + s[1:].count('1') - for i in range(1, len(s) - 1): - t += 1 if s[i] == '0' else -1 - ans = max(ans, t) - return ans","def sample_funcname ( var_0 : str ) -> int : - var_9 = var_3 = ( var_0 [ 0 ] == '0' ) + var_0 [ 1 : ].count ( '1' ) - for var_12 in range ( 1 , len ( var_0 ) - 1 ) : - var_3 += 1 if var_0 [ var_12 ] == '0' else - 1 - var_9 = max ( var_9 , var_3 ) - return var_9 -",1001,4 -1390,0688.Knight Probability in Chessboard_1.py,"def knightProbability( n: int, k: int, row: int, column: int) -> float: - dp = [[[0] * n for _ in range(n)] for _ in range(k + 1)] - for l in range(k + 1): - for i in range(n): - for j in range(n): - if l == 0: - dp[l][i][j] = 1 - else: - for a, b in ( - (-2, -1), - (-2, 1), - (2, -1), - (2, 1), - (-1, -2), - (-1, 2), - (1, -2), - (1, 2), - ): - x, y = i + a, j + b - if 0 <= x < n and 0 <= y < n: - dp[l][i][j] += dp[l - 1][x][y] / 8 - return dp[k][row][column]","def sample_funcname ( var_0 : int , var_2 : int , var_3 : int , var_4 : int ) -> float : - var_10 = [ [ [ 0 ] * var_0 for var_7 in range ( var_0 ) ] for var_7 in range ( var_2 + 1 ) ] - for var_11 in range ( var_2 + 1 ) : - for var_12 in range ( var_0 ) : - for var_13 in range ( var_0 ) : - if var_11 == 0 : - var_10 [ var_11 ] [ var_12 ] [ var_13 ] = 1 - else : - for var_15 , var_16 in ( ( - 2 , - 1 ) , ( - 2 , 1 ) , ( 2 , - 1 ) , ( 2 , 1 ) , ( - 1 , - 2 ) , ( - 1 , 2 ) , ( 1 , - 2 ) , ( 1 , 2 ) , ) : - var_17 , var_18 = var_12 + var_15 , var_13 + var_16 - if 0 <= var_17 < var_0 and 0 <= var_18 < var_0 : - var_10 [ var_11 ] [ var_12 ] [ var_13 ] += var_10 [ var_11 - 1 ] [ var_17 ] [ var_18 ] / 8 - return var_10 [ var_2 ] [ var_3 ] [ var_4 ] -",1028,4 -1391,0717.1-bit and 2-bit Characters_1.py,"def isOneBitCharacter( bits: List[int]) -> bool: - i, n = 0, len(bits) - while i < n - 1: - i += bits[i] + 1 - return i == n - 1","def sample_funcname ( var_0 : List [ int ] ) -> bool : - var_5 , var_7 = 0 , len ( var_0 ) - while var_5 < var_7 - 1 : - var_5 += var_0 [ var_5 ] + 1 - return var_5 == var_7 - 1 -",10,2 -1392,0892.Surface Area of 3D Shapes_1.py,"def surfaceArea( grid: List[List[int]]) -> int: - ans = 0 - for i, row in enumerate(grid): - for j, v in enumerate(row): - if v: - ans += 2 + v * 4 - if i: - ans -= min(v, grid[i - 1][j]) * 2 - if j: - ans -= min(v, grid[i][j - 1]) * 2 - return ans","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> int : - var_4 = 0 - for var_6 , var_7 in enumerate ( var_0 ) : - for var_8 , var_9 in enumerate ( var_7 ) : - if var_9 : - var_4 += 2 + var_9 * 4 - if var_6 : - var_4 -= min ( var_9 , var_0 [ var_6 - 1 ] [ var_8 ] ) * 2 - if var_8 : - var_4 -= min ( var_9 , var_0 [ var_6 ] [ var_8 - 1 ] ) * 2 - return var_4 -",1042,4 -1393,2031.Count Subarrays With More Ones Than Zeros_1.py,"def lowbit(x): - x += int(1e5 + 1) - return x & -x","def sample_funcname ( var_0 ) : - var_0 += int ( 1e5 + 1 ) - return var_0 & - var_0 -",11e5,2 -1394,2213.Longest Substring of One Repeating Character_1.py,"def _pushup( root, left, right): - root.lc, root.rc = left.lc, right.rc - root.size = left.size + right.size - - root.mx = max(left.mx, right.mx) - root.lmx, root.rmx = left.lmx, right.rmx - - if left.rc == right.lc: - if left.lmx == left.size: - root.lmx += right.lmx - if right.rmx == right.size: - root.rmx += left.rmx - root.mx = max(root.mx, left.rmx + right.lmx)","def sample_funcname ( var_0 , var_1 , var_2 ) : - var_0.lc , var_0.rc = var_1.lc , var_2.rc - var_0.size = var_1.size + var_2.size - var_0.mx = max ( var_1.mx , var_2.mx ) - var_0.lmx , var_0.rmx = var_1.lmx , var_2.rmx - if var_1.rc == var_2.lc : - if var_1.lmx == var_1.size : - var_0.lmx += var_2.lmx - if var_2.rmx == var_2.size : - var_0.rmx += var_1.rmx - var_0.mx = max ( var_0.mx , var_1.rmx + var_2.lmx ) -",,0 -1395,1638.Count Substrings That Differ by One Character_1.py,"def countSubstrings( s: str, t: str) -> int: - m, n = len(s), len(t) - ans = 0 - for i in range(m): - for j in range(n): - if s[i] != t[j]: - l = r = 1 - while i - l >= 0 and j - l >= 0 and s[i - l] == t[j - l]: - l += 1 - while i + r < m and j + r < n and s[i + r] == t[j + r]: - r += 1 - ans += l * r - return ans","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - var_5 , var_6 = len ( var_0 ) , len ( var_2 ) - var_8 = 0 - for var_10 in range ( var_5 ) : - for var_11 in range ( var_6 ) : - if var_0 [ var_10 ] != var_2 [ var_11 ] : - var_14 = var_13 = 1 - while var_10 - var_14 >= 0 and var_11 - var_14 >= 0 and var_0 [ var_10 - var_14 ] == var_2 [ var_11 - var_14 ] : - var_14 += 1 - while var_10 + var_13 < var_5 and var_11 + var_13 < var_6 and var_0 [ var_10 + var_13 ] == var_2 [ var_11 + var_13 ] : - var_13 += 1 - var_8 += var_14 * var_13 - return var_8 -",10,2 -1396,1566.Detect Pattern of Length M Repeated K or More Times_1.py,"def containsPattern( arr: List[int], m: int, k: int) -> bool: - n = len(arr) - for i in range(n - m * k + 1): - j = 0 - while j < m * k: - if arr[i + j] != arr[i + (j % m)]: - break - j += 1 - if j == m * k: - return True - return False","def sample_funcname ( var_0 : List [ int ] , var_3 : int , var_4 : int ) -> bool : - var_7 = len ( var_0 ) - for var_10 in range ( var_7 - var_3 * var_4 + 1 ) : - var_12 = 0 - while var_12 < var_3 * var_4 : - if var_0 [ var_10 + var_12 ] != var_0 [ var_10 + ( var_12 % var_3 ) ] : - break - var_12 += 1 - if var_12 == var_3 * var_4 : - return True - return False -",10,2 -1397,2154.Keep Multiplying Found Values by Two_1.py,"def findFinalValue( nums: List[int], original: int) -> int: - s = set(nums) - while original in s: - original <<= 1 - return original","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 = set ( var_0 ) - while var_3 in var_5 : - var_3 <<= 1 - return var_3 -",1,1 -1398,2221.Find Triangular Sum of an Array_1.py,"def triangularSum( nums: List[int]) -> int: - n = len(nums) - for i in range(n, 0, -1): - for j in range(i - 1): - nums[j] = (nums[j] + nums[j + 1]) % 10 - return nums[0]","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - for var_8 in range ( var_4 , 0 , - 1 ) : - for var_9 in range ( var_8 - 1 ) : - var_0 [ var_9 ] = ( var_0 [ var_9 ] + var_0 [ var_9 + 1 ] ) % 10 - return var_0 [ 0 ] -",1010,3 -1399,0881.Boats to Save People_1.py,"def numRescueBoats( people: List[int], limit: int) -> int: - people.sort() - num, i, j = 0, 0, len(people) - 1 - while i <= j: - if people[i] + people[j] <= limit: - i += 1 - j -= 1 - num += 1 - return num","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_0.sort ( ) - var_6 , var_7 , var_10 = 0 , 0 , len ( var_0 ) - 1 - while var_7 <= var_10 : - if var_0 [ var_7 ] + var_0 [ var_10 ] <= var_3 : - var_7 += 1 - var_10 -= 1 - var_6 += 1 - return var_6 -",10,2 -1400,1826.Faulty Sensor_1.py,"def badSensor( sensor1: List[int], sensor2: List[int]) -> int: - i, n = 0, len(sensor1) - while i < n - 1: - if sensor1[i] != sensor2[i]: - break - i += 1 - while i < n - 1: - if sensor1[i + 1] != sensor2[i]: - return 1 - if sensor1[i] != sensor2[i + 1]: - return 2 - i += 1 - return -1","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> int : - var_5 , var_7 = 0 , len ( var_0 ) - while var_5 < var_7 - 1 : - if var_0 [ var_5 ] != var_3 [ var_5 ] : - break - var_5 += 1 - while var_5 < var_7 - 1 : - if var_0 [ var_5 + 1 ] != var_3 [ var_5 ] : - return 1 - if var_0 [ var_5 ] != var_3 [ var_5 + 1 ] : - return 2 - var_5 += 1 - return - 1 -",102,3 -1401,0246.Strobogrammatic Number_1.py,"def match(a, b): - if a in {'0', '1', '8'}: - return a == b - if a == '6': - return b == '9' - if a == '9': - return b == '6' - return False","def sample_funcname ( var_0 , var_1 ) : - if var_0 in { '0' , '1' , '8' } : - return var_0 == var_1 - if var_0 == '6' : - return var_1 == '9' - if var_0 == '9' : - return var_1 == '6' - return False -",98016,5 -1402,0119.Pascal's Triangle II_1.py,"def getRow( rowIndex: int) -> List[int]: - row = [1] * (rowIndex + 1) - for i in range(2, rowIndex + 1): - for j in range(i - 1, 0, -1): - row[j] += row[j - 1] - return row","def sample_funcname ( var_0 : int ) -> List [ int ] : - var_4 = [ 1 ] * ( var_0 + 1 ) - for var_7 in range ( 2 , var_0 + 1 ) : - for var_9 in range ( var_7 - 1 , 0 , - 1 ) : - var_4 [ var_9 ] += var_4 [ var_9 - 1 ] - return var_4 -",102,3 -1403,1701.Average Waiting Time_1.py,"def averageWaitingTime( customers: List[List[int]]) -> float: - f = total_waiting_time = 0 - for arrival, time in customers: - f = max(arrival, f) + time - total_waiting_time += f - arrival - return total_waiting_time / len(customers)","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> float : - var_6 = var_4 = 0 - for var_7 , var_8 in var_0 : - var_6 = max ( var_7 , var_6 ) + var_8 - var_4 += var_6 - var_7 - return var_4 / len ( var_0 ) -",0,1 -1404,2210.Count Hills and Valleys in an Array_1.py,"def countHillValley( nums: List[int]) -> int: - ans = j = 0 - for i in range(1, len(nums) - 1): - if nums[i] == nums[i + 1]: - continue - if nums[i] > nums[j] and nums[i] > nums[i + 1]: - ans += 1 - if nums[i] < nums[j] and nums[i] < nums[i + 1]: - ans += 1 - j = i - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_5 = var_3 = 0 - for var_9 in range ( 1 , len ( var_0 ) - 1 ) : - if var_0 [ var_9 ] == var_0 [ var_9 + 1 ] : - continue - if var_0 [ var_9 ] > var_0 [ var_3 ] and var_0 [ var_9 ] > var_0 [ var_9 + 1 ] : - var_5 += 1 - if var_0 [ var_9 ] < var_0 [ var_3 ] and var_0 [ var_9 ] < var_0 [ var_9 + 1 ] : - var_5 += 1 - var_3 = var_9 - return var_5 -",10,2 -1405,1236.Web Crawler_1.py,"def host(url): - url = url[7:] - return url.split('/')[0]","def sample_funcname ( var_0 ) : - var_0 = var_0 [ 7 : ] - return var_0.split ( '/' ) [ 0 ] -",70/,3 -1406,2350.Shortest Impossible Sequence of Rolls_1.py,"def shortestSequence( rolls: List[int], k: int) -> int: - ans = 1 - s = set() - for v in rolls: - s.add(v) - if len(s) == k: - ans += 1 - s.clear() - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 = 1 - var_7 = set ( ) - for var_8 in var_0 : - var_7.add ( var_8 ) - if len ( var_7 ) == var_3 : - var_5 += 1 - var_7.clear ( ) - return var_5 -",1,1 -1407,1420.Build Array Where You Can Find The Maximum Exactly K Comparisons_1.py,"def numOfArrays( n: int, m: int, k: int) -> int: - if k == 0: - return 0 - dp = [[[0] * (m + 1) for _ in range(k + 1)] for _ in range(n + 1)] - mod = 10**9 + 7 - for i in range(1, m + 1): - dp[1][1][i] = 1 - for i in range(2, n + 1): - for c in range(1, min(k + 1, i + 1)): - for j in range(1, m + 1): - dp[i][c][j] = dp[i - 1][c][j] * j - for j0 in range(1, j): - dp[i][c][j] += dp[i - 1][c - 1][j0] - dp[i][c][j] %= mod - ans = 0 - for i in range(1, m + 1): - ans += dp[n][k][i] - ans %= mod - return ans","def sample_funcname ( var_0 : int , var_2 : int , var_3 : int ) -> int : - if var_3 == 0 : - return 0 - var_8 = [ [ [ 0 ] * ( var_2 + 1 ) for var_6 in range ( var_3 + 1 ) ] for var_6 in range ( var_0 + 1 ) ] - var_12 = 10 ** 9 + 7 - for var_13 in range ( 1 , var_2 + 1 ) : - var_8 [ 1 ] [ 1 ] [ var_13 ] = 1 - for var_13 in range ( 2 , var_0 + 1 ) : - for var_16 in range ( 1 , min ( var_3 + 1 , var_13 + 1 ) ) : - for var_17 in range ( 1 , var_2 + 1 ) : - var_8 [ var_13 ] [ var_16 ] [ var_17 ] = var_8 [ var_13 - 1 ] [ var_16 ] [ var_17 ] * var_17 - for var_18 in range ( 1 , var_17 ) : - var_8 [ var_13 ] [ var_16 ] [ var_17 ] += var_8 [ var_13 - 1 ] [ var_16 - 1 ] [ var_18 ] - var_8 [ var_13 ] [ var_16 ] [ var_17 ] %= var_12 - var_19 = 0 - for var_13 in range ( 1 , var_2 + 1 ) : - var_19 += var_8 [ var_0 ] [ var_3 ] [ var_13 ] - var_19 %= var_12 - return var_19 -",1002179,6 -1408,0240.Search a 2D Matrix II_1.py,"def searchMatrix( matrix: List[List[int]], target: int) -> bool: - m, n = len(matrix), len(matrix[0]) - i, j = m - 1, 0 - while i >= 0 and j < n: - if matrix[i][j] == target: - return True - if matrix[i][j] > target: - i -= 1 - else: - j += 1 - return False","def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : int ) -> bool : - var_6 , var_8 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_10 , var_11 = var_6 - 1 , 0 - while var_10 >= 0 and var_11 < var_8 : - if var_0 [ var_10 ] [ var_11 ] == var_3 : - return True - if var_0 [ var_10 ] [ var_11 ] > var_3 : - var_10 -= 1 - else : - var_11 += 1 - return False -",10,2 -1409,2023.Number of Pairs of Strings With Concatenation Equal to Target_1.py,"def numOfPairs( nums: List[str], target: str) -> int: - n = len(nums) - return sum( - i != j and nums[i] + nums[j] == target for i in range(n) for j in range(n) - )","def sample_funcname ( var_0 : List [ str ] , var_3 : str ) -> int : - var_6 = len ( var_0 ) - return sum ( var_8 != var_9 and var_0 [ var_8 ] + var_0 [ var_9 ] == var_3 for var_8 in range ( var_6 ) for var_9 in range ( var_6 ) ) -",,0 -1410,0168.Excel Sheet Column Title_1.py,"def convertToTitle( columnNumber: int) -> str: - res = [] - while columnNumber: - columnNumber -= 1 - res.append(chr(ord('A') + columnNumber % 26)) - columnNumber //= 26 - return ''.join(res[::-1])","def sample_funcname ( var_0 : int ) -> str : - var_3 = [ ] - while var_0 : - var_0 -= 1 - var_3.append ( chr ( ord ( 'A' ) + var_0 % 26 ) ) - var_0 //= 26 - return ''.join ( var_3 [ : : - 1 ] ) -",A126,4 -1411,2000.Reverse Prefix of Word_1.py,"def reversePrefix( word: str, ch: str) -> str: - i = word.find(ch) - return word if i == -1 else word[i::-1] + word[i + 1 :]","def sample_funcname ( var_0 : str , var_2 : str ) -> str : - var_4 = var_0.find ( var_2 ) - return var_0 if var_4 == - 1 else var_0 [ var_4 : : - 1 ] + var_0 [ var_4 + 1 : ] -",1,1 -1412,1230.Toss Strange Coins_1.py,"def probabilityOfHeads( prob: List[float], target: int) -> float: - dp = [0] * (target + 1) - dp[0] = 1 - for v in prob: - for j in range(target, -1, -1): - dp[j] *= 1 - v - if j >= 1: - dp[j] += dp[j - 1] * v - return dp[-1]","def sample_funcname ( var_0 : List [ float ] , var_3 : int ) -> float : - var_7 = [ 0 ] * ( var_3 + 1 ) - var_7 [ 0 ] = 1 - for var_8 in var_0 : - for var_10 in range ( var_3 , - 1 , - 1 ) : - var_7 [ var_10 ] *= 1 - var_8 - if var_10 >= 1 : - var_7 [ var_10 ] += var_7 [ var_10 - 1 ] * var_8 - return var_7 [ - 1 ] -",10,2 -1413,1006.Clumsy Factorial_1.py,"def clumsy( N: int) -> int: - op = 0 - s = [N] - for i in range(N - 1, 0, -1): - if op == 0: - s.append(s.pop() * i) - elif op == 1: - s.append(int(s.pop() / i)) - elif op == 2: - s.append(i) - else: - s.append(-i) - op = (op + 1) % 4 - return sum(s)","def sample_funcname ( var_0 : int ) -> int : - var_3 = 0 - var_4 = [ var_0 ] - for var_7 in range ( var_0 - 1 , 0 , - 1 ) : - if var_3 == 0 : - var_4.append ( var_4.pop ( ) * var_7 ) - elif var_3 == 1 : - var_4.append ( int ( var_4.pop ( ) / var_7 ) ) - elif var_3 == 2 : - var_4.append ( var_7 ) - else : - var_4.append ( - var_7 ) - var_3 = ( var_3 + 1 ) % 4 - return sum ( var_4 ) -",1042,4 -1414,2367.Number of Arithmetic Triplets_1.py,"def arithmeticTriplets( nums: List[int], diff: int) -> int: - s = set(nums) - return sum(v + diff in s and v + diff + diff in s for v in nums)","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 = set ( var_0 ) - return sum ( var_7 + var_3 in var_5 and var_7 + var_3 + var_3 in var_5 for var_7 in var_0 ) -",,0 -1415,0151.Reverse Words in a String_1.py,"def reverseWords( s: str) -> str: - words = s.strip().split() - return ' '.join(words[::-1])","def sample_funcname ( var_0 : str ) -> str : - var_4 = var_0.var_2 ( ).split ( ) - return ' '.join ( var_4 [ : : - 1 ] ) -",1 ,2 -1416,0390.Elimination Game_1.py,"def lastRemaining( n: int) -> int: - a1, an = 1, n - i, step, cnt = 0, 1, n - while cnt > 1: - if i % 2: - an -= step - if cnt % 2: - a1 += step - else: - a1 += step - if cnt % 2: - an -= step - cnt >>= 1 - step <<= 1 - i += 1 - return a1","def sample_funcname ( var_0 : int ) -> int : - var_3 , var_4 = 1 , var_0 - var_6 , var_7 , var_8 = 0 , 1 , var_0 - while var_8 > 1 : - if var_6 % 2 : - var_4 -= var_7 - if var_8 % 2 : - var_3 += var_7 - else : - var_3 += var_7 - if var_8 % 2 : - var_4 -= var_7 - var_8 >>= 1 - var_7 <<= 1 - var_6 += 1 - return var_3 -",102,3 -1417,1175.Prime Arrangements_1.py,"def count(n): - cnt = 0 - primes = [True] * (n + 1) - for i in range(2, n + 1): - if primes[i]: - cnt += 1 - for j in range(i + i, n + 1, i): - primes[j] = False - return cnt","def sample_funcname ( var_0 ) : - var_2 = 0 - var_5 = [ True ] * ( var_0 + 1 ) - for var_8 in range ( 2 , var_0 + 1 ) : - if var_5 [ var_8 ] : - var_2 += 1 - for var_9 in range ( var_8 + var_8 , var_0 + 1 , var_8 ) : - var_5 [ var_9 ] = False - return var_2 -",102,3 -1418,1629.Slowest Key_1.py,"def slowestKey( releaseTimes: List[int], keysPressed: str) -> str: - ans = keysPressed[0] - mx = releaseTimes[0] - for i in range(1, len(keysPressed)): - d = releaseTimes[i] - releaseTimes[i - 1] - if d > mx or (d == mx and ord(keysPressed[i]) > ord(ans)): - mx = d - ans = keysPressed[i] - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : str ) -> str : - var_6 = var_3 [ 0 ] - var_7 = var_0 [ 0 ] - for var_11 in range ( 1 , len ( var_3 ) ) : - var_12 = var_0 [ var_11 ] - var_0 [ var_11 - 1 ] - if var_12 > var_7 or ( var_12 == var_7 and ord ( var_3 [ var_11 ] ) > ord ( var_6 ) ) : - var_7 = var_12 - var_6 = var_3 [ var_11 ] - return var_6 -",10,2 -1419,0032.Longest Valid Parentheses_1.py,"def longestValidParentheses( s): - Longest = temp = 0 - stack = [] - - for i in s: - if i == '(': - stack.append(i) - elif len(stack) != 0 and stack[-1] == '(': - stack.pop() - temp += 2 - else: - stack = [] - if temp > Longest: - Longest = temp - temp = 0 - if temp > Longest: - Longest = temp - return Longest","def sample_funcname ( var_0 ) : - var_3 = var_1 = 0 - var_4 = [ ] - for var_5 in var_0 : - if var_5 == '(' : - var_4.append ( var_5 ) - elif len ( var_4 ) != 0 and var_4 [ - 1 ] == '(' : - var_4.pop ( ) - var_1 += 2 - else : - var_4 = [ ] - if var_1 > var_3 : - var_3 = var_1 - var_1 = 0 - if var_1 > var_3 : - var_3 = var_1 - return var_3 -",1(02,4 -1420,0211.Design Add and Search Words Data Structure_1.py,"def search(word, node): - for i in range(len(word)): - c = word[i] - idx = ord(c) - ord('a') - if c != '.' and node.children[idx] is None: - return False - if c == '.': - for child in node.children: - if child is not None and search(word[i + 1 :], child): - return True - return False - node = node.children[idx] - return node.is_end","def sample_funcname ( var_1 , var_2 ) : - for var_5 in range ( len ( var_1 ) ) : - var_6 = var_1 [ var_5 ] - var_9 = ord ( var_6 ) - ord ( 'a' ) - if var_6 != '.' and var_2.children [ var_9 ] is None : - return False - if var_6 == '.' : - for var_14 in var_2.children : - if var_14 is not None and var_0 ( var_1 [ var_5 + 1 : ] , var_14 ) : - return True - return False - var_2 = var_2.children [ var_9 ] - return var_2.is_end -",a1None.,4 -1421,1614.Maximum Nesting Depth of the Parentheses_1.py,"def maxDepth( s: str) -> int: - n = ans = 0 - for c in s: - if c == '(': - n += 1 - ans = max(ans, n) - elif c == ')': - n -= 1 - return ans","def sample_funcname ( var_0 : str ) -> int : - var_5 = var_3 = 0 - for var_6 in var_0 : - if var_6 == '(' : - var_5 += 1 - var_3 = max ( var_3 , var_5 ) - elif var_6 == ')' : - var_5 -= 1 - return var_3 -",1(0),4 -1422,0494.Target Sum_1.py,"def findTargetSumWays( nums: List[int], target: int) -> int: - s = sum(nums) - if s < target or (s - target) % 2 != 0: - return 0 - n = (s - target) // 2 - dp = [0] * (n + 1) - dp[0] = 1 - for v in nums: - for j in range(n, v - 1, -1): - dp[j] += dp[j - v] - return dp[-1]","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 = sum ( var_0 ) - if var_5 < var_3 or ( var_5 - var_3 ) % 2 != 0 : - return 0 - var_8 = ( var_5 - var_3 ) // 2 - var_10 = [ 0 ] * ( var_8 + 1 ) - var_10 [ 0 ] = 1 - for var_11 in var_0 : - for var_13 in range ( var_8 , var_11 - 1 , - 1 ) : - var_10 [ var_13 ] += var_10 [ var_13 - var_11 ] - return var_10 [ - 1 ] -",102,3 -1423,0388.Longest Absolute File Path_1.py,"def lengthLongestPath( input: str) -> int: - i, n = 0, len(input) - ans = 0 - stk = [] - while i < n: - ident = 0 - while input[i] == '\t': - ident += 1 - i += 1 - - cur, isFile = 0, False - while i < n and input[i] != '\n': - cur += 1 - if input[i] == '.': - isFile = True - i += 1 - i += 1 - - while len(stk) > 0 and len(stk) > ident: - stk.pop() - - if len(stk) > 0: - cur += stk[-1] + 1 - - if not isFile: - stk.append(cur) - continue - - ans = max(ans, cur) - - return ans","def sample_funcname ( var_0 : str ) -> int : - var_4 , var_6 = 0 , len ( var_0 ) - var_7 = 0 - var_8 = [ ] - while var_4 < var_6 : - var_9 = 0 - while var_0 [ var_4 ] == '\t' : - var_9 += 1 - var_4 += 1 - var_12 , var_14 = 0 , False - while var_4 < var_6 and var_0 [ var_4 ] != '\n' : - var_12 += 1 - if var_0 [ var_4 ] == '.' : - var_14 = True - var_4 += 1 - var_4 += 1 - while len ( var_8 ) > 0 and len ( var_8 ) > var_9 : - var_8.pop ( ) - if len ( var_8 ) > 0 : - var_12 += var_8 [ - 1 ] + 1 - if not var_14 : - var_8.append ( var_12 ) - continue - var_7 = max ( var_7 , var_12 ) - return var_7 -",\n0\t.1,5 -1424,0118.Pascal's Triangle_1.py,"def generate( numRows: int) -> List[List[int]]: - ans = [] - for i in range(numRows): - t = [ - 1 if j == 0 or j == i else ans[-1][j] + ans[-1][j - 1] - for j in range(i + 1) - ] - ans.append(t) - return ans","def sample_funcname ( var_0 : int ) -> List [ List [ int ] ] : - var_3 = [ ] - for var_5 in range ( var_0 ) : - var_9 = [ 1 if var_6 == 0 or var_6 == var_5 else var_3 [ - 1 ] [ var_6 ] + var_3 [ - 1 ] [ var_6 - 1 ] for var_6 in range ( var_5 + 1 ) ] - var_3.append ( var_9 ) - return var_3 -",10,2 -1425,1963.Minimum Number of Swaps to Make the String Balanced_1.py,"def minSwaps( s: str) -> int: - ans = 0 - for c in s: - if c == '[': - ans += 1 - elif ans: - ans -= 1 - return (ans + 1) >> 1","def sample_funcname ( var_0 : str ) -> int : - var_4 = 0 - for var_5 in var_0 : - if var_5 == '[' : - var_4 += 1 - elif var_4 : - var_4 -= 1 - return ( var_4 + 1 ) >> 1 -",10[,3 -1426,1589.Maximum Sum Obtained of Any Permutation_1.py,"def maxSumRangeQuery( nums: List[int], requests: List[List[int]]) -> int: - n = 100010 - delta = [0] * n - for start, end in requests: - delta[start] += 1 - delta[end + 1] -= 1 - for i in range(1, n): - delta[i] += delta[i - 1] - nums.sort() - delta.sort() - i, j, res = n - 1, len(nums) - 1, 0 - while i > 0 and delta[i] > 0: - res += delta[i] * nums[j] - i -= 1 - j -= 1 - return res % 1000000007","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ List [ int ] ] ) -> int : - var_5 = 100010 - var_7 = [ 0 ] * var_5 - for var_8 , var_9 in var_3 : - var_7 [ var_8 ] += 1 - var_7 [ var_9 + 1 ] -= 1 - for var_12 in range ( 1 , var_5 ) : - var_7 [ var_12 ] += var_7 [ var_12 - 1 ] - var_0.sort ( ) - var_7.sort ( ) - var_12 , var_15 , var_16 = var_5 - 1 , len ( var_0 ) - 1 , 0 - while var_12 > 0 and var_7 [ var_12 ] > 0 : - var_16 += var_7 [ var_12 ] * var_0 [ var_15 ] - var_12 -= 1 - var_15 -= 1 - return var_16 % 1000000007 -",110001001000000007,4 -1427,1534.Count Good Triplets_1.py,"def countGoodTriplets( arr: List[int], a: int, b: int, c: int) -> int: - n = len(arr) - ans = 0 - for i in range(n): - for j in range(i + 1, n): - for k in range(j + 1, n): - if ( - abs(arr[i] - arr[j]) <= a - and abs(arr[j] - arr[k]) <= b - and abs(arr[i] - arr[k]) <= c - ): - ans += 1 - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int , var_4 : int , var_5 : int ) -> int : - var_7 = len ( var_0 ) - var_9 = 0 - for var_11 in range ( var_7 ) : - for var_13 in range ( var_11 + 1 , var_7 ) : - for var_14 in range ( var_13 + 1 , var_7 ) : - if ( abs ( var_0 [ var_11 ] - var_0 [ var_13 ] ) <= var_3 and abs ( var_0 [ var_13 ] - var_0 [ var_14 ] ) <= var_4 and abs ( var_0 [ var_11 ] - var_0 [ var_14 ] ) <= var_5 ) : - var_9 += 1 - return var_9 -",10,2 -1428,2176.Count Equal and Divisible Pairs in an Array_1.py,"def countPairs( nums: List[int], k: int) -> int: - n = len(nums) - return sum( - nums[i] == nums[j] and (i * j) % k == 0 - for i in range(n) - for j in range(i + 1, n) - )","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 = len ( var_0 ) - return sum ( var_0 [ var_7 ] == var_0 [ var_8 ] and ( var_7 * var_8 ) % var_3 == 0 for var_7 in range ( var_5 ) for var_8 in range ( var_7 + 1 , var_5 ) ) -",10,2 -1429,0671.Second Minimum Node In a Binary Tree_1.py,"def dfs(root, val): - if root: - dfs(root.left, val) - dfs(root.right, val) - nonlocal ans - if root.val > val: - ans = root.val if ans == -1 else min(ans, root.val)","def sample_funcname ( var_1 , val ) : - if var_1 : - var_0 ( var_1.left , val ) - var_0 ( var_1.right , val ) - nonlocal var_5 - if var_1.val > val : - var_5 = var_1.val if var_5 == - 1 else min ( var_5 , var_1.val ) -",1,1 -1430,0530.Minimum Absolute Difference in BST_1.py,"def dfs(root): - if root is None: - return - dfs(root.left) - nonlocal ans, prev - ans = min(ans, abs(prev - root.val)) - prev = root.val - dfs(root.right)","def sample_funcname ( var_1 ) : - if var_1 is None : - return - var_0 ( var_1.left ) - nonlocal var_4 , var_5 - var_4 = min ( var_4 , abs ( var_5 - var_1.val ) ) - var_5 = var_1.val - var_0 ( var_1.right ) -",None,1 -1431,1002.Find Common Characters_1.py,"def commonChars( words: List[str]) -> List[str]: - freq = [10000] * 26 - for word in words: - t = [0] * 26 - for c in word: - t[ord(c) - ord('a')] += 1 - for i in range(26): - freq[i] = min(freq[i], t[i]) - res = [] - for i in range(26): - if freq[i] > 0: - res.extend([chr(i + ord(""a""))] * freq[i]) - return res","def sample_funcname ( var_0 : List [ str ] ) -> List [ str ] : - var_5 = [ 10000 ] * 26 - for var_6 in var_0 : - var_8 = [ 0 ] * 26 - for var_9 in var_6 : - var_8 [ ord ( var_9 ) - ord ( 'a' ) ] += 1 - for var_14 in range ( 26 ) : - var_5 [ var_14 ] = min ( var_5 [ var_14 ] , var_8 [ var_14 ] ) - var_16 = [ ] - for var_14 in range ( 26 ) : - if var_5 [ var_14 ] > 0 : - var_16.extend ( [ chr ( var_14 + ord ( ""a"" ) ) ] * var_5 [ var_14 ] ) - return var_16 -",0a10000a126,6 -1432,1893.Check if All the Integers in a Range Are Covered_1.py,"def isCovered( ranges: List[List[int]], left: int, right: int) -> bool: - diff = [0] * 52 - for l, r in ranges: - diff[l] += 1 - diff[r + 1] -= 1 - cur = 0 - for i, df in enumerate(diff): - cur += df - if left <= i <= right and cur == 0: - return False - return True","def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : int , var_4 : int ) -> bool : - var_8 = [ 0 ] * 52 - for var_9 , var_10 in var_0 : - var_8 [ var_9 ] += 1 - var_8 [ var_10 + 1 ] -= 1 - var_12 = 0 - for var_14 , var_15 in enumerate ( var_8 ) : - var_12 += var_15 - if var_3 <= var_14 <= var_4 and var_12 == 0 : - return False - return True -",1052,3 -1433,2144.Minimum Cost of Buying Candies With Discount_1.py,"def minimumCost( cost: List[int]) -> int: - cost.sort() - ans, n = 0, len(cost) - for i in range(n - 1, -1, -3): - ans += cost[i] - if i >= 1: - ans += cost[i - 1] - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( ) - var_5 , var_7 = 0 , len ( var_0 ) - for var_11 in range ( var_7 - 1 , - 1 , - 3 ) : - var_5 += var_0 [ var_11 ] - if var_11 >= 1 : - var_5 += var_0 [ var_11 - 1 ] - return var_5 -",130,3 -1434,0599.Minimum Index Sum of Two Lists_1.py,"def findRestaurant( list1: List[str], list2: List[str]) -> List[str]: - ans = [] - mp = {v: i for i, v in enumerate(list2)} - mi = 2000 - for i, v in enumerate(list1): - if v in mp: - t = i + mp[v] - if t < mi: - mi = t - ans = [v] - elif t == mi: - ans.append(v) - return ans","def sample_funcname ( var_0 : List [ str ] , var_3 : List [ str ] ) -> List [ str ] : - var_4 = [ ] - var_8 = { var_5 : var_6 for var_6 , var_5 in enumerate ( var_3 ) } - var_10 = 2000 - for var_6 , var_5 in enumerate ( var_0 ) : - if var_5 in var_8 : - var_11 = var_6 + var_8 [ var_5 ] - if var_11 < var_10 : - var_10 = var_11 - var_4 = [ var_5 ] - elif var_11 == var_10 : - var_4.append ( var_5 ) - return var_4 -",2000,1 -1436,2360.Longest Cycle in a Graph_1.py,"def longestCycle( edges: List[int]) -> int: - n = len(edges) - vis = [False] * n - ans = -1 - for i in range(n): - if vis[i]: - continue - curr = i - cycle = [] - while curr != -1 and not vis[curr]: - vis[curr] = True - cycle.append(curr) - curr = edges[curr] - if curr == -1: - continue - for j, v in enumerate(cycle): - if v == curr: - ans = max(ans, len(cycle) - j) - break - return ans","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - var_6 = [ False ] * var_4 - var_8 = - 1 - for var_10 in range ( var_4 ) : - if var_6 [ var_10 ] : - continue - var_11 = var_10 - var_12 = [ ] - while var_11 != - 1 and not var_6 [ var_11 ] : - var_6 [ var_11 ] = True - var_12.append ( var_11 ) - var_11 = var_0 [ var_11 ] - if var_11 == - 1 : - continue - for var_16 , var_17 in enumerate ( var_12 ) : - if var_17 == var_11 : - var_8 = max ( var_8 , len ( var_12 ) - var_16 ) - break - return var_8 -",1,1 -1437,1528.Shuffle String_1.py,"def restoreString( s: str, indices: List[int]) -> str: - ans = [0] * len(s) - for i, c in enumerate(s): - ans[indices[i]] = c - return ''.join(ans)","def sample_funcname ( var_0 : str , var_2 : List [ int ] ) -> str : - var_7 = [ 0 ] * len ( var_0 ) - for var_9 , var_10 in enumerate ( var_0 ) : - var_7 [ var_2 [ var_9 ] ] = var_10 - return ''.join ( var_7 ) -",0,2 -1438,0066.Plus One_1.py,"def plusOne( digits: List[int]) -> List[int]: - n = len(digits) - for i in range(n - 1, -1, -1): - digits[i] += 1 - digits[i] %= 10 - if digits[i] != 0: - return digits - return [1] + digits","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_4 = len ( var_0 ) - for var_7 in range ( var_4 - 1 , - 1 , - 1 ) : - var_0 [ var_7 ] += 1 - var_0 [ var_7 ] %= 10 - if var_0 [ var_7 ] != 0 : - return var_0 - return [ 1 ] + var_0 -",1010,3 -1439,1859.Sorting the Sentence_1.py,"def sortSentence( s: str) -> str: - words = s.split(' ') - arr = [None] * len(words) - for word in words: - idx = int(word[-1]) - 1 - arr[idx] = word[:-1] - return ' '.join(arr)","def sample_funcname ( var_0 : str ) -> str : - var_4 = var_0.split ( ' ' ) - var_7 = [ None ] * len ( var_4 ) - for var_8 in var_4 : - var_11 = int ( var_8 [ - 1 ] ) - 1 - var_7 [ var_11 ] = var_8 [ : - 1 ] - return ' '.join ( var_7 ) -",1 None,3 -1440,0276.Paint Fence_1.py,"def numWays( n: int, k: int) -> int: - dp = [[0] * 2 for _ in range(n)] - dp[0][0] = k - for i in range(1, n): - dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) * (k - 1) - dp[i][1] = dp[i - 1][0] - return sum(dp[-1])","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_7 = [ [ 0 ] * 2 for var_5 in range ( var_0 ) ] - var_7 [ 0 ] [ 0 ] = var_2 - for var_9 in range ( 1 , var_0 ) : - var_7 [ var_9 ] [ 0 ] = ( var_7 [ var_9 - 1 ] [ 0 ] + var_7 [ var_9 - 1 ] [ 1 ] ) * ( var_2 - 1 ) - var_7 [ var_9 ] [ 1 ] = var_7 [ var_9 - 1 ] [ 0 ] - return sum ( var_7 [ - 1 ] ) -",102,3 -1441,0516.Longest Palindromic Subsequence_1.py,"def longestPalindromeSubseq( s: str) -> int: - n = len(s) - dp = [[0] * n for _ in range(n)] - for i in range(n): - dp[i][i] = 1 - for j in range(1, n): - for i in range(j - 1, -1, -1): - if s[i] == s[j]: - dp[i][j] = dp[i + 1][j - 1] + 2 - else: - dp[i][j] = max(dp[i + 1][j], dp[i][j - 1]) - return dp[0][-1]","def sample_funcname ( var_0 : str ) -> int : - var_4 = len ( var_0 ) - var_8 = [ [ 0 ] * var_4 for var_6 in range ( var_4 ) ] - for var_9 in range ( var_4 ) : - var_8 [ var_9 ] [ var_9 ] = 1 - for var_11 in range ( 1 , var_4 ) : - for var_9 in range ( var_11 - 1 , - 1 , - 1 ) : - if var_0 [ var_9 ] == var_0 [ var_11 ] : - var_8 [ var_9 ] [ var_11 ] = var_8 [ var_9 + 1 ] [ var_11 - 1 ] + 2 - else : - var_8 [ var_9 ] [ var_11 ] = max ( var_8 [ var_9 + 1 ] [ var_11 ] , var_8 [ var_9 ] [ var_11 - 1 ] ) - return var_8 [ 0 ] [ - 1 ] -",102,3 -1442,1123.Lowest Common Ancestor of Deepest Leaves_1.py,"def dfs(root): - if root is None: - return None, 0 - l, d1 = dfs(root.left) - r, d2 = dfs(root.right) - if d1 > d2: - return l, d1 + 1 - if d1 < d2: - return r, d2 + 1 - return root, d1 + 1","def sample_funcname ( var_1 ) : - if var_1 is None : - return None , 0 - var_4 , var_6 = var_0 ( var_1.left ) - var_7 , var_9 = var_0 ( var_1.right ) - if var_6 > var_9 : - return var_4 , var_6 + 1 - if var_6 < var_9 : - return var_7 , var_9 + 1 - return var_1 , var_6 + 1 -",10None,3 -1443,0829.Consecutive Numbers Sum_1.py,"def consecutiveNumbersSum( n: int) -> int: - n <<= 1 - ans, k = 0, 1 - while k * (k + 1) <= n: - if n % k == 0 and (n // k + 1 - k) % 2 == 0: - ans += 1 - k += 1 - return ans","def sample_funcname ( var_0 : int ) -> int : - var_0 <<= 1 - var_4 , var_5 = 0 , 1 - while var_5 * ( var_5 + 1 ) <= var_0 : - if var_0 % var_5 == 0 and ( var_0 // var_5 + 1 - var_5 ) % 2 == 0 : - var_4 += 1 - var_5 += 1 - return var_4 -",102,3 -1444,2400.Number of Ways to Reach a Position After Exactly k Steps_1.py,"def dfs(d, k): - if k < 0 or abs(d) > k: - return 0 - if k == 0: - return d == 0 - res = dfs(d - 1, k - 1) + dfs(d + 1, k - 1) - return res % (10**9 + 7)","def sample_funcname ( var_1 , var_2 ) : - if var_2 < 0 or abs ( var_1 ) > var_2 : - return 0 - if var_2 == 0 : - return var_1 == 0 - var_6 = var_0 ( var_1 - 1 , var_2 - 1 ) + var_0 ( var_1 + 1 , var_2 - 1 ) - return var_6 % ( 10 ** 9 + 7 ) -",100179,5 -1445,0462.Minimum Moves to Equal Array Elements II_1.py,"def minMoves2( nums: List[int]) -> int: - nums.sort() - k = nums[len(nums) >> 1] - return sum(abs(v - k) for v in nums)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_0.sort ( ) - var_6 = var_0 [ len ( var_0 ) >> 1 ] - return sum ( abs ( var_9 - var_6 ) for var_9 in var_0 ) -",1,1 -1446,0198.House Robber_1.py,"def rob( nums: List[int]) -> int: - a, b = 0, nums[0] - for num in nums[1:]: - a, b = b, max(num + a, b) - return b","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 , var_5 = 0 , var_0 [ 0 ] - for var_7 in var_0 [ 1 : ] : - var_4 , var_5 = var_5 , max ( var_7 + var_4 , var_5 ) - return var_5 -",10,2 -1447,0228.Summary Ranges_1.py,"def make(nums, i, j): - return str(nums[i]) if i == j else f'{nums[i]}->{nums[j]}'","def sample_funcname ( var_0 , var_1 , var_2 ) : - return str ( var_0 [ var_1 ] ) if var_1 == var_2 else f'{var_0[var_1]}->{var_0[var_2]}' -",f{var_0[var_1]}->{var_0[var_2]},1 -1448,0598.Range Addition II_1.py,"def maxCount( m: int, n: int, ops: List[List[int]]) -> int: - for a, b in ops: - m = min(m, a) - n = min(n, b) - return m * n","def sample_funcname ( var_0 : int , var_2 : int , var_3 : List [ List [ int ] ] ) -> int : - for var_5 , var_6 in var_3 : - var_0 = min ( var_0 , var_5 ) - var_2 = min ( var_2 , var_6 ) - return var_0 * var_2 -",,0 -1449,2295.Replace Elements in an Array_1.py,"def arrayChange( nums: List[int], operations: List[List[int]]) -> List[int]: - d = {v: i for i, v in enumerate(nums)} - for a, b in operations: - idx = d[a] - d.pop(a) - d[b] = idx - ans = [0] * len(nums) - for v, i in d.items(): - ans[i] = v - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ List [ int ] ] ) -> List [ int ] : - var_7 = { var_4 : var_5 for var_5 , var_4 in enumerate ( var_0 ) } - for var_8 , var_9 in var_3 : - var_10 = var_7 [ var_8 ] - var_7.pop ( var_8 ) - var_7 [ var_9 ] = var_10 - var_14 = [ 0 ] * len ( var_0 ) - for var_4 , var_5 in var_7.items ( ) : - var_14 [ var_5 ] = var_4 - return var_14 -",0,1 -1450,2330.Valid Palindrome IV_1.py,"def makePalindrome( s: str) -> bool: - i, j = 0, len(s) - 1 - t = 0 - while i < j: - if s[i] != s[j]: - t += 1 - i, j = i + 1, j - 1 - return t <= 2","def sample_funcname ( var_0 : str ) -> bool : - var_4 , var_7 = 0 , len ( var_0 ) - 1 - var_8 = 0 - while var_4 < var_7 : - if var_0 [ var_4 ] != var_0 [ var_7 ] : - var_8 += 1 - var_4 , var_7 = var_4 + 1 , var_7 - 1 - return var_8 <= 2 -",102,3 -1451,0723.Candy Crush_1.py,"def candyCrush( board: List[List[int]]) -> List[List[int]]: - m, n = len(board), len(board[0]) - run = True - while run: - run = False - for i in range(m): - for j in range(n - 2): - if ( - board[i][j] != 0 - and abs(board[i][j]) == abs(board[i][j + 1]) - and abs(board[i][j]) == abs(board[i][j + 2]) - ): - run = True - board[i][j] = board[i][j + 1] = board[i][j + 2] = -abs( - board[i][j] - ) - for j in range(n): - for i in range(m - 2): - if ( - board[i][j] != 0 - and abs(board[i][j]) == abs(board[i + 1][j]) - and abs(board[i][j]) == abs(board[i + 2][j]) - ): - run = True - board[i][j] = board[i + 1][j] = board[i + 2][j] = -abs( - board[i][j] - ) - if run: - for j in range(n): - curr = m - 1 - for i in range(m - 1, -1, -1): - if board[i][j] > 0: - board[curr][j] = board[i][j] - curr -= 1 - while curr > -1: - board[curr][j] = 0 - curr -= 1 - return board","def sample_funcname ( var_0 : List [ List [ int ] ] ) -> List [ List [ int ] ] : - var_4 , var_6 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_8 = True - while var_8 : - var_8 = False - for var_11 in range ( var_4 ) : - for var_13 in range ( var_6 - 2 ) : - if ( var_0 [ var_11 ] [ var_13 ] != 0 and abs ( var_0 [ var_11 ] [ var_13 ] ) == abs ( var_0 [ var_11 ] [ var_13 + 1 ] ) and abs ( var_0 [ var_11 ] [ var_13 ] ) == abs ( var_0 [ var_11 ] [ var_13 + 2 ] ) ) : - var_8 = True - var_0 [ var_11 ] [ var_13 ] = var_0 [ var_11 ] [ var_13 + 1 ] = var_0 [ var_11 ] [ var_13 + 2 ] = - abs ( var_0 [ var_11 ] [ var_13 ] ) - for var_13 in range ( var_6 ) : - for var_11 in range ( var_4 - 2 ) : - if ( var_0 [ var_11 ] [ var_13 ] != 0 and abs ( var_0 [ var_11 ] [ var_13 ] ) == abs ( var_0 [ var_11 + 1 ] [ var_13 ] ) and abs ( var_0 [ var_11 ] [ var_13 ] ) == abs ( var_0 [ var_11 + 2 ] [ var_13 ] ) ) : - var_8 = True - var_0 [ var_11 ] [ var_13 ] = var_0 [ var_11 + 1 ] [ var_13 ] = var_0 [ var_11 + 2 ] [ var_13 ] = - abs ( var_0 [ var_11 ] [ var_13 ] ) - if var_8 : - for var_13 in range ( var_6 ) : - var_16 = var_4 - 1 - for var_11 in range ( var_4 - 1 , - 1 , - 1 ) : - if var_0 [ var_11 ] [ var_13 ] > 0 : - var_0 [ var_16 ] [ var_13 ] = var_0 [ var_11 ] [ var_13 ] - var_16 -= 1 - while var_16 > - 1 : - var_0 [ var_16 ] [ var_13 ] = 0 - var_16 -= 1 - return var_0 -",102,3 -1452,1652.Defuse the Bomb_1.py,"def decrypt( code: List[int], k: int) -> List[int]: - n = len(code) - res = [0] * n - if k == 0: - return res - for i in range(n): - if k > 0: - for j in range(i + 1, i + k + 1): - res[i] += code[j % n] - else: - for j in range(i + k, i): - res[i] += code[(j + n) % n] - return res","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_5 = len ( var_0 ) - var_7 = [ 0 ] * var_5 - if var_3 == 0 : - return var_7 - for var_9 in range ( var_5 ) : - if var_3 > 0 : - for var_11 in range ( var_9 + 1 , var_9 + var_3 + 1 ) : - var_7 [ var_9 ] += var_0 [ var_11 % var_5 ] - else : - for var_11 in range ( var_9 + var_3 , var_9 ) : - var_7 [ var_9 ] += var_0 [ ( var_11 + var_5 ) % var_5 ] - return var_7 -",10,2 -1453,1287.Element Appearing More Than 25% In Sorted Array_1.py,"def findSpecialInteger( arr: List[int]) -> int: - n = len(arr) - for i, val in enumerate(arr): - if val == arr[i + (n >> 2)]: - return val - return 0","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = len ( var_0 ) - for var_6 , var_7 in enumerate ( var_0 ) : - if var_7 == var_0 [ var_6 + ( var_4 >> 2 ) ] : - return var_7 - return 0 -",02,2 -1454,0367.Valid Perfect Square_1.py,"def isPerfectSquare( num: int) -> bool: - left, right = 1, num - while left < right: - mid = (left + right) >> 1 - if mid * mid >= num: - right = mid - else: - left = mid + 1 - return left * left == num","def sample_funcname ( var_0 : int ) -> bool : - var_4 , var_5 = 1 , var_0 - while var_4 < var_5 : - var_6 = ( var_4 + var_5 ) >> 1 - if var_6 * var_6 >= var_0 : - var_5 = var_6 - else : - var_4 = var_6 + 1 - return var_4 * var_4 == var_0 -",1,1 -1455,0793.Preimage Size of Factorial Zeroes Function_1.py,"def f(x): - if x == 0: - return 0 - return x // 5 + f(x // 5)","def sample_funcname ( var_1 ) : - if var_1 == 0 : - return 0 - return var_1 // 5 + var_0 ( var_1 // 5 ) -",50,2 -1456,1558.Minimum Numbers of Function Calls to Make Target Array_1.py,"def minOperations( nums: List[int]) -> int: - return sum(v.bit_count() for v in nums) + max(0, max(nums).bit_length() - 1)","def sample_funcname ( var_0 : List [ int ] ) -> int : - return sum ( var_4.bit_count ( ) for var_4 in var_0 ) + max ( 0 , max ( var_0 ).bit_length ( ) - 1 ) -",10,2 -1457,1431.Kids With the Greatest Number of Candies_1.py,"def kidsWithCandies( candies: List[int], extraCandies: int) -> List[bool]: - mx = max(candies) - return [candy + extraCandies >= mx for candy in candies]","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ bool ] : - var_6 = max ( var_0 ) - return [ var_7 + var_3 >= var_6 for var_7 in var_0 ] -",,0 -1458,1935.Maximum Number of Words You Can Type_1.py,"def canBeTypedWords( text: str, brokenLetters: str) -> int: - letters = set(brokenLetters) - res = 0 - for word in text.split(): - find = False - for letter in letters: - if letter in word: - find = True - break - if not find: - res += 1 - return res","def sample_funcname ( var_0 : str , var_2 : str ) -> int : - var_5 = set ( var_2 ) - var_7 = 0 - for var_9 in var_0.split ( ) : - var_11 = False - for var_12 in var_5 : - if var_12 in var_9 : - var_11 = True - break - if not var_11 : - var_7 += 1 - return var_7 -",10,2 -1459,0258.Add Digits_1.py,"def addDigits( num: int) -> int: - return 0 if num == 0 else (num - 1) % 9 + 1","def sample_funcname ( var_0 : int ) -> int : - return 0 if var_0 == 0 else ( var_0 - 1 ) % 9 + 1 -",109,3 -1460,2191.Sort the Jumbled Numbers_1.py,"def sortJumbled( mapping: List[int], nums: List[int]) -> List[int]: - m = [] - for i, v in enumerate(nums): - a, b, t = v, 0, 1 - while 1: - a, x = divmod(a, 10) - x = mapping[x] - b = x * t + b - t *= 10 - if a == 0: - break - m.append((b, i, v)) - m.sort() - for i, v in enumerate(m): - nums[i] = v[2] - return nums","def sample_funcname ( var_0 : List [ int ] , var_3 : List [ int ] ) -> List [ int ] : - var_4 = [ ] - for var_6 , var_7 in enumerate ( var_3 ) : - var_8 , var_10 , var_12 = var_7 , 0 , 1 - while 1 : - var_8 , var_15 = divmod ( var_8 , 10 ) - var_15 = var_0 [ var_15 ] - var_10 = var_15 * var_12 + var_10 - var_12 *= 10 - if var_8 == 0 : - break - var_4.append ( ( var_10 , var_6 , var_7 ) ) - var_4.sort ( ) - for var_6 , var_7 in enumerate ( var_4 ) : - var_3 [ var_6 ] = var_7 [ 2 ] - return var_3 -",10102,4 -1461,1134.Armstrong Number_1.py,"def isArmstrong( n: int) -> bool: - k = len(str(n)) - s, t = 0, n - while t: - t, v = divmod(t, 10) - s += pow(v, k) - return n == s","def sample_funcname ( var_0 : int ) -> bool : - var_5 = len ( str ( var_0 ) ) - var_7 , var_8 = 0 , var_0 - while var_8 : - var_8 , var_11 = divmod ( var_8 , 10 ) - var_7 += pow ( var_11 , var_5 ) - return var_0 == var_7 -",100,2 -1462,1562.Find Latest Group of Size M_1.py,"def findLatestStep( arr: List[int], m: int) -> int: - n = len(arr) - if m == n: - return n - cnt = [0] * (n + 2) - ans = -1 - for i, v in enumerate(arr): - v -= 1 - l, r = cnt[v - 1], cnt[v + 1] - if l == m or r == m: - ans = i - cnt[v - l] = cnt[v + r] = l + r + 1 - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - var_5 = len ( var_0 ) - if var_3 == var_5 : - return var_5 - var_8 = [ 0 ] * ( var_5 + 2 ) - var_10 = - 1 - for var_12 , var_13 in enumerate ( var_0 ) : - var_13 -= 1 - var_14 , var_15 = var_8 [ var_13 - 1 ] , var_8 [ var_13 + 1 ] - if var_14 == var_3 or var_15 == var_3 : - var_10 = var_12 - var_8 [ var_13 - var_14 ] = var_8 [ var_13 + var_15 ] = var_14 + var_15 + 1 - return var_10 -",102,3 -1463,2179.Count Good Triplets in an Array_1.py,"def lowbit(x): - return x & -x","def sample_funcname ( var_0 ) : - return var_0 & - var_0 -",,0 -1464,0449.Serialize and Deserialize BST_1.py,"def dfs(root): - if root is None: - return - nonlocal t - t.append(str(root.val)) - t.append(',') - dfs(root.left) - dfs(root.right)","def sample_funcname ( var_1 ) : - if var_1 is None : - return - nonlocal var_3 - var_3.append ( str ( var_1.val ) ) - var_3.append ( ',' ) - var_0 ( var_1.left ) - var_0 ( var_1.right ) -",",None",2 -1465,1539.Kth Missing Positive Number_1.py,"def findKthPositive( arr: List[int], k: int) -> int: - if arr[0] > k: - return k - left, right = 0, len(arr) - while left < right: - mid = (left + right) >> 1 - if arr[mid] - mid - 1 >= k: - right = mid - else: - left = mid + 1 - return arr[left - 1] + k - (arr[left - 1] - (left - 1) - 1)","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> int : - if var_0 [ 0 ] > var_3 : - return var_3 - var_5 , var_7 = 0 , len ( var_0 ) - while var_5 < var_7 : - var_9 = ( var_5 + var_7 ) >> 1 - if var_0 [ var_9 ] - var_9 - 1 >= var_3 : - var_7 = var_9 - else : - var_5 = var_9 + 1 - return var_0 [ var_5 - 1 ] + var_3 - ( var_0 [ var_5 - 1 ] - ( var_5 - 1 ) - 1 ) -",10,2 -1466,1720.Decode XORed Array_1.py,"def decode( encoded: List[int], first: int) -> List[int]: - ans = [first] - for e in encoded: - ans.append(ans[-1] ^ e) - return ans","def sample_funcname ( var_0 : List [ int ] , var_3 : int ) -> List [ int ] : - var_4 = [ var_3 ] - for var_5 in var_0 : - var_4.append ( var_4 [ - 1 ] ^ var_5 ) - return var_4 -",1,1 -1467,1844.Replace All Digits with Characters_1.py,"def replaceDigits( s: str) -> str: - s = list(s) - for i in range(1, len(s), 2): - s[i] = chr(ord(s[i - 1]) + int(s[i])) - return ''.join(s)","def sample_funcname ( var_0 : str ) -> str : - var_0 = list ( var_0 ) - for var_7 in range ( 1 , len ( var_0 ) , 2 ) : - var_0 [ var_7 ] = chr ( ord ( var_0 [ var_7 - 1 ] ) + int ( var_0 [ var_7 ] ) ) - return ''.join ( var_0 ) -",12,3 -1468,1426.Counting Elements_1.py,"def countElements( arr: List[int]) -> int: - s = set(arr) - return sum(x + 1 in s for x in arr)","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = set ( var_0 ) - return sum ( var_6 + 1 in var_4 for var_6 in var_0 ) -",1,1 -1469,2011.Final Value of Variable After Performing Operations_1.py,"def finalValueAfterOperations( operations: List[str]) -> int: - return sum(1 if s[1] == '+' else -1 for s in operations)","def sample_funcname ( var_0 : List [ str ] ) -> int : - return sum ( 1 if var_6 [ 1 ] == '+' else - 1 for var_6 in var_0 ) -",1+,2 -1470,1419.Minimum Number of Frogs Croaking_1.py,"def minNumberOfFrogs( croakOfFrogs: str) -> int: - c = r = o = a = k = ans = 0 - for ch in croakOfFrogs: - if ch == 'c': - c += 1 - if k > 0: - k -= 1 - else: - ans += 1 - elif ch == 'r': - r += 1 - c -= 1 - elif ch == 'o': - o += 1 - r -= 1 - elif ch == 'a': - a += 1 - o -= 1 - else: - k += 1 - a -= 1 - if c < 0 or r < 0 or o < 0 or a < 0: - return -1 - return -1 if c != 0 or r != 0 or o != 0 or a != 0 else ans","def sample_funcname ( var_0 : str ) -> int : - var_9 = var_3 = var_4 = var_5 = var_6 = var_7 = 0 - for var_10 in var_0 : - if var_10 == 'c' : - var_9 += 1 - if var_6 > 0 : - var_6 -= 1 - else : - var_7 += 1 - elif var_10 == 'r' : - var_3 += 1 - var_9 -= 1 - elif var_10 == 'o' : - var_4 += 1 - var_3 -= 1 - elif var_10 == 'a' : - var_5 += 1 - var_4 -= 1 - else : - var_6 += 1 - var_5 -= 1 - if var_9 < 0 or var_3 < 0 or var_4 < 0 or var_5 < 0 : - return - 1 - return - 1 if var_9 != 0 or var_3 != 0 or var_4 != 0 or var_5 != 0 else var_7 -",0ac1or,6 -1471,0059.Spiral Matrix II_1.py,"def generateMatrix( n: int) -> List[List[int]]: - res = [[0] * n for _ in range(n)] - num = 1 - m1, m2 = 0, n - 1 - while m1 < m2: - for j in range(m1, m2): - res[m1][j] = num - num += 1 - for i in range(m1, m2): - res[i][m2] = num - num += 1 - for j in range(m2, m1, -1): - res[m2][j] = num - num += 1 - for i in range(m2, m1, -1): - res[i][m1] = num - num += 1 - m1 += 1 - m2 -= 1 - if m1 == m2: - res[m1][m1] = num - return res","def sample_funcname ( var_0 : int ) -> List [ List [ int ] ] : - var_6 = [ [ 0 ] * var_0 for var_4 in range ( var_0 ) ] - var_8 = 1 - var_9 , var_10 = 0 , var_0 - 1 - while var_9 < var_10 : - for var_11 in range ( var_9 , var_10 ) : - var_6 [ var_9 ] [ var_11 ] = var_8 - var_8 += 1 - for var_12 in range ( var_9 , var_10 ) : - var_6 [ var_12 ] [ var_10 ] = var_8 - var_8 += 1 - for var_11 in range ( var_10 , var_9 , - 1 ) : - var_6 [ var_10 ] [ var_11 ] = var_8 - var_8 += 1 - for var_12 in range ( var_10 , var_9 , - 1 ) : - var_6 [ var_12 ] [ var_9 ] = var_8 - var_8 += 1 - var_9 += 1 - var_10 -= 1 - if var_9 == var_10 : - var_6 [ var_9 ] [ var_9 ] = var_8 - return var_6 -",10,2 -1472,0419.Battleships in a Board_1.py,"def countBattleships( board: List[List[str]]) -> int: - m, n = len(board), len(board[0]) - ans = 0 - for i in range(m): - for j in range(n): - if board[i][j] == '.': - continue - if i > 0 and board[i - 1][j] == 'X': - continue - if j > 0 and board[i][j - 1] == 'X': - continue - ans += 1 - return ans","def sample_funcname ( var_0 : List [ List [ str ] ] ) -> int : - var_5 , var_7 = len ( var_0 ) , len ( var_0 [ 0 ] ) - var_8 = 0 - for var_10 in range ( var_5 ) : - for var_11 in range ( var_7 ) : - if var_0 [ var_10 ] [ var_11 ] == '.' : - continue - if var_10 > 0 and var_0 [ var_10 - 1 ] [ var_11 ] == 'X' : - continue - if var_11 > 0 and var_0 [ var_10 ] [ var_11 - 1 ] == 'X' : - continue - var_8 += 1 - return var_8 -",10.X,4 -1473,1822.Sign of the Product of an Array_1.py,"def arraySign( nums: List[int]) -> int: - res = 1 - for num in nums: - if num == 0: - return 0 - if num < 0: - res *= -1 - return res","def sample_funcname ( var_0 : List [ int ] ) -> int : - var_4 = 1 - for var_5 in var_0 : - if var_5 == 0 : - return 0 - if var_5 < 0 : - var_4 *= - 1 - return var_4 -",10,2 -1474,0318.Maximum Product of Word Lengths_1.py,"def maxProduct( words: List[str]) -> int: - n = len(words) - mask = [0] * n - for i, word in enumerate(words): - for ch in word: - mask[i] |= 1 << (ord(ch) - ord('a')) - ans = 0 - for i in range(n - 1): - for j in range(i + 1, n): - if mask[i] & mask[j] == 0: - ans = max(ans, len(words[i]) * len(words[j])) - return ans","def sample_funcname ( var_0 : List [ str ] ) -> int : - var_5 = len ( var_0 ) - var_7 = [ 0 ] * var_5 - for var_9 , var_10 in enumerate ( var_0 ) : - for var_11 in var_10 : - var_7 [ var_9 ] |= 1 << ( ord ( var_11 ) - ord ( 'a' ) ) - var_15 = 0 - for var_9 in range ( var_5 - 1 ) : - for var_17 in range ( var_9 + 1 , var_5 ) : - if var_7 [ var_9 ] & var_7 [ var_17 ] == 0 : - var_15 = max ( var_15 , len ( var_0 [ var_9 ] ) * len ( var_0 [ var_17 ] ) ) - return var_15 -",10a,3 -1475,0720.Longest Word in Dictionary_1.py,"def longestWord( words: List[str]) -> str: - cnt, ans = 0, '' - s = set(words) - for w in s: - n = len(w) - if all(w[:i] in s for i in range(1, n)): - if cnt < n: - cnt, ans = n, w - elif cnt == n and w < ans: - ans = w - return ans","def sample_funcname ( var_0 : List [ str ] ) -> str : - var_4 , var_6 = 0 , '' - var_8 = set ( var_0 ) - for var_9 in var_8 : - var_11 = len ( var_9 ) - if all ( var_9 [ : var_13 ] in var_8 for var_13 in range ( 1 , var_11 ) ) : - if var_4 < var_11 : - var_4 , var_6 = var_11 , var_9 - elif var_4 == var_11 and var_9 < var_6 : - var_6 = var_9 - return var_6 -",10,3 -1476,1356.Sort Integers by The Number of 1 Bits_1.py,"def sortByBits( arr: List[int]) -> List[int]: - arr.sort(key=lambda x: (x.bit_count(), x)) - return arr","def sample_funcname ( var_0 : List [ int ] ) -> List [ int ] : - var_0.sort ( var_4 = lambda var_5 : ( var_5.bit_count ( ) , var_5 ) ) - return var_0 -",,0 -1477,1486.XOR Operation in an Array_1.py,"def xorOperation( n: int, start: int) -> int: - res = 0 - for i in range(n): - res ^= start + (i << 1) - return res","def sample_funcname ( var_0 : int , var_2 : int ) -> int : - var_4 = 0 - for var_6 in range ( var_0 ) : - var_4 ^= var_2 + ( var_6 << 1 ) - return var_4 -",10,2 -1478,1945.Sum of Digits of String After Convert_1.py,"def getLucky( s: str, k: int) -> int: - s = ''.join([str(ord(c) - ord('a') + 1) for c in s]) - for _ in range(k): - t = 0 - for c in s: - t += ord(c) - ord('0') - s = str(t) - return int(s)","def sample_funcname ( var_0 : str , var_2 : int ) -> int : - var_0 = ''.join ( [ str ( ord ( var_7 ) - ord ( 'a' ) + 1 ) for var_7 in var_0 ] ) - for var_11 in range ( var_2 ) : - var_13 = 0 - for var_7 in var_0 : - var_13 += ord ( var_7 ) - ord ( '0' ) - var_0 = str ( var_13 ) - return int ( var_0 ) -",0a01,5 -1479,1641.Count Sorted Vowel Strings_1.py,"def countVowelStrings( n: int) -> int: - cnt = [1] * 5 - for i in range(2, n + 1): - for j in range(3, -1, -1): - cnt[j] += cnt[j + 1] - return sum(cnt)","def sample_funcname ( var_0 : int ) -> int : - var_4 = [ 1 ] * 5 - for var_7 in range ( 2 , var_0 + 1 ) : - for var_9 in range ( 3 , - 1 , - 1 ) : - var_4 [ var_9 ] += var_4 [ var_9 + 1 ] - return sum ( var_4 ) -",5312,4 -1480,0241.Different Ways to Add Parentheses_1.py,"def dfs(exp): - if exp.isdigit(): - return [int(exp)] - ans = [] - for i, c in enumerate(exp): - if c in '-+*': - left, right = dfs(exp[:i]), dfs(exp[i + 1 :]) - for a in left: - for b in right: - if c == '-': - ans.append(a - b) - elif c == '+': - ans.append(a + b) - else: - ans.append(a * b) - return ans","def sample_funcname ( var_1 ) : - if var_1.isdigit ( ) : - return [ int ( var_1 ) ] - var_4 = [ ] - for var_6 , var_7 in enumerate ( var_1 ) : - if var_7 in '-+*' : - var_9 , var_11 = var_0 ( var_1 [ : var_6 ] ) , var_0 ( var_1 [ var_6 + 1 : ] ) - for var_12 in var_9 : - for var_13 in var_11 : - if var_7 == '-' : - var_4.append ( var_12 - var_13 ) - elif var_7 == '+' : - var_4.append ( var_12 + var_13 ) - else : - var_4.append ( var_12 * var_13 ) - return var_4 -",1-+*+-,4