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 string consisting of lowercase letters. Write a function to find the length of the longest substring without repeating characters.", "input": "A string consisting of lowercase letters.", "output": "The length of the longest substring without repeating characters.", "examples": [ { "input": ""abcabcbb"", "output": "3", "explanation": "The substring "abc" is the longest substring without repeating characters, with a length of 3." }, { "input": ""bbbbb"", "output": "1", "explanation": "The substring "b" is the longest substring without repeating characters, with a length of 1." }, { "input": ""pwwkew"", "output": "3", "explanation": "The substring "wke" is the longest substring without repeating characters, with a length of 3." }, { "input": """", "output": "0", "explanation": "The input string is empty, so the longest substring without repeating characters is 0." } ], "function_signature": "def longest_unique_substring(s):", "solution": { "code": " char_index = {}\n max_length = 0\n start = 0\n for end, char in enumerate(s):\n if char in char_index and char_index[char] >= start:\n start = char_index[char] + 1\n char_index[char] = end\n max_length = max(max_length, end - start + 1)\n return max_length" } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- gpt-4o-2024-08-06Compare side by side →
- gpt-4o-2024-08-06Compare side by side →
- gpt-4o-2024-08-06Compare side by side →
- gpt-4o-2024-08-06Compare side by side →
- gpt-4o-2024-08-06Compare side by side →
- gpt-4o-2024-08-06Compare side by side →
- gpt-4o-2024-08-06Compare side by side →
- gpt-4o-2024-08-06Compare side by side →
- gpt-4o-2024-08-06Compare side by side →