ShwStone/humaneval-leetcode huggingface dataset:
def shortestDistanceColor(colors: List[int], queries: List[List[int]]) -> List[int]:
    """
    You are given an array colors, in which there are three colors: 1, 2 and 3.
    You are also given some queries. Each query consists of two integers i and c, return the shortest distance between the given index i and the target color c. If there is no solution return -1.
    
    Example 1:
    
    >>> shortestDistanceColor(colors = [1,1,2,1,3,2,2,3,3], queries = [[1,3],[2,2],[6,1]])
    >>> [3,0,3]
    Explanation:
    The nearest 3 from index 1 is at index 4 (3 steps away).
    The nearest 2 from index 2 is at index 2 itself (0 steps away).
    The nearest 1 from index 6 is at index 3 (3 steps away).
    
    Example 2:
    
    >>> shortestDistanceColor(colors = [1,2], queries = [[0,3]])
    >>> [-1]
    Explanation: There is no 3 in the array.
    """
def maximumNumberOfOnes(width: int, height: int, sideLength: int, maxOnes: int) -> int:
    """
    Consider a matrix M with dimensions width * height, such that every cell has value 0 or 1, and any square sub-matrix of M of size sideLength * sideLength has at most maxOnes ones.
    Return the maximum possible number of ones that the matrix M can have.
    
    Example 1:
    
    >>> maximumNumberOfOnes(width = 3, height = 3, sideLength = 2, maxOnes = 1)
    >>> 4
    Explanation:
    In a 3*3 matrix, no 2*2 sub-matrix can have more than 1 one.
    The best solution that has 4 ones is:
    [1,0,1]
    [0,0,0]
    [1,0,1]
    
    Example 2:
    
    >>> maximumNumberOfOnes(width = 3, height = 3, sideLength = 2, maxOnes = 2)
    >>> 6
    Explanation:
    [1,0,1]
    [1,0,1]
    [1,0,1]
    """
def distanceBetweenBusStops(distance: List[int], start: int, destination: int) -> int:
    """
    A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.\r
    \r
    The bus goes along both directions i.e. clockwise and counterclockwise.\r
    \r
    Return the shortest distance between the given start and destination stops.\r
    \r
     \r
    Example 1:\r
    \r
    \r
    \r
    \r
    >>> distanceBetweenBusStops(distance = [1,2,3,4], start = 0, destination = 1\r)
    >>> 1\r
    Explanation: Distance between 0 and 1 is 1 or 9, minimum is 1.\r
    \r
     \r
    \r
    Example 2:\r
    \r
    \r
    \r
    \r
    >>> distanceBetweenBusStops(distance = [1,2,3,4], start = 0, destination = 2\r)
    >>> 3\r
    Explanation: Distance between 0 and 2 is 3 or 7, minimum is 3.\r
    \r
    \r
     \r
    \r
    Example 3:\r
    \r
    \r
    \r
    \r
    >>> distanceBetweenBusStops(distance = [1,2,3,4], start = 0, destination = 3\r)
    >>> 4\r
    Explanation: Distance between 0 and 3 is 6 or 4, minimum is 4.\r
    \r
    \r
     \r
    """
def dayOfTheWeek(day: int, month: int, year: int) -> str:
    """
    Given a date, return the corresponding day of the week for that date.
    The input is given as three integers representing the day, month and year respectively.
    Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.
    
    Example 1:
    
    >>> dayOfTheWeek(day = 31, month = 8, year = 2019)
    >>> "Saturday"
    
    Example 2:
    
    >>> dayOfTheWeek(day = 18, month = 7, year = 1999)
    >>> "Sunday"
    
    Example 3:
    
    >>> dayOfTheWeek(day = 15, month = 8, year = 1993)
    >>> "Sunday"
    """
