ShwStone/humaneval-leetcode huggingface dataset:
def circularArrayLoop(nums: List[int]) -> bool:
    """
    You are playing a game involving a circular array of non-zero integers nums. Each nums[i] denotes the number of indices forward/backward you must move if you are located at index i:
    
    If nums[i] is positive, move nums[i] steps forward, and
    If nums[i] is negative, move nums[i] steps backward.
    
    Since the array is circular, you may assume that moving forward from the last element puts you on the first element, and moving backwards from the first element puts you on the last element.
    A cycle in the array consists of a sequence of indices seq of length k where:
    
    Following the movement rules above results in the repeating index sequence seq[0] -> seq[1] -> ... -> seq[k - 1] -> seq[0] -> ...
    Every nums[seq[j]] is either all positive or all negative.
    k > 1
    
    Return true if there is a cycle in nums, or false otherwise.
    
    Example 1:
    
    
    >>> circularArrayLoop(nums = [2,-1,1,2,2])
    >>> true
    Explanation: The graph shows how the indices are connected. White nodes are jumping forward, while red is jumping backward.
    We can see the cycle 0 --> 2 --> 3 --> 0 --> ..., and all of its nodes are white (jumping in the same direction).
    
    Example 2:
    
    
    >>> circularArrayLoop(nums = [-1,-2,-3,-4,-5,6])
    >>> false
    Explanation: The graph shows how the indices are connected. White nodes are jumping forward, while red is jumping backward.
    The only cycle is of size 1, so we return false.
    
    Example 3:
    
    
    >>> circularArrayLoop(nums = [1,-1,5,1,4])
    >>> true
    Explanation: The graph shows how the indices are connected. White nodes are jumping forward, while red is jumping backward.
    We can see the cycle 0 --> 1 --> 0 --> ..., and while it is of size > 1, it has a node jumping forward and a node jumping backward, so it is not a cycle.
    We can see the cycle 3 --> 4 --> 3 --> ..., and all of its nodes are white (jumping in the same direction).
    """
def poorPigs(buckets: int, minutesToDie: int, minutesToTest: int) -> int:
    """
    There are buckets buckets of liquid, where exactly one of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have minutesToTest minutes to determine which bucket is poisonous.
    You can feed the pigs according to these steps:
    
    Choose some live pigs to feed.
    For each pig, choose which buckets to feed it. The pig will consume all the chosen buckets simultaneously and will take no time. Each pig can feed from any number of buckets, and each bucket can be fed from by any number of pigs.
    Wait for minutesToDie minutes. You may not feed any other pigs during this time.
    After minutesToDie minutes have passed, any pigs that have been fed the poisonous bucket will die, and all others will survive.
    Repeat this process until you run out of time.
    
    Given buckets, minutesToDie, and minutesToTest, return the minimum number of pigs needed to figure out which bucket is poisonous within the allotted time.
    
    Example 1:
    
    >>> poorPigs(buckets = 4, minutesToDie = 15, minutesToTest = 15)
    >>> 2
    Explanation: We can determine the poisonous bucket as follows:
    At time 0, feed the first pig buckets 1 and 2, and feed the second pig buckets 2 and 3.
    At time 15, there are 4 possible outcomes:
    - If only the first pig dies, then bucket 1 must be poisonous.
    - If only the second pig dies, then bucket 3 must be poisonous.
    - If both pigs die, then bucket 2 must be poisonous.
    - If neither pig dies, then bucket 4 must be poisonous.
    
    Example 2:
    
    >>> poorPigs(buckets = 4, minutesToDie = 15, minutesToTest = 30)
    >>> 2
    Explanation: We can determine the poisonous bucket as follows:
    At time 0, feed the first pig bucket 1, and feed the second pig bucket 2.
    At time 15, there are 2 possible outcomes:
    - If either pig dies, then the poisonous bucket is the one it was fed.
    - If neither pig dies, then feed the first pig bucket 3, and feed the second pig bucket 4.
    At time 30, one of the two pigs must die, and the poisonous bucket is the one it was fed.
    """
def repeatedSubstringPattern(s: str) -> bool:
    """
    Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.
    
    Example 1:
    
    >>> repeatedSubstringPattern(s = "abab")
    >>> true
    Explanation: It is the substring "ab" twice.
    
    Example 2:
    
    >>> repeatedSubstringPattern(s = "aba")
    >>> false
    
    Example 3:
    
    >>> repeatedSubstringPattern(s = "abcabcabcabc")
    >>> true
    Explanation: It is the substring "abc" four times or the substring "abcabc" twice.
    """
