ShwStone/humaneval-leetcode huggingface dataset:
def calcEquation(equations: List[List[str]], values: List[float], queries: List[List[str]]) -> List[float]:
    """
    You are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equation Ai / Bi = values[i]. Each Ai or Bi is a string that represents a single variable.
    You are also given some queries, where queries[j] = [Cj, Dj] represents the jth query where you must find the answer for Cj / Dj = ?.
    Return the answers to all queries. If a single answer cannot be determined, return -1.0.
    Note: The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction.
    Note: The variables that do not occur in the list of equations are undefined, so the answer cannot be determined for them.
    
    Example 1:
    
    >>> calcEquation(equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]])
    >>> [6.00000,0.50000,-1.00000,1.00000,-1.00000]
    Explanation:
    Given: a / b = 2.0, b / c = 3.0
    queries are: a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ?
    return: [6.0, 0.5, -1.0, 1.0, -1.0 ]
    note: x is undefined => -1.0
    Example 2:
    
    >>> calcEquation(equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]])
    >>> [3.75000,0.40000,5.00000,0.20000]
    
    Example 3:
    
    >>> calcEquation(equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]])
    >>> [0.50000,2.00000,-1.00000,-1.00000]
    """
def findNthDigit(n: int) -> int:
    """
    Given an integer n, return the nth digit of the infinite integer sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...].
    
    Example 1:
    
    >>> findNthDigit(n = 3)
    >>> 3
    
    Example 2:
    
    >>> findNthDigit(n = 11)
    >>> 0
    Explanation: The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... is a 0, which is part of the number 10.
    """
def readBinaryWatch(turnedOn: int) -> List[str]:
    """
    A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.
    
    For example, the below binary watch reads "4:51".
    
    
    Given an integer turnedOn which represents the number of LEDs that are currently on (ignoring the PM), return all possible times the watch could represent. You may return the answer in any order.
    The hour must not contain a leading zero.
    
    For example, "01:00" is not valid. It should be "1:00".
    
    The minute must consist of two digits and may contain a leading zero.
    
    For example, "10:2" is not valid. It should be "10:02".
    
    
    Example 1:
    >>> readBinaryWatch(turnedOn = 1)
    >>> ["0:01","0:02","0:04","0:08","0:16","0:32","1:00","2:00","4:00","8:00"]
    Example 2:
    >>> readBinaryWatch(turnedOn = 9)
    >>> []
    """
def removeKdigits(num: str, k: int) -> str:
    """
    Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.
    
    Example 1:
    
    >>> removeKdigits(num = "1432219", k = 3)
    >>> "1219"
    Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.
    
    Example 2:
    
    >>> removeKdigits(num = "10200", k = 1)
    >>> "200"
    Explanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.
    
    Example 3:
    
    >>> removeKdigits(num = "10", k = 2)
    >>> "0"
    Explanation: Remove all the digits from the number and it is left with nothing which is 0.
    """