def maximumSum(arr: List[int]) -> int:
    """
    Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maximum possible.
    Note that the subarray needs to be non-empty after deleting one element.
    
    Example 1:
    
    >>> maximumSum(arr = [1,-2,0,3])
    >>> 4
    Explanation: Because we can choose [1, -2, 0, 3] and drop -2, thus the subarray [1, 0, 3] becomes the maximum value.
    Example 2:
    
    >>> maximumSum(arr = [1,-2,-2,3])
    >>> 3
    Explanation: We just choose [3] and it's the maximum sum.
    
    Example 3:
    
    >>> maximumSum(arr = [-1,-1,-1,-1])
    >>> -1
    Explanation: The final subarray needs to be non-empty. You can't choose [-1] and delete -1 from it, then get an empty subarray to make the sum equals to 0.
    """
def makeArrayIncreasing(arr1: List[int], arr2: List[int]) -> int:
    """
    Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing.
    In one operation, you can choose two indices 0 <= i < arr1.length and 0 <= j < arr2.length and do the assignment arr1[i] = arr2[j].
    If there is no way to make arr1 strictly increasing, return -1.
    
    Example 1:
    
    >>> makeArrayIncreasing(arr1 = [1,5,3,6,7], arr2 = [1,3,2,4])
    >>> 1
    Explanation: Replace 5 with 2, then arr1 = [1, 2, 3, 6, 7].
    
    Example 2:
    
    >>> makeArrayIncreasing(arr1 = [1,5,3,6,7], arr2 = [4,3,1])
    >>> 2
    Explanation: Replace 5 with 3 and then replace 3 with 4. arr1 = [1, 3, 4, 6, 7].
    
    Example 3:
    
    >>> makeArrayIncreasing(arr1 = [1,5,3,6,7], arr2 = [1,6,3,3])
    >>> -1
    Explanation: You can't make arr1 strictly increasing.
    """
def maxNumberOfBalloons(text: str) -> int:
    """
    Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.
    You can use each character in text at most once. Return the maximum number of instances that can be formed.
    
    Example 1:
    
    
    >>> maxNumberOfBalloons(text = "nlaebolko")
    >>> 1
    
    Example 2:
    
    
    >>> maxNumberOfBalloons(text = "loonbalxballpoon")
    >>> 2
    
    Example 3:
    
    >>> maxNumberOfBalloons(text = "leetcode")
    >>> 0
    """
def reverseParentheses(s: str) -> str:
    """
    You are given a string s that consists of lower case English letters and brackets.
    Reverse the strings in each pair of matching parentheses, starting from the innermost one.
    Your result should not contain any brackets.
    
    Example 1:
    
    >>> reverseParentheses(s = "(abcd)")
    >>> "dcba"
    
    Example 2:
    
    >>> reverseParentheses(s = "(u(love)i)")
    >>> "iloveu"
    Explanation: The substring "love" is reversed first, then the whole string is reversed.
    
    Example 3:
    
    >>> reverseParentheses(s = "(ed(et(oc))el)")
    >>> "leetcode"
    Explanation: First, we reverse the substring "oc", then "etco", and finally, the whole string.
    """
def kConcatenationMaxSum(arr: List[int], k: int) -> int:
    """
    Given an integer array arr and an integer k, modify the array by repeating it k times.
    For example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2].
    Return the maximum sub-array sum in the modified array. Note that the length of the sub-array can be 0 and its sum in that case is 0.
    As the answer can be very large, return the answer modulo 109 + 7.
    
    Example 1:
    
    >>> kConcatenationMaxSum(arr = [1,2], k = 3)
    >>> 9
    
    Example 2:
    
    >>> kConcatenationMaxSum(arr = [1,-2,1], k = 5)
    >>> 2
    
    Example 3:
    
    >>> kConcatenationMaxSum(arr = [-1,-2], k = 7)
    >>> 0
    """
