diff --git a/src/my_project/interviews/top_150_questions_round_12/merge_sorted_array.py b/src/my_project/interviews/top_150_questions_round_12/merge_sorted_array.py new file mode 100644 index 00000000..34a8d66c --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_12/merge_sorted_array.py @@ -0,0 +1,14 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def merge(self, + nums1: List[int], + m: int, nums2: List[int], + n: int) -> None: + + nums1[m: m+n] = nums2 + + nums1.sort() + + return nums1 \ No newline at end of file diff --git a/tests/test_150_questions_round_12/test_merge_sorted_array_round_12.py b/tests/test_150_questions_round_12/test_merge_sorted_array_round_12.py new file mode 100644 index 00000000..a450edaa --- /dev/null +++ b/tests/test_150_questions_round_12/test_merge_sorted_array_round_12.py @@ -0,0 +1,12 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_12\ +.merge_sorted_array import Solution + +class MergeSortedArrayTestCase(unittest.TestCase): + + def test_merge_sorted_array(self): + solution = Solution() + output = solution.merge(nums1=[1,2,3,0,0,0], m=3, nums2=[2,5,6], n=3) + target = [1,2,2,3,5,6] + for k, v in enumerate(target): + self.assertEqual(output[k], v) \ No newline at end of file