From 80ba9abcc7a46b914ed696a97d30cad6bcc1e355 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 20 Sep 2025 04:31:35 -0600 Subject: [PATCH] adding algo --- .../merge_sorted_array.py | 14 ++++++++++++++ .../test_merge_sorted_array_20.py | 12 ++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_20/merge_sorted_array.py create mode 100644 tests/test_150_questions_round_20/test_merge_sorted_array_20.py diff --git a/src/my_project/interviews/top_150_questions_round_20/merge_sorted_array.py b/src/my_project/interviews/top_150_questions_round_20/merge_sorted_array.py new file mode 100644 index 00000000..529aa24b --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_20/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_20/test_merge_sorted_array_20.py b/tests/test_150_questions_round_20/test_merge_sorted_array_20.py new file mode 100644 index 00000000..efb861b8 --- /dev/null +++ b/tests/test_150_questions_round_20/test_merge_sorted_array_20.py @@ -0,0 +1,12 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_20\ +.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)