Create a programming task related to common algorithms and data…
- User
Assistant: User: Create a programming task related to common algorithms and data structures. The task should follow this format:
{ "problem_description": "You are given an array of integers. Write a function to find the maximum sum of a subarray within the array.", "input": "An array of integers.", "output": "The maximum sum of a subarray within the input array.", "examples": [ { "input": "[-2, 1, -3, 4, -1, 2, 1, -5, 4]", "output": "6", "explanation": "The subarray [4, -1, 2, 1] has the maximum sum of 6." }, { "input": "[1, 2, 3, 4, -10, 5, 6]", "output": "15", "explanation": "The subarray [1, 2, 3, 4, -10, 5, 6] has the maximum sum of 15." }, { "input": "[5, 4, -1, 7, 8]", "output": "23", "explanation": "The subarray [5, 4, -1, 7, 8] has the maximum sum of 23." }, { "input": "[-1, -2, -3, -4]", "output": "-1", "explanation": "The subarray [-1] has the maximum sum of -1." } ], "function_signature": "def max_subarray_sum(arr):", "solution": { "code": " max_sum = float('-inf') current_sum = 0 for num in arr: current_sum += num if current_sum > max_sum: max_sum = current_sum if current_sum < 0: current_sum = 0 return max_sum" } }
Assistant:
- Assistant
{ "problem_description": "You are given a binary tree represented as a series of nested lists. Write a function to determine the maximum depth of the binary tree.", "input": "A binary tree represented as a nested list where each node is represented by [value, left_subtree, right_subtree]. An empty tree or leaf node is represented by an empty list [].", "output": "The maximum depth of the binary tree.", "examples": [ { "input": "[3, [9, [], []], [20, [15, [], []], [7, [], []]]]", "output": "3", "explanation": "The binary tree has a maximum depth of 3." }, { "input": "[1, [2, [4, [], []], []], [3, [], []]]", "output": "3", "explanation": "The binary tree has a maximum depth of 3." }, { "input": "[5, [], []]", "output": "1", "explanation": "The binary tree has a maximum depth of 1." }, { "input": "[]", "output": "0", "explanation": "An empty binary tree has a depth of 0." } ], "function_signature": "def max_binary_tree_depth(tree):", "solution": { "code": "def max_binary_tree_depth(tree):\n if not tree:\n return 0\n value, left, right = tree\n left_depth = max_binary_tree_depth(left)\n right_depth = max_binary_tree_depth(right)\n return 1 + max(left_depth, right_depth)" } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.