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 an array of integers. Write a function to find the first non-repeating element in the array.", "input": "An array of integers.", "output": "The first non-repeating element in the input array, or -1 if every element repeats.", "examples": [ { "input": "[4, 5, 1, 2, 0, 4]", "output": "5", "explanation": "The element 5 is the first non-repeating element." }, { "input": "[1, 2, 3, 4, 1, 2, 3]", "output": "4", "explanation": "The element 4 is the first non-repeating element." }, { "input": "[7, 7, 8, 8, 8, 9, 9]", "output": "-1", "explanation": "All elements repeat, hence no non-repeating element." }, { "input": "[11, 22, 33, 11, 22, 44]", "output": "33", "explanation": "The element 33 is the first non-repeating element." } ], "function_signature": "def first_non_repeating(arr):", "solution": { "code": " element_count = {}\n for num in arr:\n element_count[num] = element_count.get(num, 0) + 1\n for num in arr:\n if element_count[num] == 1:\n return num\n return -1" } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.