buggy_code:
def two_sum(nums, target):
    seen = {}
    for i, num in enumerate(nums):
        complement = target - num
        if complement in seen:
            return [seen[complement], i]
        seen[num] = num
    return []

original_code:
def two_sum(nums, target):
    seen = {}
    for i, num in enumerate(nums):
        complement = target - num
        if complement in seen:
            return [seen[complement], i]
        seen[num] = i
    return []

initial_error: AssertionError: two_sum([2,7,11,15], 9) expected [0,1], got [2,1]


function_name: fibonacci

buggy_code:
def fibonacci(n):
    if n == 0:
        return 0
    return fibonacci(n - 1) + fibonacci(n - 2)

original_code:
def fibonacci(n):
    if n == 0:
        return 0
    if n == 1:
        return 1
    return fibonacci(n - 1) + fibonacci(n - 2)

initial_error: RecursionError: maximum recursion depth exceeded

function: fibonacci


function_name: flatten

buggy_code:
def flatten(lst):
    result = []
    for item in lst:
        if isinstance(item, list):
            result.append(flatten(item))
        else:
            result.append(item)
    return result

original_code:
def flatten(lst):
    result = []
    for item in lst:
        if isinstance(item, list):
            result.extend(flatten(item))
        else:
            result.append(item)
    return result

initial_error: AssertionError: flatten([[1,[2]],3]) expected [1,2,3], got [1,[2],3]

function: flatten


buggy_code:
def find_first_positive(nums):
    i = 0
    while i < len(nums) - 1:
        if nums[i] > 0:
            return nums[i]
        i += 1
    return -1

original_code:
def find_first_positive(nums):
    i = 0
    while i < len(nums):
        if nums[i] > 0:
            return nums[i]
        i += 1
    return -1

initial_error: AssertionError: expected 5, got -1


buggy_code:
def binary_search_insert(arr, target):
    left, right = 0, len(arr) - 1
    while left < right:
        mid = (left + right) // 2
        if arr[mid] < target:
            left = mid + 1
        else:
            right = mid
    return left

original_code:
def binary_search_insert(arr, target):
    left, right = 0, len(arr)
    while left < right:
        mid = (left + right) // 2
        if arr[mid] < target:
            left = mid + 1
        else:
            right = mid
    return left

initial_error: AssertionError: expected 3, got 2


buggy_code:
def countdown_to_zero(n):
    res = []
    while n > 0:
        res.append(n)
        n -= 1
    return res

original_code:
def countdown_to_zero(n):
    res = []
    while n >= 0:
        res.append(n)
        n -= 1
    return res

initial_error: AssertionError: expected [3, 2, 1, 0], got [3, 2, 1]


buggy_code:
def collect_until_negative(nums):
    res = []
    i = 0
    while i <= len(nums) and nums[i] >= 0:
        res.append(nums[i])
        i += 1
    return res

original_code:
def collect_until_negative(nums):
    res = []
    i = 0
    while i < len(nums) and nums[i] >= 0:
        res.append(nums[i])
        i += 1
    return res

initial_error: IndexError: list index out of range


buggy_code:
def skip_spaces(s):
    i = 0
    while s[i] == ' ':
        i += 1
    return s[i:]

original_code:
def skip_spaces(s):
    i = 0
    while i < len(s) and s[i] == ' ':
        i += 1
    return s[i:]

initial_error: IndexError: string index out of range

input: hello

expected_output: hello

input: world

expected_output: world


buggy_code:
def find_last_even(nums):
    i = len(nums) - 1
    while i > 0:
        if nums[i] % 2 == 0:
            return nums[i]
        i -= 1
    return -1

original_code:
def find_last_even(nums):
    i = len(nums) - 1
    while i >= 0:
        if nums[i] % 2 == 0:
            return nums[i]
        i -= 1
    return -1

initial_error: AssertionError: expected 2, got -1


buggy_code:
def get_chunks(lst, size):
    chunks = []
    i = 0
    while i < len(lst) - size:
        chunks.append(lst[i:i+size])
        i += size
    return chunks