def hammingDistance(x: int, y: int) -> int:
    """
    The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
    Given two integers x and y, return the Hamming distance between them.
    
    Example 1:
    
    >>> hammingDistance(x = 1, y = 4)
    >>> 2
    Explanation:
    1   (0 0 0 1)
    4   (0 1 0 0)
           ↑   ↑
    The above arrows point to positions where the corresponding bits are different.
    
    Example 2:
    
    >>> hammingDistance(x = 3, y = 1)
    >>> 1
    """
def minMoves2(nums: List[int]) -> int:
    """
    Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal.
    In one move, you can increment or decrement an element of the array by 1.
    Test cases are designed so that the answer will fit in a 32-bit integer.
    
    Example 1:
    
    >>> minMoves2(nums = [1,2,3])
    >>> 2
    Explanation:
    Only two moves are needed (remember each move increments or decrements one element):
    [1,2,3]  =>  [2,2,3]  =>  [2,2,2]
    
    Example 2:
    
    >>> minMoves2(nums = [1,10,2,9])
    >>> 16
    """
def islandPerimeter(grid: List[List[int]]) -> int:
    """
    You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water.
    Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).
    The island doesn't have "lakes", meaning the water inside isn't connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.
    
    Example 1:
    
    
    >>> islandPerimeter(grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]])
    >>> 16
    Explanation: The perimeter is the 16 yellow stripes in the image above.
    
    Example 2:
    
    >>> islandPerimeter(grid = [[1]])
    >>> 4
    
    Example 3:
    
    >>> islandPerimeter(grid = [[1,0]])
    >>> 4
    """
def canIWin(maxChoosableInteger: int, desiredTotal: int) -> bool:
    """
    In the "100 game" two players take turns adding, to a running total, any integer from 1 to 10. The player who first causes the running total to reach or exceed 100 wins.
    What if we change the game so that players cannot re-use integers?
    For example, two players might take turns drawing from a common pool of numbers from 1 to 15 without replacement until they reach a total >= 100.
    Given two integers maxChoosableInteger and desiredTotal, return true if the first player to move can force a win, otherwise, return false. Assume both players play optimally.
    
    Example 1:
    
    >>> canIWin(maxChoosableInteger = 10, desiredTotal = 11)
    >>> false
    Explanation:
    No matter which integer the first player choose, the first player will lose.
    The first player can choose an integer from 1 up to 10.
    If the first player choose 1, the second player can only choose integers from 2 up to 10.
    The second player will win by choosing 10 and get a total = 11, which is >= desiredTotal.
    Same with other integers chosen by the first player, the second player will always win.
    
    Example 2:
    
    >>> canIWin(maxChoosableInteger = 10, desiredTotal = 0)
    >>> true
    
    Example 3:
    
    >>> canIWin(maxChoosableInteger = 10, desiredTotal = 1)
    >>> true
    """
def minTransfers(transactions: List[List[int]]) -> int:
    """
    You are given an array of transactions transactions where transactions[i] = [fromi, toi, amounti] indicates that the person with ID = fromi gave amounti $ to the person with ID = toi.
    Return the minimum number of transactions required to settle the debt.
    
    Example 1:
    
    >>> minTransfers(transactions = [[0,1,10],[2,0,5]])
    >>> 2
    Explanation:
    Person #0 gave person #1 $10.
    Person #2 gave person #0 $5.
    Two transactions are needed. One way to settle the debt is person #1 pays person #0 and #2 $5 each.
    
    Example 2:
    
    >>> minTransfers(transactions = [[0,1,10],[1,0,1],[1,2,5],[2,0,5]])
    >>> 1
    Explanation:
    Person #0 gave person #1 $10.
    Person #1 gave person #0 $1.
    Person #1 gave person #2 $5.
    Person #2 gave person #0 $5.
    Therefore, person #1 only need to give person #0 $4, and all debt is settled.
    """
