Learn Data Structures by Building the Merge Sort Algorithm - Step 33

Tell us what’s happening:

Describe your issue in detail here.
Hi team, the platform does not let my code pass. The code seems fine and the print statement is deindented.

Your code so far

def merge_sort(array):
    if len(array) <= 1:
        return
    
    middle_point = len(array) // 2
    left_part = array[:middle_point]
    right_part = array[middle_point:]

    merge_sort(left_part)
    merge_sort(right_part)

    left_array_index = 0
    right_array_index = 0
    sorted_index = 0

    while left_array_index < len(left_part) and right_array_index < len(right_part):
        if left_part[left_array_index] < right_part[right_array_index]:
            array[sorted_index] = left_part[left_array_index]
            left_array_index += 1
        else:
            array[sorted_index] = right_part[right_array_index]
            right_array_index += 1
        sorted_index += 1

    while left_array_index < len(left_part):
        array[sorted_index] = left_part[left_array_index]
        left_array_index += 1
        sorted_index += 1
    
    while right_array_index < len(right_part):
        array[sorted_index] = right_part[right_array_index]
        right_array_index += 1
        sorted_index += 1



# User Editable Region

if __name__ == '__main__':
    numbers = [4, 10, 6, 14, 2, 1, 8, 5]
    print('Unsorted array: ')
    print(numbers)
    merge_sort(numbers)
print(concat('Sorted array: ', str(numbers)))


# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0

Challenge Information:

Learn Data Structures by Building the Merge Sort Algorithm - Step 33
https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-data-structures-by-building-the-merge-sort-algorithm/step-33`Preformatted text`

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Hello!

  • “concat()” is used in the Pandas library for combining data frames, in everyday Python that’s done with “+”

  • line needs to be part of the if statement block

1 Like