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": "Write a function to determine if a given string is a permutation of a palindrome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words.", "input": "A string consisting of alphabetical characters and optional spaces.", "output": "A boolean value indicating whether the input string is a permutation of a palindrome.", "examples": [ { "input": "'Tact Coa'", "output": "True", "explanation": "The string 'Tact Coa' is a permutation of 'taco cat', which is a palindrome." }, { "input": "'A man a plan a canal Panama'", "output": "True", "explanation": "The string is a permutation of the palindrome 'amanaplanacanalpanama'." }, { "input": "'abc'", "output": "False", "explanation": "No permutation of 'abc' forms a palindrome." }, { "input": "'racecar'", "output": "True", "explanation": "The string 'racecar' is already a palindrome." } ], "function_signature": "def is_permutation_of_palindrome(s):", "solution": { "code": " from collections import Counter\n s = s.replace(' ', '').lower()\n char_count = Counter(s)\n odd_count = 0\n for count in char_count.values():\n if count % 2 != 0:\n odd_count += 1\n if odd_count > 1:\n return False\n return True" } }
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 →