def getMaxRepetitions(s1: str, n1: int, s2: str, n2: int) -> int:
    """
    We define str = [s, n] as the string str which consists of the string s concatenated n times.
    
    For example, str == ["abc", 3] =="abcabcabc".
    
    We define that string s1 can be obtained from string s2 if we can remove some characters from s2 such that it becomes s1.
    
    For example, s1 = "abc" can be obtained from s2 = "abdbec" based on our definition by removing the bolded underlined characters.
    
    You are given two strings s1 and s2 and two integers n1 and n2. You have the two strings str1 = [s1, n1] and str2 = [s2, n2].
    Return the maximum integer m such that str = [str2, m] can be obtained from str1.
    
    Example 1:
    >>> getMaxRepetitions(s1 = "acb", n1 = 4, s2 = "ab", n2 = 2)
    >>> 2
    Example 2:
    >>> getMaxRepetitions(s1 = "acb", n1 = 1, s2 = "acb", n2 = 1)
    >>> 1
    """
def findSubstringInWraproundString(s: str) -> int:
    """
    We define the string base to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so base will look like this:
    
    "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".
    
    Given a string s, return the number of unique non-empty substrings of s are present in base.
    
    Example 1:
    
    >>> findSubstringInWraproundString(s = "a")
    >>> 1
    Explanation: Only the substring "a" of s is in base.
    
    Example 2:
    
    >>> findSubstringInWraproundString(s = "cac")
    >>> 2
    Explanation: There are two substrings ("a", "c") of s in base.
    
    Example 3:
    
    >>> findSubstringInWraproundString(s = "zab")
    >>> 6
    Explanation: There are six substrings ("z", "a", "b", "za", "ab", and "zab") of s in base.
    """
def validIPAddress(queryIP: str) -> str:
    """
    Given a string queryIP, return "IPv4" if IP is a valid IPv4 address, "IPv6" if IP is a valid IPv6 address or "Neither" if IP is not a correct IP of any type.
    A valid IPv4 address is an IP in the form "x1.x2.x3.x4" where 0 <= xi <= 255 and xi cannot contain leading zeros. For example, "192.168.1.1" and "192.168.1.0" are valid IPv4 addresses while "192.168.01.1", "192.168.1.00", and "192.168@1.1" are invalid IPv4 addresses.
    A valid IPv6 address is an IP in the form "x1:x2:x3:x4:x5:x6:x7:x8" where:
    
    1 <= xi.length <= 4
    xi is a hexadecimal string which may contain digits, lowercase English letter ('a' to 'f') and upper-case English letters ('A' to 'F').
    Leading zeros are allowed in xi.
    
    For example, "2001:0db8:85a3:0000:0000:8a2e:0370:7334" and "2001:db8:85a3:0:0:8A2E:0370:7334" are valid IPv6 addresses, while "2001:0db8:85a3::8A2E:037j:7334" and "02001:0db8:85a3:0000:0000:8a2e:0370:7334" are invalid IPv6 addresses.
    
    Example 1:
    
    >>> validIPAddress(queryIP = "172.16.254.1")
    >>> "IPv4"
    Explanation: This is a valid IPv4 address, return "IPv4".
    
    Example 2:
    
    >>> validIPAddress(queryIP = "2001:0db8:85a3:0:0:8A2E:0370:7334")
    >>> "IPv6"
    Explanation: This is a valid IPv6 address, return "IPv6".
    
    Example 3:
    
    >>> validIPAddress(queryIP = "256.256.256.256")
    >>> "Neither"
    Explanation: This is neither a IPv4 address nor a IPv6 address.
    """
def isConvex(points: List[List[int]]) -> bool:
    """
    You are given an array of points on the X-Y plane points where points[i] = [xi, yi]. The points form a polygon when joined sequentially.
    Return true if this polygon is convex and false otherwise.
    You may assume the polygon formed by given points is always a simple polygon. In other words, we ensure that exactly two edges intersect at each vertex and that edges otherwise don't intersect each other.
    
    Example 1:
    
    
    >>> isConvex(points = [[0,0],[0,5],[5,5],[5,0]])
    >>> true
    
    Example 2:
    
    
    >>> isConvex(points = [[0,0],[0,10],[10,10],[10,0],[5,5]])
    >>> false
    """
def encode(s: str) -> str:
    """
    Given a string s, encode the string such that its encoded length is the shortest.
    The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. k should be a positive integer.
    If an encoding process does not make the string shorter, then do not encode it. If there are several solutions, return any of them.
    
    Example 1:
    
    >>> encode(s = "aaa")
    >>> "aaa"
    Explanation: There is no way to encode it such that it is shorter than the input string, so we do not encode it.
    
    Example 2:
    
    >>> encode(s = "aaaaa")
    >>> "5[a]"
    Explanation: "5[a]" is shorter than "aaaaa" by 1 character.
    
    Example 3:
    
    >>> encode(s = "aaaaaaaaaa")
    >>> "10[a]"
    Explanation: "a9[a]" or "9[a]a" are also valid solutions, both of them have the same length = 5, which is the same as "10[a]".
    """
