# server/tasks/task_easy.py TASK_EASY = { "task_id": "task_easy", "difficulty": "easy", "num_tests": 4, "description": ( "Fix the off-by-one error in the `find_max_subarray_sum` function. " "It should return the maximum contiguous subarray sum (Kadane's algorithm). " "Currently it misses the last element." ), # The broken version the agent sees "buggy_code": """\ def find_max_subarray_sum(nums: list[int]) -> int: if not nums: return 0 max_sum = current_sum = nums[0] # BUG: range stops one short for i in range(1, len(nums) - 1): current_sum = max(nums[i], current_sum + nums[i]) max_sum = max(max_sum, current_sum) return max_sum """, # The correct solution (used by task_generator) "clean_code": """\ def find_max_subarray_sum(nums: list[int]) -> int: if not nums: return 0 max_sum = current_sum = nums[0] for i in range(1, len(nums)): current_sum = max(nums[i], current_sum + nums[i]) max_sum = max(max_sum, current_sum) return max_sum """, # Hidden test suite — agent never sees this directly "test_suite": """\ def test_basic(): assert find_max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == 6 def test_all_negative(): assert find_max_subarray_sum([-3, -1, -2]) == -1 def test_single(): assert find_max_subarray_sum([42]) == 42 def test_empty(): assert find_max_subarray_sum([]) == 0 """, }