ShwStone/humaneval-leetcode huggingface dataset:
def longestCommonSubsequence(arrays: List[List[int]]) -> List[int]:
    """
    Given an array of integer arrays arrays where each arrays[i] is sorted in strictly increasing order, return an integer array representing the longest common subsequence among all the arrays.
    A subsequence is a sequence that can be derived from another sequence by deleting some elements (possibly none) without changing the order of the remaining elements.
    
    Example 1:
    
                     [1,4,7,9]]
    >>> longestCommonSubsequence(arrays = [[1,3,4],)
    >>> [1,4]
    Explanation: The longest common subsequence in the two arrays is [1,4].
    
    Example 2:
    
                     [1,2,3,5,6,7,10],
                     [2,3,4,6,9]]
    >>> longestCommonSubsequence(arrays = [[2,3,6,8],)
    >>> [2,3,6]
    Explanation: The longest common subsequence in all three arrays is [2,3,6].
    
    Example 3:
    
                     [6,7,8]]
    >>> longestCommonSubsequence(arrays = [[1,2,3,4,5],)
    >>> []
    Explanation: There is no common subsequence between the two arrays.
    """
def areOccurrencesEqual(s: str) -> bool:
    """
    Given a string s, return true if s is a good string, or false otherwise.
    A string s is good if all the characters that appear in s have the same number of occurrences (i.e., the same frequency).
    
    Example 1:
    
    >>> areOccurrencesEqual(s = "abacbc")
    >>> true
    Explanation: The characters that appear in s are 'a', 'b', and 'c'. All characters occur 2 times in s.
    
    Example 2:
    
    >>> areOccurrencesEqual(s = "aaabb")
    >>> false
    Explanation: The characters that appear in s are 'a' and 'b'.
    'a' occurs 3 times while 'b' occurs 2 times, which is not the same number of times.
    """
def smallestChair(times: List[List[int]], targetFriend: int) -> int:
    """
    There is a party where n friends numbered from 0 to n - 1 are attending. There is an infinite number of chairs in this party that are numbered from 0 to infinity. When a friend arrives at the party, they sit on the unoccupied chair with the smallest number.
    
    For example, if chairs 0, 1, and 5 are occupied when a friend comes, they will sit on chair number 2.
    
    When a friend leaves the party, their chair becomes unoccupied at the moment they leave. If another friend arrives at that same moment, they can sit in that chair.
    You are given a 0-indexed 2D integer array times where times[i] = [arrivali, leavingi], indicating the arrival and leaving times of the ith friend respectively, and an integer targetFriend. All arrival times are distinct.
    Return the chair number that the friend numbered targetFriend will sit on.
    
    Example 1:
    
    >>> smallestChair(times = [[1,4],[2,3],[4,6]], targetFriend = 1)
    >>> 1
    Explanation:
    - Friend 0 arrives at time 1 and sits on chair 0.
    - Friend 1 arrives at time 2 and sits on chair 1.
    - Friend 1 leaves at time 3 and chair 1 becomes empty.
    - Friend 0 leaves at time 4 and chair 0 becomes empty.
    - Friend 2 arrives at time 4 and sits on chair 0.
    Since friend 1 sat on chair 1, we return 1.
    
    Example 2:
    
    >>> smallestChair(times = [[3,10],[1,5],[2,6]], targetFriend = 0)
    >>> 2
    Explanation:
    - Friend 1 arrives at time 1 and sits on chair 0.
    - Friend 2 arrives at time 2 and sits on chair 1.
    - Friend 0 arrives at time 3 and sits on chair 2.
    - Friend 1 leaves at time 5 and chair 0 becomes empty.
    - Friend 2 leaves at time 6 and chair 1 becomes empty.
    - Friend 0 leaves at time 10 and chair 2 becomes empty.
    Since friend 0 sat on chair 2, we return 2.
    """
