Blue Week Special Offer | Brighten your week!
days
hours
minutes
seconds

Possible bug on Data Engineering mission 480: Space Complexity

I’ve noticed a possible bug on page 4 of the space complexity mission. The question seems to accept the output: {2: True, 3: True, 7: True, 8: False, 6: True} when it should accept the output: {2: True, 3: True, 7: True, 8: False}

My Code functions when written thusly:

def find_sums(values, target_sums):
    sums = {}
    for target in target_sums:
        sums[target] = False
    for value1 in values:
        for value2 in values:
            if (value1 + value2) in test_targets or value1 + value1 in test_targets or value2 + value2 in test_targets:
                sums[value1 + value2] = True
    return sums 

but if I change the if statement to a more brief, but still accurate form, I’m mistakenly told that my answer is wrong:

def find_sums(values, target_sums):
    sums = {}
    for target in target_sums:
        sums[target] = False
    for value1 in values:
        for value2 in values:
            if (value1 + value2) in test_targets:
                sums[value1 + value2] = True
    return sums 

https://app.dataquest.io/c/86/m/480/space-complexity/4/pair-sums-problem

There is in fact a bug because none of these answers should be able to pass. Notice that they both reference test_targets, but this shouldn’t take part in the definition of the function.

The code runs because we provide test_targets in the display code, otherwise it would error out.

Think about what the output of find_sums([1, 3, 5, 7, 9], [5]) should be and see what your functions does to it.

Thanks Bruno, the inclusion of test_targets went right over my head