<commit_before>import unittest

"""
Given two sorted arrays, one of size n and one of size m+n containing only m elements,
merge the smaller array into the larger array such that output is sorted.
Note: NA means empty slot
Input: larger => 2 NA 7 NA NA 10 NA
       smaller => 5 8 12 14
Output: 2 5 7 8 10 12 14
"""

"""
Approach:
1. Move all (non-NA) elements in larger array to the right.
2. Keep one index at start of smaller array, and one index after n positions in larger array.
3. Keep one index at start of larger array.
4. Compare elements and place the smaller at the start of larger array.
5. Increment indices accordingly.
"""


def move_to_right(list_of_numbers):
    destination = len(list_of_numbers) - 1
    index = len(list_of_numbers) - 1
    while index >= 0:
        if list_of_numbers[index] is not None:
            list_of_numbers[destination] = list_of_numbers[index]
            destination -= 1
        index -= 1


def merge_lists(larger_list, smaller_list):
    smaller_index = 0
    larger_index = len(smaller_list)
    destination = 0

    while smaller_index < len(smaller_list):
        if larger_index < len(larger_list) and larger_list[larger_index] <= smaller_list[smaller_index]:
            larger_list[destination] = larger_list[larger_index]
            larger_index += 1
        else:
            larger_list[destination] = smaller_list[smaller_index]
            smaller_index += 1
        destination += 1


def merge_smaller_into_larger(larger_list, smaller_list):
    move_to_right(larger_list)
    merge_lists(larger_list, smaller_list)


class TestMerge(unittest.TestCase):

    def test_merge_smaller_array_has_largest_element(self):
        smaller_list = [5, 8, 12, 14]
        larger_list = [2, None, 7, None, None, 10, None]

        merge_smaller_into_larger(larger_list, smaller_list)<commit_msg>Move NA to left logic change<commit_after>import unittest

"""
Given two sorted arrays, one of size n and one of size m+n containing only m elements,
merge the smaller array into the larger array such that output is sorted.
Note: NA means empty slot
Input: larger => 2 NA 7 NA NA 10 NA
       smaller => 5 8 12 14
Output: 2 5 7 8 10 12 14
"""

"""
Approach:
1. Move all (non-NA) elements in larger array to the right.
2. Keep one index at start of smaller array, and one index after n positions in larger array.
3. Keep one index at start of larger array.
4. Compare elements and place the smaller at the start of larger array.
5. Increment indices accordingly.
"""


def move_non_na_to_right(list_of_numbers):
    # Uses similar logic to move zeros to end of list
    end = len(list_of_numbers)
    count_non_na = end - 1
    for i in range(end - 1, -1, -1):
        if list_of_numbers[i] is not None:
            list_of_numbers[count_non_na] = list_of_numbers[i]
            count_non_na -= 1

    for i in range(count_non_na, -1, -1):
        list_of_numbers[i] = None


def merge_lists(larger_list, smaller_list):
    smaller_index = 0
    larger_index = len(smaller_list)
    destination = 0

    while smaller_index < len(smaller_list):
        if larger_index < len(larger_list) and larger_list[larger_index] <= smaller_list[smaller_index]:
            larger_list[destination] = larger_list[larger_index]
            larger_index += 1
        else:
            larger_list[destination] = smaller_list[smaller_index]
            smaller_index += 1
        destination += 1


def merge_smaller_into_larger(larger_list, smaller_list):
    move_non_na_to_right(larger_list)
    merge_lists(larger_list, smaller_list)


class TestMerge(unittest.TestCase):

    def test_merge_smaller_array_has_largest_element(self):
        smaller_list = [5, 8, 12, 14]
        larger_list = [2, None, 7, None, None, 10, None]

        merge_smaller_into_larger(larger_list, smaller_list)
{'fraction_non_alphanumeric': 0.07658128593831678, 'fraction_numerical': 0.024046001045478306, 'mean_word_length': 3.26644370122631, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4209721', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1193, 'n_words': 405}