def criticalConnections(n: int, connections: List[List[int]]) -> List[List[int]]:
    """
    There are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network where connections[i] = [ai, bi] represents a connection between servers ai and bi. Any server can reach other servers directly or indirectly through the network.
    A critical connection is a connection that, if removed, will make some servers unable to reach some other server.
    Return all critical connections in the network in any order.
    
    Example 1:
    
    
    >>> criticalConnections(n = 4, connections = [[0,1],[1,2],[2,0],[1,3]])
    >>> [[1,3]]
    Explanation: [[3,1]] is also accepted.
    
    Example 2:
    
    >>> criticalConnections(n = 2, connections = [[0,1]])
    >>> [[0,1]]
    """
def maxNumberOfApples(weight: List[int]) -> int:
    """
    You have some apples and a basket that can carry up to 5000 units of weight.
    Given an integer array weight where weight[i] is the weight of the ith apple, return the maximum number of apples you can put in the basket.
    
    Example 1:
    
    >>> maxNumberOfApples(weight = [100,200,150,1000])
    >>> 4
    Explanation: All 4 apples can be carried by the basket since their sum of weights is 1450.
    
    Example 2:
    
    >>> maxNumberOfApples(weight = [900,950,800,1000,700,800])
    >>> 5
    Explanation: The sum of weights of the 6 apples exceeds 5000 so we choose any 5 of them.
    """
def minKnightMoves(x: int, y: int) -> int:
    """
    In an infinite chess board with coordinates from -infinity to +infinity, you have a knight at square [0, 0].
    A knight has 8 possible moves it can make, as illustrated below. Each move is two squares in a cardinal direction, then one square in an orthogonal direction.
    
    Return the minimum number of steps needed to move the knight to the square [x, y]. It is guaranteed the answer exists.
    
    Example 1:
    
    >>> minKnightMoves(x = 2, y = 1)
    >>> 1
    Explanation: [0, 0] → [2, 1]
    
    Example 2:
    
    >>> minKnightMoves(x = 5, y = 5)
    >>> 4
    Explanation: [0, 0] → [2, 1] → [4, 2] → [3, 4] → [5, 5]
    """
def smallestCommonElement(mat: List[List[int]]) -> int:
    """
    Given an m x n matrix mat where every row is sorted in strictly increasing order, return the smallest common element in all rows.
    If there is no common element, return -1.
    
    Example 1:
    
    >>> smallestCommonElement(mat = [[1,2,3,4,5],[2,4,5,8,10],[3,5,7,9,11],[1,3,5,7,9]])
    >>> 5
    
    Example 2:
    
    >>> smallestCommonElement(mat = [[1,2,3],[2,3,4],[2,3,5]])
    >>> 2
    """
def minBuildTime(blocks: List[int], split: int) -> int:
    """
    You are given a list of blocks, where blocks[i] = t means that the i-th block needs t units of time to be built. A block can only be built by exactly one worker.
    A worker can either split into two workers (number of workers increases by one) or build a block then go home. Both decisions cost some time.
    The time cost of spliting one worker into two workers is given as an integer split. Note that if two workers split at the same time, they split in parallel so the cost would be split.
    Output the minimum time needed to build all blocks.
    Initially, there is only one worker.
    
    Example 1:
    
    >>> minBuildTime(blocks = [1], split = 1)
    >>> 1
    Explanation: We use 1 worker to build 1 block in 1 time unit.
    
    Example 2:
    
    >>> minBuildTime(blocks = [1,2], split = 5)
    >>> 7
    Explanation: We split the worker into 2 workers in 5 time units then assign each of them to a block so the cost is 5 + max(1, 2) = 7.
    
    Example 3:
    
    >>> minBuildTime(blocks = [1,2,3], split = 1)
    >>> 4
    Explanation: Split 1 worker into 2, then assign the first worker to the last block and split the second worker into 2.
    Then, use the two unassigned workers to build the first two blocks.
    The cost is 1 + max(3, 1 + max(1, 2)) = 4.
    """