def splitPainting(segments: List[List[int]]) -> List[List[int]]:
    """
    There is a long and thin painting that can be represented by a number line. The painting was painted with multiple overlapping segments where each segment was painted with a unique color. You are given a 2D integer array segments, where segments[i] = [starti, endi, colori] represents the half-closed segment [starti, endi) with colori as the color.
    The colors in the overlapping segments of the painting were mixed when it was painted. When two or more colors mix, they form a new color that can be represented as a set of mixed colors.
    
    For example, if colors 2, 4, and 6 are mixed, then the resulting mixed color is {2,4,6}.
    
    For the sake of simplicity, you should only output the sum of the elements in the set rather than the full set.
    You want to describe the painting with the minimum number of non-overlapping half-closed segments of these mixed colors. These segments can be represented by the 2D array painting where painting[j] = [leftj, rightj, mixj] describes a half-closed segment [leftj, rightj) with the mixed color sum of mixj.
    
    For example, the painting created with segments = [[1,4,5],[1,7,7]] can be described by painting = [[1,4,12],[4,7,7]] because:
    
    
    [1,4) is colored {5,7} (with a sum of 12) from both the first and second segments.
    [4,7) is colored {7} from only the second segment.
    
    
    
    Return the 2D array painting describing the finished painting (excluding any parts that are not painted). You may return the segments in any order.
    A half-closed segment [a, b) is the section of the number line between points a and b including point a and not including point b.
    
    Example 1:
    
    
    >>> splitPainting(segments = [[1,4,5],[4,7,7],[1,7,9]])
    >>> [[1,4,14],[4,7,16]]
    Explanation: The painting can be described as follows:
    - [1,4) is colored {5,9} (with a sum of 14) from the first and third segments.
    - [4,7) is colored {7,9} (with a sum of 16) from the second and third segments.
    
    Example 2:
    
    
    >>> splitPainting(segments = [[1,7,9],[6,8,15],[8,10,7]])
    >>> [[1,6,9],[6,7,24],[7,8,15],[8,10,7]]
    Explanation: The painting can be described as follows:
    - [1,6) is colored 9 from the first segment.
    - [6,7) is colored {9,15} (with a sum of 24) from the first and second segments.
    - [7,8) is colored 15 from the second segment.
    - [8,10) is colored 7 from the third segment.
    
    Example 3:
    
    
    >>> splitPainting(segments = [[1,4,5],[1,4,7],[4,7,1],[4,7,11]])
    >>> [[1,4,12],[4,7,12]]
    Explanation: The painting can be described as follows:
    - [1,4) is colored {5,7} (with a sum of 12) from the first and second segments.
    - [4,7) is colored {1,11} (with a sum of 12) from the third and fourth segments.
    Note that returning a single segment [1,7) is incorrect because the mixed color sets are different.
    """
def canSeePersonsCount(heights: List[int]) -> List[int]:
    """
    There are n people standing in a queue, and they numbered from 0 to n - 1 in left to right order. You are given an array heights of distinct integers where heights[i] represents the height of the ith person.
    A person can see another person to their right in the queue if everybody in between is shorter than both of them. More formally, the ith person can see the jth person if i < j and min(heights[i], heights[j]) > max(heights[i+1], heights[i+2], ..., heights[j-1]).
    Return an array answer of length n where answer[i] is the number of people the ith person can see to their right in the queue.
    
    Example 1:
    
    
    >>> canSeePersonsCount(heights = [10,6,8,5,11,9])
    >>> [3,1,2,1,1,0]
    Explanation:
    Person 0 can see person 1, 2, and 4.
    Person 1 can see person 2.
    Person 2 can see person 3 and 4.
    Person 3 can see person 4.
    Person 4 can see person 5.
    Person 5 can see no one since nobody is to the right of them.
    
    Example 2:
    
    >>> canSeePersonsCount(heights = [5,1,2,3,10])
    >>> [4,1,1,1,0]
    """
