From de80f47f4f86f47b23427fae522c83df7201b70d Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 29 Apr 2026 04:42:39 -0600 Subject: [PATCH] adding updates --- .../ex_01_merge_sorted_array.py | 14 ++++++++++++++ .../top_150_questions_round_23/ListNode.ts | 8 ++++++++ .../top_150_questions_round_23/Node.ts | 12 ++++++++++++ .../top_150_questions_round_23/TreeNode.ts | 11 +++++++++++ .../ex_01_merge_sorted_array.ts | 9 +++++++++ .../test_01_merge_sorted_array_round_23.py | 12 ++++++++++++ 6 files changed, 66 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_23/ex_01_merge_sorted_array.py create mode 100644 src/my_project/interviews_typescript/top_150_questions_round_23/ListNode.ts create mode 100644 src/my_project/interviews_typescript/top_150_questions_round_23/Node.ts create mode 100644 src/my_project/interviews_typescript/top_150_questions_round_23/TreeNode.ts create mode 100644 src/my_project/interviews_typescript/top_150_questions_round_23/ex_01_merge_sorted_array.ts create mode 100644 tests/test_150_questions_round_23/test_01_merge_sorted_array_round_23.py diff --git a/src/my_project/interviews/top_150_questions_round_23/ex_01_merge_sorted_array.py b/src/my_project/interviews/top_150_questions_round_23/ex_01_merge_sorted_array.py new file mode 100644 index 00000000..07b561ed --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_23/ex_01_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 diff --git a/src/my_project/interviews_typescript/top_150_questions_round_23/ListNode.ts b/src/my_project/interviews_typescript/top_150_questions_round_23/ListNode.ts new file mode 100644 index 00000000..91741114 --- /dev/null +++ b/src/my_project/interviews_typescript/top_150_questions_round_23/ListNode.ts @@ -0,0 +1,8 @@ +export class ListNode { + val: number + next: ListNode | null + constructor(val?: number, next?: ListNode | null) { + this.val = (val===undefined ? 0 : val) + this.next = (next===undefined ? null : next) + } +} diff --git a/src/my_project/interviews_typescript/top_150_questions_round_23/Node.ts b/src/my_project/interviews_typescript/top_150_questions_round_23/Node.ts new file mode 100644 index 00000000..1a281a48 --- /dev/null +++ b/src/my_project/interviews_typescript/top_150_questions_round_23/Node.ts @@ -0,0 +1,12 @@ +// Definition for a Node. +export class _Node { + val: number; + next: _Node | null; + random: _Node | null; + + constructor(val?: number, next?: _Node | null, random?: _Node | null) { + this.val = val ?? 0; + this.next = next ?? null; + this.random = random ?? null; + } +} \ No newline at end of file diff --git a/src/my_project/interviews_typescript/top_150_questions_round_23/TreeNode.ts b/src/my_project/interviews_typescript/top_150_questions_round_23/TreeNode.ts new file mode 100644 index 00000000..df3eb8a6 --- /dev/null +++ b/src/my_project/interviews_typescript/top_150_questions_round_23/TreeNode.ts @@ -0,0 +1,11 @@ +export class TreeNode { + val: number; + left: TreeNode | null; + right: TreeNode | null; + + constructor(val: number = 0, left: TreeNode | null = null, right: TreeNode | null = null) { + this.val = val; + this.left = left; + this.right = right; + } +} \ No newline at end of file diff --git a/src/my_project/interviews_typescript/top_150_questions_round_23/ex_01_merge_sorted_array.ts b/src/my_project/interviews_typescript/top_150_questions_round_23/ex_01_merge_sorted_array.ts new file mode 100644 index 00000000..c11a1c13 --- /dev/null +++ b/src/my_project/interviews_typescript/top_150_questions_round_23/ex_01_merge_sorted_array.ts @@ -0,0 +1,9 @@ +function merge(nums1: number[], m: number, nums2: number[], n: number): number[] { + // Replace the tail of nums1 with nums2 + for (let i = 0; i < n; i++){ + nums1[m + i] = nums2[i]; + } + return nums1; +} + +console.log(merge([1,2,3,0,0,0], 3, [2,5,6], 3)) \ No newline at end of file diff --git a/tests/test_150_questions_round_23/test_01_merge_sorted_array_round_23.py b/tests/test_150_questions_round_23/test_01_merge_sorted_array_round_23.py new file mode 100644 index 00000000..17480107 --- /dev/null +++ b/tests/test_150_questions_round_23/test_01_merge_sorted_array_round_23.py @@ -0,0 +1,12 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_23\ +.ex_01_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