def canCross(stones: List[int]) -> bool:
    """
    A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.
    Given a list of stones positions (in units) in sorted ascending order, determine if the frog can cross the river by landing on the last stone. Initially, the frog is on the first stone and assumes the first jump must be 1 unit.
    If the frog's last jump was k units, its next jump must be either k - 1, k, or k + 1 units. The frog can only jump in the forward direction.
    
    Example 1:
    
    >>> canCross(stones = [0,1,3,5,6,8,12,17])
    >>> true
    Explanation: The frog can jump to the last stone by jumping 1 unit to the 2nd stone, then 2 units to the 3rd stone, then 2 units to the 4th stone, then 3 units to the 6th stone, 4 units to the 7th stone, and 5 units to the 8th stone.
    
    Example 2:
    
    >>> canCross(stones = [0,1,2,3,4,8,9,11])
    >>> false
    Explanation: There is no way to jump to the last stone as the gap between the 5th and 6th stone is too large.
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def sumOfLeftLeaves(root: Optional[TreeNode]) -> int:
    """
    Given the root of a binary tree, return the sum of all left leaves.
    A leaf is a node with no children. A left leaf is a leaf that is the left child of another node.
    
    Example 1:
    
    
    >>> __init__(root = [3,9,20,null,null,15,7])
    >>> 24
    Explanation: There are two left leaves in the binary tree, with values 9 and 15 respectively.
    
    Example 2:
    
    >>> __init__(root = [1])
    >>> 0
    """
def toHex(num: int) -> str:
    """
    Given a 32-bit integer num, return a string representing its hexadecimal representation. For negative integers, two’s complement method is used.
    All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer except for the zero itself.
    Note: You are not allowed to use any built-in library method to directly solve this problem.
    
    Example 1:
    >>> toHex(num = 26)
    >>> "1a"
    Example 2:
    >>> toHex(num = -1)
    >>> "ffffffff"
    """
def reconstructQueue(people: List[List[int]]) -> List[List[int]]:
    """
    You are given an array of people, people, which are the attributes of some people in a queue (not necessarily in order). Each people[i] = [hi, ki] represents the ith person of height hi with exactly ki other people in front who have a height greater than or equal to hi.
    Reconstruct and return the queue that is represented by the input array people. The returned queue should be formatted as an array queue, where queue[j] = [hj, kj] is the attributes of the jth person in the queue (queue[0] is the person at the front of the queue).
    
    Example 1:
    
    >>> reconstructQueue(people = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]])
    >>> [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]
    Explanation:
    Person 0 has height 5 with no other people taller or the same height in front.
    Person 1 has height 7 with no other people taller or the same height in front.
    Person 2 has height 5 with two persons taller or the same height in front, which is person 0 and 1.
    Person 3 has height 6 with one person taller or the same height in front, which is person 1.
    Person 4 has height 4 with four people taller or the same height in front, which are people 0, 1, 2, and 3.
    Person 5 has height 7 with one person taller or the same height in front, which is person 1.
    Hence [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]] is the reconstructed queue.
    
    Example 2:
    
    >>> reconstructQueue(people = [[6,0],[5,0],[4,0],[3,2],[2,2],[1,4]])
    >>> [[4,0],[5,0],[2,2],[3,2],[1,4],[6,0]]
    """
def trapRainWater(heightMap: List[List[int]]) -> int:
    """
    Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.
    
    Example 1:
    
    
    >>> trapRainWater(heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]])
    >>> 4
    Explanation: After the rain, water is trapped between the blocks.
    We have two small ponds 1 and 3 units trapped.
    The total volume of water trapped is 4.
    
    Example 2:
    
    
    >>> trapRainWater(heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]])
    >>> 10
    """
def validWordAbbreviation(word: str, abbr: str) -> bool:
    """
    A string can be abbreviated by replacing any number of non-adjacent, non-empty substrings with their lengths. The lengths should not have leading zeros.
    For example, a string such as "substitution" could be abbreviated as (but not limited to):
    
    "s10n" ("s ubstitutio n")
    "sub4u4" ("sub stit u tion")
    "12" ("substitution")
    "su3i1u2on" ("su bst i t u ti on")
    "substitution" (no substrings replaced)
    
    The following are not valid abbreviations:
    
    "s55n" ("s ubsti tutio n", the replaced substrings are adjacent)
    "s010n" (has leading zeros)
    "s0ubstitution" (replaces an empty substring)
    
    Given a string word and an abbreviation abbr, return whether the string matches the given abbreviation.
    A substring is a contiguous non-empty sequence of characters within a string.
    
    Example 1:
    
    >>> validWordAbbreviation(word = "internationalization", abbr = "i12iz4n")
    >>> true
    Explanation: The word "internationalization" can be abbreviated as "i12iz4n" ("i nternational iz atio n").
    
    Example 2:
    
    >>> validWordAbbreviation(word = "apple", abbr = "a2e")
    >>> false
    Explanation: The word "apple" cannot be abbreviated as "a2e".
    """
def longestPalindrome(s: str) -> int:
    """
    Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters.
    Letters are case sensitive, for example, "Aa" is not considered a palindrome.
    
    Example 1:
    
    >>> longestPalindrome(s = "abccccdd")
    >>> 7
    Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7.
    
    Example 2:
    
    >>> longestPalindrome(s = "a")
    >>> 1
    Explanation: The longest palindrome that can be built is "a", whose length is 1.
    """
def splitArray(nums: List[int], k: int) -> int:
    """
    Given an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized.
    Return the minimized largest sum of the split.
    A subarray is a contiguous part of the array.
    
    Example 1:
    
    >>> splitArray(nums = [7,2,5,10,8], k = 2)
    >>> 18
    Explanation: There are four ways to split nums into two subarrays.
    The best way is to split it into [7,2,5] and [10,8], where the largest sum among the two subarrays is only 18.
    
    Example 2:
    
    >>> splitArray(nums = [1,2,3,4,5], k = 2)
    >>> 9
    Explanation: There are four ways to split nums into two subarrays.
    The best way is to split it into [1,2,3] and [4,5], where the largest sum among the two subarrays is only 9.
    """
def minAbbreviation(target: str, dictionary: List[str]) -> str:
    """
    A string can be abbreviated by replacing any number of non-adjacent substrings with their lengths. For example, a string such as "substitution" could be abbreviated as (but not limited to):
    
    "s10n" ("s ubstitutio n")
    "sub4u4" ("sub stit u tion")
    "12" ("substitution")
    "su3i1u2on" ("su bst i t u ti on")
    "substitution" (no substrings replaced)
    
    Note that "s55n" ("s ubsti tutio n") is not a valid abbreviation of "substitution" because the replaced substrings are adjacent.
    The length of an abbreviation is the number of letters that were not replaced plus the number of substrings that were replaced. For example, the abbreviation "s10n" has a length of 3 (2 letters + 1 substring) and "su3i1u2on" has a length of 9 (6 letters + 3 substrings).
    Given a target string target and an array of strings dictionary, return an abbreviation of target with the shortest possible length such that it is not an abbreviation of any string in dictionary. If there are multiple shortest abbreviations, return any of them.
    
    Example 1:
    
    >>> minAbbreviation(target = "apple", dictionary = ["blade"])
    >>> "a4"
    Explanation: The shortest abbreviation of "apple" is "5", but this is also an abbreviation of "blade".
    The next shortest abbreviations are "a4" and "4e". "4e" is an abbreviation of blade while "a4" is not.
    Hence, return "a4".
    
    Example 2:
    
    >>> minAbbreviation(target = "apple", dictionary = ["blade","plain","amber"])
    >>> "1p3"
    Explanation: "5" is an abbreviation of both "apple" but also every word in the dictionary.
    "a4" is an abbreviation of "apple" but also "amber".
    "4e" is an abbreviation of "apple" but also "blade".
    "1p3", "2p2", and "3l1" are the next shortest abbreviations of "apple".
    Since none of them are abbreviations of words in the dictionary, returning any of them is correct.
    """
def fizzBuzz(n: int) -> List[str]:
    """
    Given an integer n, return a string array answer (1-indexed) where:
    
    answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
    answer[i] == "Fizz" if i is divisible by 3.
    answer[i] == "Buzz" if i is divisible by 5.
    answer[i] == i (as a string) if none of the above conditions are true.
    
    
    Example 1:
    >>> fizzBuzz(n = 3)
    >>> ["1","2","Fizz"]
    Example 2:
    >>> fizzBuzz(n = 5)
    >>> ["1","2","Fizz","4","Buzz"]
    Example 3:
    >>> fizzBuzz(n = 15)
    >>> ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
    """
def numberOfArithmeticSlices(nums: List[int]) -> int:
    """
    An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.
    
    For example, [1,3,5,7,9], [7,7,7,7], and [3,-1,-5,-9] are arithmetic sequences.
    
    Given an integer array nums, return the number of arithmetic subarrays of nums.
    A subarray is a contiguous subsequence of the array.
    
    Example 1:
    
    >>> numberOfArithmeticSlices(nums = [1,2,3,4])
    >>> 3
    Explanation: We have 3 arithmetic slices in nums: [1, 2, 3], [2, 3, 4] and [1,2,3,4] itself.
    
    Example 2:
    
    >>> numberOfArithmeticSlices(nums = [1])
    >>> 0
    """
def thirdMax(nums: List[int]) -> int:
    """
    Given an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number.
    
    Example 1:
    
    >>> thirdMax(nums = [3,2,1])
    >>> 1
    Explanation:
    The first distinct maximum is 3.
    The second distinct maximum is 2.
    The third distinct maximum is 1.
    
    Example 2:
    
    >>> thirdMax(nums = [1,2])
    >>> 2
    Explanation:
    The first distinct maximum is 2.
    The second distinct maximum is 1.
    The third distinct maximum does not exist, so the maximum (2) is returned instead.
    
    Example 3:
    
    >>> thirdMax(nums = [2,2,3,1])
    >>> 1
    Explanation:
    The first distinct maximum is 3.
    The second distinct maximum is 2 (both 2's are counted together since they have the same value).
    The third distinct maximum is 1.
    """
def addStrings(num1: str, num2: str) -> str:
    """
    Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string.
    You must solve the problem without using any built-in library for handling large integers (such as BigInteger). You must also not convert the inputs to integers directly.
    
    Example 1:
    
    >>> addStrings(num1 = "11", num2 = "123")
    >>> "134"
    
    Example 2:
    
    >>> addStrings(num1 = "456", num2 = "77")
    >>> "533"
    
    Example 3:
    
    >>> addStrings(num1 = "0", num2 = "0")
    >>> "0"
    """
def canPartition(nums: List[int]) -> bool:
    """
    Given an integer array nums, return true if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or false otherwise.
    
    Example 1:
    
    >>> canPartition(nums = [1,5,11,5])
    >>> true
    Explanation: The array can be partitioned as [1, 5, 5] and [11].
    
    Example 2:
    
    >>> canPartition(nums = [1,2,3,5])
    >>> false
    Explanation: The array cannot be partitioned into equal sum subsets.
    """
def pacificAtlantic(heights: List[List[int]]) -> List[List[int]]:
    """
    There is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and top edges, and the Atlantic Ocean touches the island's right and bottom edges.
    The island is partitioned into a grid of square cells. You are given an m x n integer matrix heights where heights[r][c] represents the height above sea level of the cell at coordinate (r, c).
    The island receives a lot of rain, and the rain water can flow to neighboring cells directly north, south, east, and west if the neighboring cell's height is less than or equal to the current cell's height. Water can flow from any cell adjacent to an ocean into the ocean.
    Return a 2D list of grid coordinates result where result[i] = [ri, ci] denotes that rain water can flow from cell (ri, ci) to both the Pacific and Atlantic oceans.
    
    Example 1:
    
    
    >>> pacificAtlantic(heights = [[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]])
    >>> [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]
    Explanation: The following cells can flow to the Pacific and Atlantic oceans, as shown below:
    [0,4]: [0,4] -> Pacific Ocean
           [0,4] -> Atlantic Ocean
    [1,3]: [1,3] -> [0,3] -> Pacific Ocean
           [1,3] -> [1,4] -> Atlantic Ocean
    [1,4]: [1,4] -> [1,3] -> [0,3] -> Pacific Ocean
           [1,4] -> Atlantic Ocean
    [2,2]: [2,2] -> [1,2] -> [0,2] -> Pacific Ocean
           [2,2] -> [2,3] -> [2,4] -> Atlantic Ocean
    [3,0]: [3,0] -> Pacific Ocean
           [3,0] -> [4,0] -> Atlantic Ocean
    [3,1]: [3,1] -> [3,0] -> Pacific Ocean
           [3,1] -> [4,1] -> Atlantic Ocean
    [4,0]: [4,0] -> Pacific Ocean
           [4,0] -> Atlantic Ocean
    Note that there are other possible paths for these cells to flow to the Pacific and Atlantic oceans.
    
    Example 2:
    
    >>> pacificAtlantic(heights = [[1]])
    >>> [[0,0]]
    Explanation: The water can flow from the only cell to the Pacific and Atlantic oceans.
    """
def wordsTyping(sentence: List[str], rows: int, cols: int) -> int:
    """
    Given a rows x cols screen and a sentence represented as a list of strings, return the number of times the given sentence can be fitted on the screen.
    The order of words in the sentence must remain unchanged, and a word cannot be split into two lines. A single space must separate two consecutive words in a line.
    
    Example 1:
    
    >>> wordsTyping(sentence = ["hello","world"], rows = 2, cols = 8)
    >>> 1
    Explanation:
    hello---
    world---
    The character '-' signifies an empty space on the screen.
    
    Example 2:
    
    >>> wordsTyping(sentence = ["a", "bcd", "e"], rows = 3, cols = 6)
    >>> 2
    Explanation:
    a-bcd-
    e-a---
    bcd-e-
    The character '-' signifies an empty space on the screen.
    
    Example 3:
    
    >>> wordsTyping(sentence = ["i","had","apple","pie"], rows = 4, cols = 5)
    >>> 1
    Explanation:
    i-had
    apple
    pie-i
    had--
    The character '-' signifies an empty space on the screen.
    """
def countBattleships(board: List[List[str]]) -> int:
    """
    Given an m x n matrix board where each cell is a battleship 'X' or empty '.', return the number of the battleships on board.
    Battleships can only be placed horizontally or vertically on board. In other words, they can only be made of the shape 1 x k (1 row, k columns) or k x 1 (k rows, 1 column), where k can be of any size. At least one horizontal or vertical cell separates between two battleships (i.e., there are no adjacent battleships).
    
    Example 1:
    
    
    >>> countBattleships(board = [["X",".",".","X"],[".",".",".","X"],[".",".",".","X"]])
    >>> 2
    
    Example 2:
    
    >>> countBattleships(board = [["."]])
    >>> 0
    """
def strongPasswordChecker(password: str) -> int:
    """
    A password is considered strong if the below conditions are all met:
    
    It has at least 6 characters and at most 20 characters.
    It contains at least one lowercase letter, at least one uppercase letter, and at least one digit.
    It does not contain three repeating characters in a row (i.e., "Baaabb0" is weak, but "Baaba0" is strong).
    
    Given a string password, return the minimum number of steps required to make password strong. if password is already strong, return 0.
    In one step, you can:
    
    Insert one character to password,
    Delete one character from password, or
    Replace one character of password with another character.
    
    
    Example 1:
    >>> strongPasswordChecker(password = "a")
    >>> 5
    Example 2:
    >>> strongPasswordChecker(password = "aA1")
    >>> 3
    Example 3:
    >>> strongPasswordChecker(password = "1337C0d3")
    >>> 0
    """
def findMaximumXOR(nums: List[int]) -> int:
    """
    Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n.
    
    Example 1:
    
    >>> findMaximumXOR(nums = [3,10,5,25,2,8])
    >>> 28
    Explanation: The maximum result is 5 XOR 25 = 28.
    
    Example 2:
    
    >>> findMaximumXOR(nums = [14,70,53,83,49,91,36,80,92,51,66,70])
    >>> 127
    """
def validWordSquare(words: List[str]) -> bool:
    """
    Given an array of strings words, return true if it forms a valid word square.
    A sequence of strings forms a valid word square if the kth row and column read the same string, where 0 <= k < max(numRows, numColumns).
    
    Example 1:
    
    
    >>> validWordSquare(words = ["abcd","bnrt","crmy","dtye"])
    >>> true
    Explanation:
    The 1st row and 1st column both read "abcd".
    The 2nd row and 2nd column both read "bnrt".
    The 3rd row and 3rd column both read "crmy".
    The 4th row and 4th column both read "dtye".
    Therefore, it is a valid word square.
    
    Example 2:
    
    
    >>> validWordSquare(words = ["abcd","bnrt","crm","dt"])
    >>> true
    Explanation:
    The 1st row and 1st column both read "abcd".
    The 2nd row and 2nd column both read "bnrt".
    The 3rd row and 3rd column both read "crm".
    The 4th row and 4th column both read "dt".
    Therefore, it is a valid word square.
    
    Example 3:
    
    
    >>> validWordSquare(words = ["ball","area","read","lady"])
    >>> false
    Explanation:
    The 3rd row reads "read" while the 3rd column reads "lead".
    Therefore, it is NOT a valid word square.
    """
def originalDigits(s: str) -> str:
    """
    Given a string s containing an out-of-order English representation of digits 0-9, return the digits in ascending order.
    
    Example 1:
    >>> originalDigits(s = "owoztneoer")
    >>> "012"
    Example 2:
    >>> originalDigits(s = "fviefuro")
    >>> "45"
    """
def characterReplacement(s: str, k: int) -> int:
    """
    You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times.
    Return the length of the longest substring containing the same letter you can get after performing the above operations.
    
    Example 1:
    
    >>> characterReplacement(s = "ABAB", k = 2)
    >>> 4
    Explanation: Replace the two 'A's with two 'B's or vice versa.
    
    Example 2:
    
    >>> characterReplacement(s = "AABABBA", k = 1)
    >>> 4
    Explanation: Replace the one 'A' in the middle with 'B' and form "AABBBBA".
    The substring "BBBB" has the longest repeating letters, which is 4.
    There may exists other ways to achieve this answer too.
    """