def findAllConcatenatedWordsInADict(words: List[str]) -> List[str]:
    """
    Given an array of strings words (without duplicates), return all the concatenated words in the given list of words.
    A concatenated word is defined as a string that is comprised entirely of at least two shorter words (not necessarily distinct) in the given array.
    
    Example 1:
    
    >>> findAllConcatenatedWordsInADict(words = ["cat","cats","catsdogcats","dog","dogcatsdog","hippopotamuses","rat","ratcatdogcat"])
    >>> ["catsdogcats","dogcatsdog","ratcatdogcat"]
    Explanation: "catsdogcats" can be concatenated by "cats", "dog" and "cats";
    "dogcatsdog" can be concatenated by "dog", "cats" and "dog";
    "ratcatdogcat" can be concatenated by "rat", "cat", "dog" and "cat".
    Example 2:
    
    >>> findAllConcatenatedWordsInADict(words = ["cat","dog","catdog"])
    >>> ["catdog"]
    """
def makesquare(matchsticks: List[int]) -> bool:
    """
    You are given an integer array matchsticks where matchsticks[i] is the length of the ith matchstick. You want to use all the matchsticks to make one square. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time.
    Return true if you can make this square and false otherwise.
    
    Example 1:
    
    
    >>> makesquare(matchsticks = [1,1,2,2,2])
    >>> true
    Explanation: You can form a square with length 2, one side of the square came two sticks with length 1.
    
    Example 2:
    
    >>> makesquare(matchsticks = [3,3,3,3,4])
    >>> false
    Explanation: You cannot find a way to form a square with all the matchsticks.
    """
def findMaxForm(strs: List[str], m: int, n: int) -> int:
    """
    You are given an array of binary strings strs and two integers m and n.
    Return the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset.
    A set x is a subset of a set y if all elements of x are also elements of y.
    
    Example 1:
    
    >>> findMaxForm(strs = ["10","0001","111001","1","0"], m = 5, n = 3)
    >>> 4
    Explanation: The largest subset with at most 5 0's and 3 1's is {"10", "0001", "1", "0"}, so the answer is 4.
    Other valid but smaller subsets include {"0001", "1"} and {"10", "1", "0"}.
    {"111001"} is an invalid subset because it contains 4 1's, greater than the maximum of 3.
    
    Example 2:
    
    >>> findMaxForm(strs = ["10","0","1"], m = 1, n = 1)
    >>> 2
    Explanation: The largest subset is {"0", "1"}, so the answer is 2.
    """
def findRadius(houses: List[int], heaters: List[int]) -> int:
    """
    Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses.
    Every house can be warmed, as long as the house is within the heater's warm radius range.
    Given the positions of houses and heaters on a horizontal line, return the minimum radius standard of heaters so that those heaters could cover all houses.
    Notice that all the heaters follow your radius standard, and the warm radius will the same.
    
    Example 1:
    
    >>> findRadius(houses = [1,2,3], heaters = [2])
    >>> 1
    Explanation: The only heater was placed in the position 2, and if we use the radius 1 standard, then all the houses can be warmed.
    
    Example 2:
    
    >>> findRadius(houses = [1,2,3,4], heaters = [1,4])
    >>> 1
    Explanation: The two heaters were placed at positions 1 and 4. We need to use a radius 1 standard, then all the houses can be warmed.
    
    Example 3:
    
    >>> findRadius(houses = [1,5], heaters = [2])
    >>> 3
    """
def findComplement(num: int) -> int:
    """
    The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.
    
    For example, The integer 5 is "101" in binary and its complement is "010" which is the integer 2.
    
    Given an integer num, return its complement.
    
    Example 1:
    
    >>> findComplement(num = 5)
    >>> 2
    Explanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.
    
    Example 2:
    
    >>> findComplement(num = 1)
    >>> 0
    Explanation: The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.
    """
def totalHammingDistance(nums: List[int]) -> int:
    """
    The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
    Given an integer array nums, return the sum of Hamming distances between all the pairs of the integers in nums.
    
    Example 1:
    
    >>> totalHammingDistance(nums = [4,14,2])
    >>> 6
    Explanation: In binary representation, the 4 is 0100, 14 is 1110, and 2 is 0010 (just
    showing the four bits relevant in this case).
    The answer will be:
    HammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 + 2 = 6.
    
    Example 2:
    
    >>> totalHammingDistance(nums = [4,14,4])
    >>> 4
    """