original_code:
def get_chunks(lst, size):
    chunks = []
    i = 0
    while i < len(lst):
        chunks.append(lst[i:i+size])
        i += size
    return chunks

initial_error: AssertionError: expected [[1,2],[3]], got [[1,2]]


buggy_code:
def sum_even_numbers(nums):
    total = 1
    for n in nums:
        if n % 2 == 0:
            total += n
    return total

original_code:
def sum_even_numbers(nums):
    total = 0
    for n in nums:
        if n % 2 == 0:
            total += n
    return total

initial_error: AssertionError: expected 6, got 7


buggy_code:
def multiply_all(nums):
    total = 0
    for n in nums:
        total *= n
    return total

original_code:
def multiply_all(nums):
    total = 1
    for n in nums:
        total *= n
    return total

initial_error: AssertionError: expected 24, got 0


buggy_code:
def concatenate_strings(strs):
    res = strs[0]
    for s in strs:
        res += s
    return res

original_code:
def concatenate_strings(strs):
    res = ''
    for s in strs:
        res += s
    return res

initial_error: AssertionError: expected 'abc', got 'aabc'

input: a b c

expected_output: abc

input: hello world

expected_output: helloworld

input: a

expected_output: a

input: x y

expected_output: xy


buggy_code:
def max_profit(prices):
    min_price = 0
    max_prof = 0
    for price in prices:
        min_price = min(min_price, price)
        max_prof = max(max_prof, price - min_price)
    return max_prof

original_code:
def max_profit(prices):
    min_price = float('inf')
    max_prof = 0
    for price in prices:
        min_price = min(min_price, price)
        max_prof = max(max_prof, price - min_price)
    return max_prof

initial_error: AssertionError: expected 5, got 6


buggy_code:
def find_longest_word(words):
    longest = words[0]
    for word in words:
        if len(word) > len(longest):
            longest = longest
    return longest

original_code:
def find_longest_word(words):
    longest = ''
    for word in words:
        if len(word) > len(longest):
            longest = word
    return longest

initial_error: AssertionError: expected 'banana', got 'apple'

input: apple banana kiwi

expected_output: banana

input: a ab abc

input: dog

expected_output: dog

input: x yz

expected_output: yz


buggy_code:
def running_sum(nums):
    res = []
    current = nums[0]
    for n in nums:
        current += n
        res.append(current)
    return res

original_code:
def running_sum(nums):
    res = []
    current = 0
    for n in nums:
        current += n
        res.append(current)
    return res

initial_error: AssertionError: expected [1, 3, 6], got [2, 4, 7]


buggy_code:
def count_negatives(nums):
    count = -1
    for n in nums:
        if n < 0:
            count += 1
    return count

original_code:
def count_negatives(nums):
    count = 0
    for n in nums:
        if n < 0:
            count += 1
    return count

initial_error: AssertionError: expected 2, got 1


buggy_code:
def classify_number(n):
    if n > 0:
        return 'positive'
    elif n < 0:
        return 'negative'
    elif n == 0:
        return 'negative'

original_code:
def classify_number(n):
    if n > 0:
        return 'positive'
    elif n < 0:
        return 'negative'
    else:
        return 'zero'

initial_error: AssertionError: expected 'zero', got 'negative'

expected_output: positive

expected_output: negative

expected_output: zero


buggy_code:
def get_discount(price):
    if price > 100:
        return 20
    if price > 50:
        return 50
    return 0

original_code:
def get_discount(price):
    if price > 100:
        return 20
    elif price > 50:
        return 10
    return 0

initial_error: AssertionError: expected 10, got 50


buggy_code:
def fizz_buzz(n):
    if n % 3 == 0:
        return 'Fizz'
    if n % 5 == 0:
        return 'Buzz'
    if n % 15 == 0:
        return 'FizzBuzz'
    return str(n)

original_code:
def fizz_buzz(n):
    if n % 15 == 0:
        return 'FizzBuzz'
    if n % 3 == 0:
        return 'Fizz'
    if n % 5 == 0:
        return 'Buzz'
    return str(n)