def getLucky(s: str, k: int) -> int:
    """
    You are given a string s consisting of lowercase English letters, and an integer k. Your task is to convert the string into an integer by a special process, and then transform it by summing its digits repeatedly k times. More specifically, perform the following steps:
    
    Convert s into an integer by replacing each letter with its position in the alphabet (i.e. replace 'a' with 1, 'b' with 2, ..., 'z' with 26).
    Transform the integer by replacing it with the sum of its digits.
    Repeat the transform operation (step 2) k times in total.
    
    For example, if s = "zbax" and k = 2, then the resulting integer would be 8 by the following operations:
    
    Convert: "zbax" ➝ "(26)(2)(1)(24)" ➝ "262124" ➝ 262124
    Transform #1: 262124 ➝ 2 + 6 + 2 + 1 + 2 + 4 ➝ 17
    Transform #2: 17 ➝ 1 + 7 ➝ 8
    
    Return the resulting integer after performing the operations described above.
    
    Example 1:
    
    >>> getLucky(s = "iiii", k = 1)
    >>> 36
    Explanation:
    The operations are as follows:
    - Convert: "iiii" ➝ "(9)(9)(9)(9)" ➝ "9999" ➝ 9999
    - Transform #1: 9999 ➝ 9 + 9 + 9 + 9 ➝ 36
    Thus the resulting integer is 36.
    
    Example 2:
    
    >>> getLucky(s = "leetcode", k = 2)
    >>> 6
    Explanation:
    The operations are as follows:
    - Convert: "leetcode" ➝ "(12)(5)(5)(20)(3)(15)(4)(5)" ➝ "12552031545" ➝ 12552031545
    - Transform #1: 12552031545 ➝ 1 + 2 + 5 + 5 + 2 + 0 + 3 + 1 + 5 + 4 + 5 ➝ 33
    - Transform #2: 33 ➝ 3 + 3 ➝ 6
    Thus the resulting integer is 6.
    
    Example 3:
    
    >>> getLucky(s = "zbax", k = 2)
    >>> 8
    """
def maximumNumber(num: str, change: List[int]) -> str:
    """
    You are given a string num, which represents a large integer. You are also given a 0-indexed integer array change of length 10 that maps each digit 0-9 to another digit. More formally, digit d maps to digit change[d].
    You may choose to mutate a single substring of num. To mutate a substring, replace each digit num[i] with the digit it maps to in change (i.e. replace num[i] with change[num[i]]).
    Return a string representing the largest possible integer after mutating (or choosing not to) a single substring of num.
    A substring is a contiguous sequence of characters within the string.
    
    Example 1:
    
    >>> maximumNumber(num = "132", change = [9,8,5,0,3,6,4,2,6,8])
    >>> "832"
    Explanation: Replace the substring "1":
    - 1 maps to change[1] = 8.
    Thus, "132" becomes "832".
    "832" is the largest number that can be created, so return it.
    
    Example 2:
    
    >>> maximumNumber(num = "021", change = [9,4,3,5,7,2,1,9,0,6])
    >>> "934"
    Explanation: Replace the substring "021":
    - 0 maps to change[0] = 9.
    - 2 maps to change[2] = 3.
    - 1 maps to change[1] = 4.
    Thus, "021" becomes "934".
    "934" is the largest number that can be created, so return it.
    
    Example 3:
    
    >>> maximumNumber(num = "5", change = [1,4,7,5,3,2,5,6,9,4])
    >>> "5"
    Explanation: "5" is already the largest number that can be created, so return it.
    """