def largestPalindrome(n: int) -> int:
    """
    Given an integer n, return the largest palindromic integer that can be represented as the product of two n-digits integers. Since the answer can be very large, return it modulo 1337.
    
    Example 1:
    
    >>> largestPalindrome(n = 2)
    >>> 987
    Explanation: 99 x 91 = 9009, 9009 % 1337 = 987
    
    Example 2:
    
    >>> largestPalindrome(n = 1)
    >>> 9
    """
def medianSlidingWindow(nums: List[int], k: int) -> List[float]:
    """
    The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.
    
    For examples, if arr = [2,3,4], the median is 3.
    For examples, if arr = [1,2,3,4], the median is (2 + 3) / 2 = 2.5.
    
    You are given an integer array nums and an integer k. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.
    Return the median array for each window in the original array. Answers within 10-5 of the actual value will be accepted.
    
    Example 1:
    
    >>> medianSlidingWindow(nums = [1,3,-1,-3,5,3,6,7], k = 3)
    >>> [1.00000,-1.00000,-1.00000,3.00000,5.00000,6.00000]
    Explanation:
    Window position                Median
    ---------------                -----
    [1  3  -1] -3  5  3  6  7        1
     1 [3  -1  -3] 5  3  6  7       -1
     1  3 [-1  -3  5] 3  6  7       -1
     1  3  -1 [-3  5  3] 6  7        3
     1  3  -1  -3 [5  3  6] 7        5
     1  3  -1  -3  5 [3  6  7]       6
    
    Example 2:
    
    >>> medianSlidingWindow(nums = [1,2,3,4,2,3,1,4,2], k = 3)
    >>> [2.00000,3.00000,3.00000,3.00000,2.00000,3.00000,2.00000]
    """
def magicalString(n: int) -> int:
    """
    A magical string s consists of only '1' and '2' and obeys the following rules:
    
    The string s is magical because concatenating the number of contiguous occurrences of characters '1' and '2' generates the string s itself.
    
    The first few elements of s is s = "1221121221221121122……". If we group the consecutive 1's and 2's in s, it will be "1 22 11 2 1 22 1 22 11 2 11 22 ......" and the occurrences of 1's or 2's in each group are "1 2 2 1 1 2 1 2 2 1 2 2 ......". You can see that the occurrence sequence is s itself.
    Given an integer n, return the number of 1's in the first n number in the magical string s.
    
    Example 1:
    
    >>> magicalString(n = 6)
    >>> 3
    Explanation: The first 6 elements of magical string s is "122112" and it contains three 1's, so return 3.
    
    Example 2:
    
    >>> magicalString(n = 1)
    >>> 1
    """
def licenseKeyFormatting(s: str, k: int) -> str:
    """
    You are given a license key represented as a string s that consists of only alphanumeric characters and dashes. The string is separated into n + 1 groups by n dashes. You are also given an integer k.
    We want to reformat the string s such that each group contains exactly k characters, except for the first group, which could be shorter than k but still must contain at least one character. Furthermore, there must be a dash inserted between two groups, and you should convert all lowercase letters to uppercase.
    Return the reformatted license key.
    
    Example 1:
    
    >>> licenseKeyFormatting(s = "5F3Z-2e-9-w", k = 4)
    >>> "5F3Z-2E9W"
    Explanation: The string s has been split into two parts, each part has 4 characters.
    Note that the two extra dashes are not needed and can be removed.
    
    Example 2:
    
    >>> licenseKeyFormatting(s = "2-5g-3-J", k = 2)
    >>> "2-5G-3J"
    Explanation: The string s has been split into three parts, each part has 2 characters except the first part as it could be shorter as mentioned above.
    """
def smallestGoodBase(n: str) -> str:
    """
    Given an integer n represented as a string, return the smallest good base of n.
    We call k >= 2 a good base of n, if all digits of n base k are 1's.
    
    Example 1:
    
    >>> smallestGoodBase(n = "13")
    >>> "3"
    Explanation: 13 base 3 is 111.
    
    Example 2:
    
    >>> smallestGoodBase(n = "4681")
    >>> "8"
    Explanation: 4681 base 8 is 11111.
    
    Example 3:
    
    >>> smallestGoodBase(n = "1000000000000000000")
    >>> "999999999999999999"
    Explanation: 1000000000000000000 base 999999999999999999 is 11.
    """