PulipatiPranav
Curated the bugs dataset
85f14d3
t1_bugs = [
{
"id": "t1_009",
"difficulty": 1,
"bug_type": "off_by_one",
"function_name": "factorial",
"buggy_code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n)",
"original_code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)",
"initial_error": "RecursionError: maximum recursion depth exceeded",
"bug_location": {"function": "factorial", "line_start": 4},
"test_cases": [{"input": 0, "expected_output": 1}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 120}, {"input": 3, "expected_output": 6}]
},
{
"id": "t1_010",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "factorial",
"buggy_code": "def factorial(n):\n if n == 0:\n return 1\n return n + factorial(n - 1)",
"original_code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)",
"initial_error": "AssertionError: factorial(3) expected 6, got 6 - wait got 7",
"bug_location": {"function": "factorial", "line_start": 4},
"test_cases": [{"input": 0, "expected_output": 1}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 120}, {"input": 3, "expected_output": 6}]
},
{
"id": "t1_011",
"difficulty": 1,
"bug_type": "off_by_one",
"function_name": "fibonacci",
"buggy_code": "def fibonacci(n):\n if n < 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)",
"original_code": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)",
"initial_error": "RecursionError: maximum recursion depth exceeded",
"bug_location": {"function": "fibonacci", "line_start": 2},
"test_cases": [{"input": 0, "expected_output": 0}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 5}, {"input": 7, "expected_output": 13}]
},
{
"id": "t1_012",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "fibonacci",
"buggy_code": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) * fibonacci(n-2)",
"original_code": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)",
"initial_error": "AssertionError: fibonacci(5) expected 5, got 0",
"bug_location": {"function": "fibonacci", "line_start": 4},
"test_cases": [{"input": 0, "expected_output": 0}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 5}, {"input": 7, "expected_output": 13}]
},
{
"id": "t1_013",
"difficulty": 1,
"bug_type": "off_by_one",
"function_name": "string_reverse",
"buggy_code": "def string_reverse(s):\n return s[:-1]",
"original_code": "def string_reverse(s):\n return s[::-1]",
"initial_error": "AssertionError: string_reverse('hello') expected 'olleh', got 'hell'",
"bug_location": {"function": "string_reverse", "line_start": 2},
"test_cases": [{"input": "hello", "expected_output": "olleh"}, {"input": "", "expected_output": ""}, {"input": "a", "expected_output": "a"}, {"input": "racecar", "expected_output": "racecar"}]
},
{
"id": "t1_014",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "string_reverse",
"buggy_code": "def string_reverse(s):\n return s[1:]",
"original_code": "def string_reverse(s):\n return s[::-1]",
"initial_error": "AssertionError: string_reverse('hello') expected 'olleh', got 'ello'",
"bug_location": {"function": "string_reverse", "line_start": 2},
"test_cases": [{"input": "hello", "expected_output": "olleh"}, {"input": "", "expected_output": ""}, {"input": "a", "expected_output": "a"}, {"input": "racecar", "expected_output": "racecar"}]
},
{
"id": "t1_015",
"difficulty": 1,
"bug_type": "wrong_comparison",
"function_name": "count_occurrences",
"buggy_code": "def count_occurrences(lst, target):\n count = 0\n for item in lst:\n if item != target:\n count += 1\n return count",
"original_code": "def count_occurrences(lst, target):\n count = 0\n for item in lst:\n if item == target:\n count += 1\n return count",
"initial_error": "AssertionError: count_occurrences([1,2,1,3,1], 1) expected 3, got 2",
"bug_location": {"function": "count_occurrences", "line_start": 4},
"test_cases": [{"input": [[1,2,1,3,1], 1], "expected_output": 3}, {"input": [[], 5], "expected_output": 0}, {"input": [[2,2,2], 2], "expected_output": 3}, {"input": [[1,2,3], 4], "expected_output": 0}]
},
{
"id": "t1_016",
"difficulty": 1,
"bug_type": "off_by_one",
"function_name": "count_occurrences",
"buggy_code": "def count_occurrences(lst, target):\n count = 1\n for item in lst:\n if item == target:\n count += 1\n return count",
"original_code": "def count_occurrences(lst, target):\n count = 0\n for item in lst:\n if item == target:\n count += 1\n return count",
"initial_error": "AssertionError: count_occurrences([], 5) expected 0, got 1",
"bug_location": {"function": "count_occurrences", "line_start": 2},
"test_cases": [{"input": [[1,2,1,3,1], 1], "expected_output": 3}, {"input": [[], 5], "expected_output": 0}, {"input": [[2,2,2], 2], "expected_output": 3}, {"input": [[1,2,3], 4], "expected_output": 0}]
},
{
"id": "t1_017",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "sum_digits",
"buggy_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n // 10\n n //= 10\n return total",
"original_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n % 10\n n //= 10\n return total",
"initial_error": "AssertionError: sum_digits(123) expected 6, got 13",
"bug_location": {"function": "sum_digits", "line_start": 4},
"test_cases": [{"input": 123, "expected_output": 6}, {"input": 0, "expected_output": 0}, {"input": 999, "expected_output": 27}, {"input": 10, "expected_output": 1}]
},
{
"id": "t1_018",
"difficulty": 1,
"bug_type": "logic_inversion",
"function_name": "sum_digits",
"buggy_code": "def sum_digits(n):\n total = 0\n while n < 0:\n total += n % 10\n n //= 10\n return total",
"original_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n % 10\n n //= 10\n return total",
"initial_error": "AssertionError: sum_digits(123) expected 6, got 0",
"bug_location": {"function": "sum_digits", "line_start": 3},
"test_cases": [{"input": 123, "expected_output": 6}, {"input": 0, "expected_output": 0}, {"input": 999, "expected_output": 27}, {"input": 10, "expected_output": 1}]
},
{
"id": "t1_019",
"difficulty": 1,
"bug_type": "off_by_one",
"function_name": "is_prime",
"buggy_code": "def is_prime(n):\n if n < 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True",
"original_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True",
"initial_error": "AssertionError: is_prime(1) expected False, got True",
"bug_location": {"function": "is_prime", "line_start": 2},
"test_cases": [{"input": 2, "expected_output": True}, {"input": 4, "expected_output": False}, {"input": 13, "expected_output": True}, {"input": 1, "expected_output": False}]
},
{
"id": "t1_020",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "is_prime",
"buggy_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i != 0:\n return False\n return True",
"original_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True",
"initial_error": "AssertionError: is_prime(13) expected True, got False",
"bug_location": {"function": "is_prime", "line_start": 5},
"test_cases": [{"input": 2, "expected_output": True}, {"input": 4, "expected_output": False}, {"input": 13, "expected_output": True}, {"input": 1, "expected_output": False}]
},
{
"id": "t1_021",
"difficulty": 1,
"bug_type": "wrong_comparison",
"function_name": "merge_intervals",
"buggy_code": "def merge_intervals(intervals):\n if not intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] < previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged",
"original_code": "def merge_intervals(intervals):\n if not intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] <= previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged",
"initial_error": "AssertionError: merge_intervals([[1,4],[4,5]]) expected [[1,5]], got [[1,4],[4,5]]",
"bug_location": {"function": "merge_intervals", "line_start": 8},
"test_cases": [{"input": [[[1,3],[2,6],[8,10],[15,18]]], "expected_output": [[1,6],[8,10],[15,18]]}, {"input": [[[1,4],[4,5]]], "expected_output": [[1,5]]}, {"input": [[]], "expected_output": []}, {"input": [[[1,4],[0,4]]], "expected_output": [[0,4]]}]
},
{
"id": "t1_022",
"difficulty": 1,
"bug_type": "logic_inversion",
"function_name": "merge_intervals",
"buggy_code": "def merge_intervals(intervals):\n if intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] <= previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged",
"original_code": "def merge_intervals(intervals):\n if not intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] <= previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged",
"initial_error": "AssertionError: merge_intervals([[1,4],[4,5]]) expected [[1,5]], got []",
"bug_location": {"function": "merge_intervals", "line_start": 2},
"test_cases": [{"input": [[[1,3],[2,6],[8,10],[15,18]]], "expected_output": [[1,6],[8,10],[15,18]]}, {"input": [[[1,4],[4,5]]], "expected_output": [[1,5]]}, {"input": [[]], "expected_output": []}, {"input": [[[1,4],[0,4]]], "expected_output": [[0,4]]}]
},
{
"id": "t1_023",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "remove_duplicates",
"buggy_code": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] == nums[i]:\n i += 1\n nums[i] = nums[j]\n return i + 1",
"original_code": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] != nums[i]:\n i += 1\n nums[i] = nums[j]\n return i + 1",
"initial_error": "AssertionError: remove_duplicates([1,1,2]) expected 2, got 2 with array [1,1,2]",
"bug_location": {"function": "remove_duplicates", "line_start": 6},
"test_cases": [{"input": [[1,1,2]], "expected_output": 2}, {"input": [[0,0,1,1,1,2,2,3,3,4]], "expected_output": 5}, {"input": [[]], "expected_output": 0}, {"input": [[1]], "expected_output": 1}]
},
{
"id": "t1_024",
"difficulty": 1,
"bug_type": "off_by_one",
"function_name": "remove_duplicates",
"buggy_code": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] != nums[i]:\n i += 1\n nums[i] = nums[j]\n return i",
"original_code": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] != nums[i]:\n i += 1\n nums[i] = nums[j]\n return i + 1",
"initial_error": "AssertionError: remove_duplicates([1,1,2]) expected 2, got 1",
"bug_location": {"function": "remove_duplicates", "line_start": 9},
"test_cases": [{"input": [[1,1,2]], "expected_output": 2}, {"input": [[0,0,1,1,1,2,2,3,3,4]], "expected_output": 5}, {"input": [[]], "expected_output": 0}, {"input": [[1]], "expected_output": 1}]
},
{
"id": "t1_025",
"difficulty": 1,
"bug_type": "wrong_comparison",
"function_name": "longest_common_prefix",
"buggy_code": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs[1:]:\n while s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix",
"original_code": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs[1:]:\n while not s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix",
"initial_error": "AssertionError: longest_common_prefix(['flower','flow','flight']) expected 'fl', got ''",
"bug_location": {"function": "longest_common_prefix", "line_start": 6},
"test_cases": [{"input": [["flower","flow","flight"]], "expected_output": "fl"}, {"input": [["dog","racecar","car"]], "expected_output": ""}, {"input": [[]], "expected_output": ""}, {"input": [["a"]], "expected_output": "a"}]
},
{
"id": "t1_026",
"difficulty": 1,
"bug_type": "off_by_one",
"function_name": "longest_common_prefix",
"buggy_code": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs:\n while not s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix",
"original_code": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs[1:]:\n while not s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix",
"initial_error": "AssertionError: doesn't strictly fail but runs longer",
"bug_location": {"function": "longest_common_prefix", "line_start": 5},
"test_cases": [{"input": [["flower","flow","flight"]], "expected_output": "fl"}, {"input": [["dog","racecar","car"]], "expected_output": ""}, {"input": [[]], "expected_output": ""}, {"input": [["a"]], "expected_output": "a"}]
},
{
"id": "t1_027",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "product_except_self",
"buggy_code": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix += nums[i]\n postfix = 1\n for i in range(n - 1, -1, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res",
"original_code": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix *= nums[i]\n postfix = 1\n for i in range(n - 1, -1, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res",
"initial_error": "AssertionError: product_except_self([1,2,3,4]) expected [24,12,8,6], got [24, 24, 16, 6]",
"bug_location": {"function": "product_except_self", "line_start": 7},
"test_cases": [{"input": [[1,2,3,4]], "expected_output": [24,12,8,6]}, {"input": [[-1,1,0,-3,3]], "expected_output": [0,0,9,0,0]}, {"input": [[2,3]], "expected_output": [3,2]}, {"input": [[1,1,1]], "expected_output": [1,1,1]}]
},
{
"id": "t1_028",
"difficulty": 1,
"bug_type": "off_by_one",
"function_name": "product_except_self",
"buggy_code": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix *= nums[i]\n postfix = 1\n for i in range(n - 1, 0, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res",
"original_code": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix *= nums[i]\n postfix = 1\n for i in range(n - 1, -1, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res",
"initial_error": "AssertionError: product_except_self([1,2,3,4]) expected [24,12,8,6], got [1,12,8,6]",
"bug_location": {"function": "product_except_self", "line_start": 9},
"test_cases": [{"input": [[1,2,3,4]], "expected_output": [24,12,8,6]}, {"input": [[-1,1,0,-3,3]], "expected_output": [0,0,9,0,0]}, {"input": [[2,3]], "expected_output": [3,2]}, {"input": [[1,1,1]], "expected_output": [1,1,1]}]
},
{
"id": "t1_029",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "valid_parentheses",
"buggy_code": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] == top_element:\n return False\n else:\n stack.append(char)\n return not stack",
"original_code": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] != top_element:\n return False\n else:\n stack.append(char)\n return not stack",
"initial_error": "AssertionError: valid_parentheses('()') expected True, got False",
"bug_location": {"function": "valid_parentheses", "line_start": 7},
"test_cases": [{"input": "()", "expected_output": True}, {"input": "()[]{}", "expected_output": True}, {"input": "(]", "expected_output": False}, {"input": "([)]", "expected_output": False}]
},
{
"id": "t1_030",
"difficulty": 1,
"bug_type": "logic_inversion",
"function_name": "valid_parentheses",
"buggy_code": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] != top_element:\n return False\n else:\n stack.append(char)\n return bool(stack)",
"original_code": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] != top_element:\n return False\n else:\n stack.append(char)\n return not stack",
"initial_error": "AssertionError: valid_parentheses('()') expected True, got False",
"bug_location": {"function": "valid_parentheses", "line_start": 11},
"test_cases": [{"input": "()", "expected_output": True}, {"input": "()[]{}", "expected_output": True}, {"input": "(]", "expected_output": False}, {"input": "([)]", "expected_output": False}]
},
{
"id": "t1_031",
"difficulty": 1,
"bug_type": "off_by_one",
"function_name": "climbing_stairs",
"buggy_code": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n):\n a, b = b, a + b\n return b",
"original_code": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a + b\n return b",
"initial_error": "AssertionError: climbing_stairs(3) expected 3, got 2",
"bug_location": {"function": "climbing_stairs", "line_start": 5},
"test_cases": [{"input": 2, "expected_output": 2}, {"input": 3, "expected_output": 3}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 8}]
},
{
"id": "t1_032",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "climbing_stairs",
"buggy_code": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a * b\n return b",
"original_code": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a + b\n return b",
"initial_error": "AssertionError: climbing_stairs(3) expected 3, got 2",
"bug_location": {"function": "climbing_stairs", "line_start": 6},
"test_cases": [{"input": 2, "expected_output": 2}, {"input": 3, "expected_output": 3}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 8}]
},
{
"id": "t1_033",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "house_robber",
"buggy_code": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = min(nums[0], nums[1])\n for i in range(2, len(nums)):\n dp[i] = max(dp[i-1], dp[i-2] + nums[i])\n return dp[-1]",
"original_code": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = max(nums[0], nums[1])\n for i in range(2, len(nums)):\n dp[i] = max(dp[i-1], dp[i-2] + nums[i])\n return dp[-1]",
"initial_error": "AssertionError: house_robber([2,7,9,3,1]) expected 12, got 11",
"bug_location": {"function": "house_robber", "line_start": 8},
"test_cases": [{"input": [[1,2,3,1]], "expected_output": 4}, {"input": [[2,7,9,3,1]], "expected_output": 12}, {"input": [[]], "expected_output": 0}, {"input": [[5]], "expected_output": 5}]
},
{
"id": "t1_034",
"difficulty": 1,
"bug_type": "off_by_one",
"function_name": "house_robber",
"buggy_code": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = max(nums[0], nums[1])\n for i in range(1, len(nums)):\n dp[i] = max(dp[i-1], dp[i-2] + nums[i])\n return dp[-1]",
"original_code": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = max(nums[0], nums[1])\n for i in range(2, len(nums)):\n dp[i] = max(dp[i-1], dp[i-2] + nums[i])\n return dp[-1]",
"initial_error": "IndexError: list index out of range",
"bug_location": {"function": "house_robber", "line_start": 9},
"test_cases": [{"input": [[1,2,3,1]], "expected_output": 4}, {"input": [[2,7,9,3,1]], "expected_output": 12}, {"input": [[]], "expected_output": 0}, {"input": [[5]], "expected_output": 5}]
},
{
"id": "t1_035",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "intersection_of_arrays",
"buggy_code": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) | set(nums2))",
"original_code": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) & set(nums2))",
"initial_error": "AssertionError: intersection_of_arrays([1,2,2,1], [2,2]) expected [2], got [1,2]",
"bug_location": {"function": "intersection_of_arrays", "line_start": 2},
"test_cases": [{"input": [[1,2,2,1], [2,2]], "expected_output": [2]}, {"input": [[4,9,5], [9,4,9,8,4]], "expected_output": [9,4]}, {"input": [[], [1]], "expected_output": []}, {"input": [[1,2], [3,4]], "expected_output": []}]
},
{
"id": "t1_036",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "intersection_of_arrays",
"buggy_code": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) - set(nums2))",
"original_code": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) & set(nums2))",
"initial_error": "AssertionError: intersection_of_arrays([1,2,2,1], [2,2]) expected [2], got [1]",
"bug_location": {"function": "intersection_of_arrays", "line_start": 2},
"test_cases": [{"input": [[1,2,2,1], [2,2]], "expected_output": [2]}, {"input": [[4,9,5], [9,4,9,8,4]], "expected_output": [9,4]}, {"input": [[], [1]], "expected_output": []}, {"input": [[1,2], [3,4]], "expected_output": []}]
},
{
"id": "t1_037",
"difficulty": 1,
"bug_type": "wrong_comparison",
"function_name": "group_anagrams",
"buggy_code": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(s)].append(s)\n return list(ans.values())",
"original_code": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(sorted(s))].append(s)\n return list(ans.values())",
"initial_error": "AssertionError: expected [['eat','tea','ate'],['tan','nat'],['bat']]",
"bug_location": {"function": "group_anagrams", "line_start": 5},
"test_cases": [{"input": [["eat","tea","tan","ate","nat","bat"]], "expected_output": [["eat","tea","ate"],["tan","nat"],["bat"]]}, {"input": [[""]], "expected_output": [[""]]}, {"input": [["a"]], "expected_output": [["a"]]}, {"input": [["ab", "ba"]], "expected_output": [["ab", "ba"]]}]
},
{
"id": "t1_038",
"difficulty": 1,
"bug_type": "logic_inversion",
"function_name": "group_anagrams",
"buggy_code": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(sorted(s))].append(s[::-1])\n return list(ans.values())",
"original_code": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(sorted(s))].append(s)\n return list(ans.values())",
"initial_error": "AssertionError: expected [['eat','tea','ate'],['tan','nat'],['bat']]",
"bug_location": {"function": "group_anagrams", "line_start": 5},
"test_cases": [{"input": [["eat","tea","tan","ate","nat","bat"]], "expected_output": [["eat","tea","ate"],["tan","nat"],["bat"]]}, {"input": [[""]], "expected_output": [[""]]}, {"input": [["a"]], "expected_output": [["a"]]}, {"input": [["ab", "ba"]], "expected_output": [["ab", "ba"]]}]
},
{
"id": "t1_039",
"difficulty": 1,
"bug_type": "wrong_operator",
"function_name": "sum_digits",
"buggy_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total *= n % 10\n n //= 10\n return total",
"original_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n % 10\n n //= 10\n return total",
"initial_error": "AssertionError: sum_digits(123) expected 6, got 0",
"bug_location": {"function": "sum_digits", "line_start": 4},
"test_cases": [{"input": 123, "expected_output": 6}, {"input": 0, "expected_output": 0}, {"input": 999, "expected_output": 27}, {"input": 10, "expected_output": 1}]
},
{
"id": "t1_040",
"difficulty": 1,
"bug_type": "off_by_one",
"function_name": "factorial",
"buggy_code": "def factorial(n):\n if n <= 0:\n return 0\n return n * factorial(n - 1)",
"original_code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)",
"initial_error": "AssertionError: factorial(3) expected 6, got 0",
"bug_location": {"function": "factorial", "line_start": 3},
"test_cases": [{"input": 0, "expected_output": 1}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 120}, {"input": 3, "expected_output": 6}]
}
]