def minimumAbsDifference(arr: List[int]) -> List[List[int]]:
    """
    Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements.
    Return a list of pairs in ascending order(with respect to pairs), each pair [a, b] follows
    
    a, b are from arr
    a < b
    b - a equals to the minimum absolute difference of any two elements in arr
    
    
    Example 1:
    
    >>> minimumAbsDifference(arr = [4,2,1,3])
    >>> [[1,2],[2,3],[3,4]]
    Explanation: The minimum absolute difference is 1. List all pairs with difference equal to 1 in ascending order.
    Example 2:
    
    >>> minimumAbsDifference(arr = [1,3,6,10,15])
    >>> [[1,3]]
    
    Example 3:
    
    >>> minimumAbsDifference(arr = [3,8,-10,23,19,-4,-14,27])
    >>> [[-14,-10],[19,23],[23,27]]
    """
def nthUglyNumber(n: int, a: int, b: int, c: int) -> int:
    """
    An ugly number is a positive integer that is divisible by a, b, or c.
    Given four integers n, a, b, and c, return the nth ugly number.
    
    Example 1:
    
    >>> nthUglyNumber(n = 3, a = 2, b = 3, c = 5)
    >>> 4
    Explanation: The ugly numbers are 2, 3, 4, 5, 6, 8, 9, 10... The 3rd is 4.
    
    Example 2:
    
    >>> nthUglyNumber(n = 4, a = 2, b = 3, c = 4)
    >>> 6
    Explanation: The ugly numbers are 2, 3, 4, 6, 8, 9, 10, 12... The 4th is 6.
    
    Example 3:
    
    >>> nthUglyNumber(n = 5, a = 2, b = 11, c = 13)
    >>> 10
    Explanation: The ugly numbers are 2, 4, 6, 8, 10, 11, 12, 13... The 5th is 10.
    """
def smallestStringWithSwaps(s: str, pairs: List[List[int]]) -> str:
    """
    You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string.
    You can swap the characters at any pair of indices in the given pairs any number of times.
    Return the lexicographically smallest string that s can be changed to after using the swaps.
    
    Example 1:
    
    >>> smallestStringWithSwaps(s = "dcab", pairs = [[0,3],[1,2]])
    >>> "bacd"
    Explaination:
    Swap s[0] and s[3], s = "bcad"
    Swap s[1] and s[2], s = "bacd"
    
    Example 2:
    
    >>> smallestStringWithSwaps(s = "dcab", pairs = [[0,3],[1,2],[0,2]])
    >>> "abcd"
    Explaination:
    Swap s[0] and s[3], s = "bcad"
    Swap s[0] and s[2], s = "acbd"
    Swap s[1] and s[2], s = "abcd"
    Example 3:
    
    >>> smallestStringWithSwaps(s = "cba", pairs = [[0,1],[1,2]])
    >>> "abc"
    Explaination:
    Swap s[0] and s[1], s = "bca"
    Swap s[1] and s[2], s = "bac"
    Swap s[0] and s[1], s = "abc"
    """
def sortItems(n: int, m: int, group: List[int], beforeItems: List[List[int]]) -> List[int]:
    """
    There are n items each belonging to zero or one of m groups where group[i] is the group that the i-th item belongs to and it's equal to -1 if the i-th item belongs to no group. The items and the groups are zero indexed. A group can have no item belonging to it.
    Return a sorted list of the items such that:
    
    The items that belong to the same group are next to each other in the sorted list.
    There are some relations between these items where beforeItems[i] is a list containing all the items that should come before the i-th item in the sorted array (to the left of the i-th item).
    
    Return any solution if there is more than one solution and return an empty list if there is no solution.
    
    Example 1:
    
    
    >>> sortItems(n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]])
    >>> [6,3,4,1,5,2,0,7]
    
    Example 2:
    
    >>> sortItems(n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]])
    >>> []
    Explanation: This is the same as example 1 except that 4 needs to be before 6 in the sorted list.
    """
def uniqueOccurrences(arr: List[int]) -> bool:
    """
    Given an array of integers arr, return true if the number of occurrences of each value in the array is unique or false otherwise.
    
    Example 1:
    
    >>> uniqueOccurrences(arr = [1,2,2,1,1,3])
    >>> true
    Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.
    Example 2:
    
    >>> uniqueOccurrences(arr = [1,2])
    >>> false
    
    Example 3:
    
    >>> uniqueOccurrences(arr = [-3,0,1,-3,1,1,1,-3,10,0])
    >>> true
    """