initial_error: AssertionError: expected 'FizzBuzz', got 'Fizz'

expected_output: Fizz

expected_output: Buzz

expected_output: FizzBuzz


buggy_code:
def is_leap_year(year):
    if year % 4 == 0:
        if year % 100 == 0:
            if year % 400 == 0:
                return False
            return True
        return True
    return False

original_code:
def is_leap_year(year):
    if year % 4 == 0:
        if year % 100 == 0:
            if year % 400 == 0:
                return True
            return False
        return True
    return False

initial_error: AssertionError: expected False, got True


buggy_code:
def grade_score(score):
    if score >= 90:
        return 'A'
    elif score >= 80:
        return 'B'
    elif score > 70:
        return 'C'
    else:
        return 'F'

original_code:
def grade_score(score):
    if score >= 90:
        return 'A'
    elif score >= 80:
        return 'B'
    elif score >= 70:
        return 'C'
    else:
        return 'F'

initial_error: AssertionError: expected 'C', got 'F'

expected_output: A

expected_output: B

expected_output: C

expected_output: F


buggy_code:
def can_drink_alcohol(age, country):
    if country == 'US':
        if age > 21:
            return True
        return False
    return age >= 18

original_code:
def can_drink_alcohol(age, country):
    if country == 'US':
        if age >= 21:
            return True
        return False
    return age >= 18

initial_error: AssertionError: expected True, got False

input: US

input: US

input: UK

input: UK


buggy_code:
def get_quadrant(x, y):
    if x > 0 and y > 0:
        return 1
    elif x < 0 and y > 0:
        return 2
    elif x > 0 and y < 0:
        return 3
    elif x < 0 and y < 0:
        return 4
    return 0

original_code:
def get_quadrant(x, y):
    if x > 0 and y > 0:
        return 1
    elif x < 0 and y > 0:
        return 2
    elif x < 0 and y < 0:
        return 3
    elif x > 0 and y < 0:
        return 4
    return 0

initial_error: AssertionError: expected 4, got 3


buggy_code:
def merge_arrays(a, b):
    res = a + b
    res.sort()
    return a

original_code:
def merge_arrays(a, b):
    res = a + b
    res.sort()
    return res

initial_error: AssertionError: expected [1, 2, 3, 4], got [1, 3]


buggy_code:
def find_min_max(nums):
    if not nums:
        return None
    mn = min(nums)
    mx = max(nums)
    return [mn, mn]

original_code:
def find_min_max(nums):
    if not nums:
        return None
    mn = min(nums)
    mx = max(nums)
    return [mn, mx]

initial_error: AssertionError: expected (1, 5), got (1, 1)


buggy_code:
def remove_evens(nums):
    res = []
    for n in nums:
        if n % 2 != 0:
            res.append(n)
    return nums

original_code:
def remove_evens(nums):
    res = []
    for n in nums:
        if n % 2 != 0:
            res.append(n)
    return res

initial_error: AssertionError: expected [1, 3], got [1, 2, 3]


buggy_code:
def duplicate_list(lst):
    res = lst[:]
    res.extend(lst)
    return lst

original_code:
def duplicate_list(lst):
    res = lst[:]
    res.extend(lst)
    return res

initial_error: AssertionError: expected [1, 1], got [1]


buggy_code:
def swap_halves(lst):
    mid = len(lst) // 2
    left = lst[:mid]
    right = lst[mid:]
    return left + left

original_code:
def swap_halves(lst):
    mid = len(lst) // 2
    left = lst[:mid]
    right = lst[mid:]
    return right + left

initial_error: AssertionError: expected [3, 4, 1, 2], got [1, 2, 1, 2]


buggy_code:
def get_initials(name):
    words = name.split()
    initials = [w[0].upper() for w in words]
    return ''.join(words)

original_code:
def get_initials(name):
    words = name.split()
    initials = [w[0].upper() for w in words]
    return ''.join(initials)

initial_error: AssertionError: expected 'JD', got 'JohnDoe'

input: John Doe

expected_output: JD

input: Alice

input: bob smith junior

expected_output: BSJ