Skip to content
🤔prompts chat🧠
🔍
question:def maxCompleteRecipes(ingredients, stock): Given the ingredient requirements and available stock, return the maximum number of complete recipes that can be prepared. :param ingredients: List of integers representing the amount of each ingredient required for one recipe. :param stock: List of integers representing the available amount of each ingredient. :return: Maximum number of complete recipes possible. pass # Test cases def test_basic_case(): ingredients = [2, 3, 5] stock = [10, 15, 25] assert maxCompleteRecipes(ingredients, stock) == 5 def test_zero_stock(): ingredients = [1, 1, 1] stock = [0, 0, 0] assert maxCompleteRecipes(ingredients, stock) == 0 def test_zero_ingredients(): ingredients = [0, 0, 0] stock = [10, 15, 25] assert maxCompleteRecipes(ingredients, stock) == 0 def test_mixed_case(): ingredients = [1, 2, 3] stock = [3, 6, 9] assert maxCompleteRecipes(ingredients, stock) == 3 def test_insufficient_stock(): ingredients = [2, 4, 6] stock = [10, 7, 6] assert maxCompleteRecipes(ingredients, stock) == 1 def test_large_numbers(): ingredients = [1000000, 2000000, 3000000] stock = [1000000000, 2000000000, 3000000000] assert maxCompleteRecipes(ingredients, stock) == 1000 def test_different_lengths(): ingredients = [1, 2, 3] stock = [3, 6] # Different length test assert maxCompleteRecipes(ingredients, stock) == 0

answer:def maxCompleteRecipes(ingredients, stock): Given the ingredient requirements and available stock, return the maximum number of complete recipes that can be prepared. :param ingredients: List of integers representing the amount of each ingredient required for one recipe. :param stock: List of integers representing the available amount of each ingredient. :return: Maximum number of complete recipes possible. if not ingredients or not stock or len(ingredients) != len(stock): return 0 # Find the maximum number of times we can use each ingredient max_recipes = float('inf') for i in range(len(ingredients)): if ingredients[i] == 0: continue # If no ingredient is required, skip it max_possible = stock[i] // ingredients[i] max_recipes = min(max_recipes, max_possible) return max_recipes if max_recipes != float('inf') else 0

question:def findMaxLength(nums: List[int]) -> int: Returns the length of the longest contiguous subarray with an equal number of 1s and 0s. >>> findMaxLength([0, 1]) 2 >>> findMaxLength([0, 1, 0]) 2 >>> findMaxLength([0, 1, 0, 1, 0, 1]) 6 >>> findMaxLength([0, 0, 0, 1, 1]) 4 >>> findMaxLength([1, 1, 1]) 0 >>> findMaxLength([1]) 0 >>> findMaxLength([0]) 0 >>> findMaxLength([]) 0

answer:def findMaxLength(nums): Returns the length of the longest contiguous subarray with an equal number of 1s and 0s. count = 0 max_len = 0 count_map = {0: -1} for i in range(len(nums)): count += 1 if nums[i] == 1 else -1 if count in count_map: max_len = max(max_len, i - count_map[count]) else: count_map[count] = i return max_len

question:def minCoins(coins, amount): Returns the minimum number of coins needed to make the total value of 'amount'. If it is not possible to make the amount with the given coins, returns -1. :param coins: List of positive integers representing the coin values. :param amount: Integer representing the target amount. :return: Minimum number of coins needed, or -1 if the amount cannot be formed. >>> minCoins([1, 2, 5], 11) 3 >>> minCoins([2], 3) -1 >>> minCoins([1, 2, 3], 6) 2 >>> minCoins([1], 0) 0 >>> minCoins([2], 1) -1 >>> minCoins([2, 4], 7) -1 >>> minCoins([], 0) 0 >>> minCoins([1], 1) 1 >>> minCoins([1], 5) 5 >>> minCoins([1, 2, 5], 100) 20 >>> minCoins([3], 9) 3 >>> minCoins([10], 30) 3 >>> minCoins([1, 5, 10, 25], 63) 6

answer:def minCoins(coins, amount): Returns the minimum number of coins needed to make the total value of 'amount'. If it is not possible to make the amount with the given coins, returns -1. :param coins: List of positive integers representing the coin values. :param amount: Integer representing the target amount. :return: Minimum number of coins needed, or -1 if the amount cannot be formed. # DP array to store the minimum coins needed for each amount from 0 to amount dp = [float('inf')] * (amount + 1) dp[0] = 0 # Base case: 0 coins to make the amount 0 # Update dp array for each coin for coin in coins: for x in range(coin, amount + 1): dp[x] = min(dp[x], dp[x - coin] + 1) return dp[amount] if dp[amount] != float('inf') else -1

question:def count_paths_with_target_sum(matrix, target): Returns the number of distinct paths from the top-left to the bottom-right cell of the matrix such that the sum of the integers along the path equals the target. You can only move right or down from a cell. Args: matrix (List[List[int]]): The m x n matrix filled with integers. target (int): The target sum. Returns: int: The number of distinct paths where the sum of the integers along the path equals the target. >>> count_paths_with_target_sum([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 21) == 1 >>> count_paths_with_target_sum([[1, 2, 3], [4, 2, 2], [1, 1, 1]], 9) == 2 >>> count_paths_with_target_sum([[1, 2], [1, 2]], 10) == 0 >>> count_paths_with_target_sum([[5]], 5) == 1 >>> count_paths_with_target_sum([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 100) == 0 pass

answer:def count_paths_with_target_sum(matrix, target): Returns the number of distinct paths from the top-left to the bottom-right cell of the matrix such that the sum of the integers along the path equals the target. You can only move right or down from a cell. m, n = len(matrix), len(matrix[0]) # Memoization dictionary memo = {} def dfs(r, c, path_sum): if r == m-1 and c == n-1: return 1 if path_sum + matrix[r][c] == target else 0 if (r, c, path_sum) in memo: return memo[(r, c, path_sum)] total_paths = 0 if r < m - 1: total_paths += dfs(r + 1, c, path_sum + matrix[r][c]) if c < n - 1: total_paths += dfs(r, c + 1, path_sum + matrix[r][c]) memo[(r, c, path_sum)] = total_paths return total_paths return dfs(0, 0, 0)

Released under the chat License.

has loaded