def equalSubstring(s: str, t: str, maxCost: int) -> int:
    """
    You are given two strings s and t of the same length and an integer maxCost.
    You want to change s to t. Changing the ith character of s to ith character of t costs |s[i] - t[i]| (i.e., the absolute difference between the ASCII values of the characters).
    Return the maximum length of a substring of s that can be changed to be the same as the corresponding substring of t with a cost less than or equal to maxCost. If there is no substring from s that can be changed to its corresponding substring from t, return 0.
    
    Example 1:
    
    >>> equalSubstring(s = "abcd", t = "bcdf", maxCost = 3)
    >>> 3
    Explanation: "abc" of s can change to "bcd".
    That costs 3, so the maximum length is 3.
    
    Example 2:
    
    >>> equalSubstring(s = "abcd", t = "cdef", maxCost = 3)
    >>> 1
    Explanation: Each character in s costs 2 to change to character in t,  so the maximum length is 1.
    
    Example 3:
    
    >>> equalSubstring(s = "abcd", t = "acde", maxCost = 0)
    >>> 1
    Explanation: You cannot make any change, so the maximum length is 1.
    """
def removeDuplicates(s: str, k: int) -> str:
    """
    You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together.
    We repeatedly make k duplicate removals on s until we no longer can.
    Return the final string after all such duplicate removals have been made. It is guaranteed that the answer is unique.
    
    Example 1:
    
    >>> removeDuplicates(s = "abcd", k = 2)
    >>> "abcd"
    Explanation: There's nothing to delete.
    Example 2:
    
    >>> removeDuplicates(s = "deeedbbcccbdaa", k = 3)
    >>> "aa"
    Explanation:
    First delete "eee" and "ccc", get "ddbbbdaa"
    Then delete "bbb", get "dddaa"
    Finally delete "ddd", get "aa"
    Example 3:
    
    >>> removeDuplicates(s = "pbbcggttciiippooaais", k = 2)
    >>> "ps"
    """
def minimumMoves(grid: List[List[int]]) -> int:
    """
    In an n*n grid, there is a snake that spans 2 cells and starts moving from the top left corner at (0, 0) and (0, 1). The grid has empty cells represented by zeros and blocked cells represented by ones. The snake wants to reach the lower right corner at (n-1, n-2) and (n-1, n-1).
    In one move the snake can:
    
    Move one cell to the right if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is.
    Move down one cell if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is.
    Rotate clockwise if it's in a horizontal position and the two cells under it are both empty. In that case the snake moves from (r, c) and (r, c+1) to (r, c) and (r+1, c).
    
    Rotate counterclockwise if it's in a vertical position and the two cells to its right are both empty. In that case the snake moves from (r, c) and (r+1, c) to (r, c) and (r, c+1).
    
    
    Return the minimum number of moves to reach the target.
    If there is no way to reach the target, return -1.
    
    Example 1:
    
    
                   [1,1,0,0,1,0],
                   [0,0,0,0,1,1],
                   [0,0,1,0,1,0],
                   [0,1,1,0,0,0],
                   [0,1,1,0,0,0]]
    >>> minimumMoves(grid = [[0,0,0,0,0,1],)
    >>> 11
    Explanation:
    One possible solution is [right, right, rotate clockwise, right, down, down, down, down, rotate counterclockwise, right, down].
    
    Example 2:
    
                   [0,0,0,0,1,1],
                   [1,1,0,0,0,1],
                   [1,1,1,0,0,1],
                   [1,1,1,0,0,1],
                   [1,1,1,0,0,0]]
    >>> minimumMoves(grid = [[0,0,1,1,1,1],)
    >>> 9
    """