def maxCompatibilitySum(students: List[List[int]], mentors: List[List[int]]) -> int:
    """
    There is a survey that consists of n questions where each question's answer is either 0 (no) or 1 (yes).
    The survey was given to m students numbered from 0 to m - 1 and m mentors numbered from 0 to m - 1. The answers of the students are represented by a 2D integer array students where students[i] is an integer array that contains the answers of the ith student (0-indexed). The answers of the mentors are represented by a 2D integer array mentors where mentors[j] is an integer array that contains the answers of the jth mentor (0-indexed).
    Each student will be assigned to one mentor, and each mentor will have one student assigned to them. The compatibility score of a student-mentor pair is the number of answers that are the same for both the student and the mentor.
    
    For example, if the student's answers were [1, 0, 1] and the mentor's answers were [0, 0, 1], then their compatibility score is 2 because only the second and the third answers are the same.
    
    You are tasked with finding the optimal student-mentor pairings to maximize the sum of the compatibility scores.
    Given students and mentors, return the maximum compatibility score sum that can be achieved.
    
    Example 1:
    
    >>> maxCompatibilitySum(students = [[1,1,0],[1,0,1],[0,0,1]], mentors = [[1,0,0],[0,0,1],[1,1,0]])
    >>> 8
    Explanation: We assign students to mentors in the following way:
    - student 0 to mentor 2 with a compatibility score of 3.
    - student 1 to mentor 0 with a compatibility score of 2.
    - student 2 to mentor 1 with a compatibility score of 3.
    The compatibility score sum is 3 + 2 + 3 = 8.
    
    Example 2:
    
    >>> maxCompatibilitySum(students = [[0,0],[0,0],[0,0]], mentors = [[1,1],[1,1],[1,1]])
    >>> 0
    Explanation: The compatibility score of any student-mentor pair is 0.
    """
def deleteDuplicateFolder(paths: List[List[str]]) -> List[List[str]]:
    """
    Due to a bug, there are many duplicate folders in a file system. You are given a 2D array paths, where paths[i] is an array representing an absolute path to the ith folder in the file system.
    
    For example, ["one", "two", "three"] represents the path "/one/two/three".
    
    Two folders (not necessarily on the same level) are identical if they contain the same non-empty set of identical subfolders and underlying subfolder structure. The folders do not need to be at the root level to be identical. If two or more folders are identical, then mark the folders as well as all their subfolders.
    
    For example, folders "/a" and "/b" in the file structure below are identical. They (as well as their subfolders) should all be marked:
    
    
    /a
    /a/x
    /a/x/y
    /a/z
    /b
    /b/x
    /b/x/y
    /b/z
    
    
    However, if the file structure also included the path "/b/w", then the folders "/a" and "/b" would not be identical. Note that "/a/x" and "/b/x" would still be considered identical even with the added folder.
    
    Once all the identical folders and their subfolders have been marked, the file system will delete all of them. The file system only runs the deletion once, so any folders that become identical after the initial deletion are not deleted.
    Return the 2D array ans containing the paths of the remaining folders after deleting all the marked folders. The paths may be returned in any order.
    
    Example 1:
    
    
    >>> deleteDuplicateFolder(paths = [["a"],["c"],["d"],["a","b"],["c","b"],["d","a"]])
    >>> [["d"],["d","a"]]
    Explanation: The file structure is as shown.
    Folders "/a" and "/c" (and their subfolders) are marked for deletion because they both contain an empty
    folder named "b".
    
    Example 2:
    
    
    >>> deleteDuplicateFolder(paths = [["a"],["c"],["a","b"],["c","b"],["a","b","x"],["a","b","x","y"],["w"],["w","y"]])
    >>> [["c"],["c","b"],["a"],["a","b"]]
    Explanation: The file structure is as shown.
    Folders "/a/b/x" and "/w" (and their subfolders) are marked for deletion because they both contain an empty folder named "y".
    Note that folders "/a" and "/c" are identical after the deletion, but they are not deleted because they were not marked beforehand.
    
    Example 3:
    
    
    >>> deleteDuplicateFolder(paths = [["a","b"],["c","d"],["c"],["a"]])
    >>> [["c"],["c","d"],["a"],["a","b"]]
    Explanation: All folders are unique in the file system.
    Note that the returned array can be in a different order as the order does not matter.
    """