def arraysIntersection(arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:
    """
    Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a sorted array of only the integers that appeared in all three arrays.
    
    Example 1:
    
    >>> arraysIntersection(arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8])
    >>> [1,5]
    Explanation: Only 1 and 5 appeared in the three arrays.
    
    Example 2:
    
    >>> arraysIntersection(arr1 = [197,418,523,876,1356], arr2 = [501,880,1593,1710,1870], arr3 = [521,682,1337,1395,1764])
    >>> []
    """
# class TreeNode:
#     def __init__(val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def twoSumBSTs(root1: Optional[TreeNode], root2: Optional[TreeNode], target: int) -> bool:
    """
    Given the roots of two binary search trees, root1 and root2, return true if and only if there is a node in the first tree and a node in the second tree whose values sum up to a given integer target.
    
    Example 1:
    
    
    >>> __init__(root1 = [2,1,4], root2 = [1,0,3], target = 5)
    >>> true
    Explanation: 2 and 3 sum up to 5.
    
    Example 2:
    
    
    >>> __init__(root1 = [0,-10,10], root2 = [5,1,7,0,2], target = 18)
    >>> false
    """
def countSteppingNumbers(low: int, high: int) -> List[int]:
    """
    A stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1.
    
    For example, 321 is a stepping number while 421 is not.
    
    Given two integers low and high, return a sorted list of all the stepping numbers in the inclusive range [low, high].
    
    Example 1:
    
    >>> countSteppingNumbers(low = 0, high = 21)
    >>> [0,1,2,3,4,5,6,7,8,9,10,12,21]
    
    Example 2:
    
    >>> countSteppingNumbers(low = 10, high = 15)
    >>> [10,12]
    """
def isValidPalindrome(s: str, k: int) -> bool:
    """
    Given a string s and an integer k, return true if s is a k-palindrome.
    A string is k-palindrome if it can be transformed into a palindrome by removing at most k characters from it.
    
    Example 1:
    
    >>> isValidPalindrome(s = "abcdeca", k = 2)
    >>> true
    Explanation: Remove 'b' and 'e' characters.
    
    Example 2:
    
    >>> isValidPalindrome(s = "abbababa", k = 1)
    >>> true
    """
def minCostToMoveChips(position: List[int]) -> int:
    """
    We have n chips, where the position of the ith chip is position[i].
    We need to move all the chips to the same position. In one step, we can change the position of the ith chip from position[i] to:
    
    position[i] + 2 or position[i] - 2 with cost = 0.
    position[i] + 1 or position[i] - 1 with cost = 1.
    
    Return the minimum cost needed to move all the chips to the same position.
    
    Example 1:
    
    
    >>> minCostToMoveChips(position = [1,2,3])
    >>> 1
    Explanation: First step: Move the chip at position 3 to position 1 with cost = 0.
    Second step: Move the chip at position 2 to position 1 with cost = 1.
    Total cost is 1.
    
    Example 2:
    
    
    >>> minCostToMoveChips(position = [2,2,2,3,3])
    >>> 2
    Explanation: We can move the two chips at position  3 to position 2. Each move has cost = 1. The total cost = 2.
    
    Example 3:
    
    >>> minCostToMoveChips(position = [1,1000000000])
    >>> 1
    """
def longestSubsequence(arr: List[int], difference: int) -> int:
    """
    Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference.
    A subsequence is a sequence that can be derived from arr by deleting some or no elements without changing the order of the remaining elements.
    
    Example 1:
    
    >>> longestSubsequence(arr = [1,2,3,4], difference = 1)
    >>> 4
    Explanation: The longest arithmetic subsequence is [1,2,3,4].
    Example 2:
    
    >>> longestSubsequence(arr = [1,3,5,7], difference = 1)
    >>> 1
    Explanation: The longest arithmetic subsequence is any single element.
    
    Example 3:
    
    >>> longestSubsequence(arr = [1,5,7,8,5,3,4,2,1], difference = -2)
    >>> 4
    Explanation: The longest arithmetic subsequence is [7,5,3,1].
    """