def findMaximums(nums: List[int]) -> List[int]:
    """
    You are given an integer array nums of size n. You are asked to solve n queries for each integer i in the range 0 <= i < n.
    To solve the ith query:
    
    Find the minimum value in each possible subarray of size i + 1 of the array nums.
    Find the maximum of those minimum values. This maximum is the answer to the query.
    
    Return a 0-indexed integer array ans of size n such that ans[i] is the answer to the ith query.
    A subarray is a contiguous sequence of elements in an array.
    
    Example 1:
    
    >>> findMaximums(nums = [0,1,2,4])
    >>> [4,2,1,0]
    Explanation:
    i=0:
    - The subarrays of size 1 are [0], [1], [2], [4]. The minimum values are 0, 1, 2, 4.
    - The maximum of the minimum values is 4.
    i=1:
    - The subarrays of size 2 are [0,1], [1,2], [2,4]. The minimum values are 0, 1, 2.
    - The maximum of the minimum values is 2.
    i=2:
    - The subarrays of size 3 are [0,1,2], [1,2,4]. The minimum values are 0, 1.
    - The maximum of the minimum values is 1.
    i=3:
    - There is one subarray of size 4, which is [0,1,2,4]. The minimum value is 0.
    - There is only one value, so the maximum is 0.
    
    Example 2:
    
    >>> findMaximums(nums = [10,20,50,10])
    >>> [50,20,10,10]
    Explanation:
    i=0:
    - The subarrays of size 1 are [10], [20], [50], [10]. The minimum values are 10, 20, 50, 10.
    - The maximum of the minimum values is 50.
    i=1:
    - The subarrays of size 2 are [10,20], [20,50], [50,10]. The minimum values are 10, 20, 10.
    - The maximum of the minimum values is 20.
    i=2:
    - The subarrays of size 3 are [10,20,50], [20,50,10]. The minimum values are 10, 10.
    - The maximum of the minimum values is 10.
    i=3:
    - There is one subarray of size 4, which is [10,20,50,10]. The minimum value is 10.
    - There is only one value, so the maximum is 10.
    """
def isThree(n: int) -> bool:
    """
    Given an integer n, return true if n has exactly three positive divisors. Otherwise, return false.
    An integer m is a divisor of n if there exists an integer k such that n = k * m.
    
    Example 1:
    
    >>> isThree(n = 2)
    >>> false
    Explantion: 2 has only two divisors: 1 and 2.
    
    Example 2:
    
    >>> isThree(n = 4)
    >>> true
    Explantion: 4 has three divisors: 1, 2, and 4.
    """
def numberOfWeeks(milestones: List[int]) -> int:
    """
    There are n projects numbered from 0 to n - 1. You are given an integer array milestones where each milestones[i] denotes the number of milestones the ith project has.
    You can work on the projects following these two rules:
    
    Every week, you will finish exactly one milestone of one project. You must work every week.
    You cannot work on two milestones from the same project for two consecutive weeks.
    
    Once all the milestones of all the projects are finished, or if the only milestones that you can work on will cause you to violate the above rules, you will stop working. Note that you may not be able to finish every project's milestones due to these constraints.
    Return the maximum number of weeks you would be able to work on the projects without violating the rules mentioned above.
    
    Example 1:
    
    >>> numberOfWeeks(milestones = [1,2,3])
    >>> 6
    Explanation: One possible scenario is:
    ​​​​- During the 1st week, you will work on a milestone of project 0.
    - During the 2nd week, you will work on a milestone of project 2.
    - During the 3rd week, you will work on a milestone of project 1.
    - During the 4th week, you will work on a milestone of project 2.
    - During the 5th week, you will work on a milestone of project 1.
    - During the 6th week, you will work on a milestone of project 2.
    The total number of weeks is 6.
    
    Example 2:
    
    >>> numberOfWeeks(milestones = [5,2,1])
    >>> 7
    Explanation: One possible scenario is:
    - During the 1st week, you will work on a milestone of project 0.
    - During the 2nd week, you will work on a milestone of project 1.
    - During the 3rd week, you will work on a milestone of project 0.
    - During the 4th week, you will work on a milestone of project 1.
    - During the 5th week, you will work on a milestone of project 0.
    - During the 6th week, you will work on a milestone of project 2.
    - During the 7th week, you will work on a milestone of project 0.
    The total number of weeks is 7.
    Note that you cannot work on the last milestone of project 0 on 8th week because it would violate the rules.
    Thus, one milestone in project 0 will remain unfinished.
    """
def minimumPerimeter(neededApples: int) -> int:
    """
    In a garden represented as an infinite 2D grid, there is an apple tree planted at every integer coordinate. The apple tree planted at an integer coordinate (i, j) has |i| + |j| apples growing on it.
    You will buy an axis-aligned square plot of land that is centered at (0, 0).
    Given an integer neededApples, return the minimum perimeter of a plot such that at least neededApples apples are inside or on the perimeter of that plot.
    The value of |x| is defined as:
    
    x if x >= 0
    -x if x < 0
    
    
    Example 1:
    
    
    >>> minimumPerimeter(neededApples = 1)
    >>> 8
    Explanation: A square plot of side length 1 does not contain any apples.
    However, a square plot of side length 2 has 12 apples inside (as depicted in the image above).
    The perimeter is 2 * 4 = 8.
    
    Example 2:
    
    >>> minimumPerimeter(neededApples = 13)
    >>> 16
    
    Example 3:
    
    >>> minimumPerimeter(neededApples = 1000000000)
    >>> 5040
    """
def countSpecialSubsequences(nums: List[int]) -> int:
    """
    A sequence is special if it consists of a positive number of 0s, followed by a positive number of 1s, then a positive number of 2s.
    
    For example, [0,1,2] and [0,0,1,1,1,2] are special.
    In contrast, [2,1,0], [1], and [0,1,2,0] are not special.
    
    Given an array nums (consisting of only integers 0, 1, and 2), return the number of different subsequences that are special. Since the answer may be very large, return it modulo 109 + 7.
    A subsequence of an array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements. Two subsequences are different if the set of indices chosen are different.
    
    Example 1:
    
    >>> countSpecialSubsequences(nums = [0,1,2,2])
    >>> 3
    Explanation: The special subsequences are bolded [0,1,2,2], [0,1,2,2], and [0,1,2,2].
    
    Example 2:
    
    >>> countSpecialSubsequences(nums = [2,2,0,0])
    >>> 0
    Explanation: There are no special subsequences in [2,2,0,0].
    
    Example 3:
    
    >>> countSpecialSubsequences(nums = [0,1,2,0,1,2])
    >>> 7
    Explanation: The special subsequences are bolded:
    - [0,1,2,0,1,2]
    - [0,1,2,0,1,2]
    - [0,1,2,0,1,2]
    - [0,1,2,0,1,2]
    - [0,1,2,0,1,2]
    - [0,1,2,0,1,2]
    - [0,1,2,0,1,2]
    """
def minDayskVariants(points: List[List[int]], k: int) -> int:
    """
    There are n unique virus variants in an infinite 2D grid. You are given a 2D array points, where points[i] = [xi, yi] represents a virus originating at (xi, yi) on day 0. Note that it is possible for multiple virus variants to originate at the same point.
    Every day, each cell infected with a virus variant will spread the virus to all neighboring points in the four cardinal directions (i.e. up, down, left, and right). If a cell has multiple variants, all the variants will spread without interfering with each other.
    Given an integer k, return the minimum integer number of days for any point to contain at least k of the unique virus variants.
    
    Example 1:
    
    
    >>> minDayskVariants(points = [[1,1],[6,1]], k = 2)
    >>> 3
    Explanation: On day 3, points (3,1) and (4,1) will contain both virus variants. Note that these are not the only points that will contain both virus variants.
    
    Example 2:
    
    
    >>> minDayskVariants(points = [[3,3],[1,2],[9,2]], k = 2)
    >>> 2
    Explanation: On day 2, points (1,3), (2,3), (2,2), and (3,2) will contain the first two viruses. Note that these are not the only points that will contain both virus variants.
    
    Example 3:
    
    
    >>> minDayskVariants(points = [[3,3],[1,2],[9,2]], k = 3)
    >>> 4
    Explanation: On day 4, the point (5,2) will contain all 3 viruses. Note that this is not the only point that will contain all 3 virus variants.
    """