From d48e8a3d0a4fcfe07cb0d81b52b35ab6d776c576 Mon Sep 17 00:00:00 2001 From: hiiamkarati Date: Wed, 6 Aug 2025 18:28:07 +0530 Subject: [PATCH 1/4] Two-Sum to match target --- interview-bootcamp/Two-Sum.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 interview-bootcamp/Two-Sum.py diff --git a/interview-bootcamp/Two-Sum.py b/interview-bootcamp/Two-Sum.py new file mode 100644 index 000000000000..a5a5e68e6296 --- /dev/null +++ b/interview-bootcamp/Two-Sum.py @@ -0,0 +1,20 @@ +def to_sum(nums, target): + """ + This function finds two numbers in the list 'nums' that add up to 'target'. + + :param nums: List of integers + :param target: Integer target sum + :return: Tuple of the two numbers that add up to target, or None if no such pair exists + """ + num_set = set() + + for num in nums: + complement = target - num + if complement in num_set: + return (complement, num) + num_set.add(num) + + return None + +if __name__ == "__main__": + print(to_sum([2, 7, 11, 15], 9)) \ No newline at end of file From c3e20baeda3b54aac345eaa5c10b59a0ff95748e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 6 Aug 2025 13:00:41 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- interview-bootcamp/Two-Sum.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/interview-bootcamp/Two-Sum.py b/interview-bootcamp/Two-Sum.py index a5a5e68e6296..d335e5016ed1 100644 --- a/interview-bootcamp/Two-Sum.py +++ b/interview-bootcamp/Two-Sum.py @@ -1,20 +1,21 @@ def to_sum(nums, target): """ This function finds two numbers in the list 'nums' that add up to 'target'. - + :param nums: List of integers :param target: Integer target sum :return: Tuple of the two numbers that add up to target, or None if no such pair exists """ num_set = set() - + for num in nums: complement = target - num if complement in num_set: return (complement, num) num_set.add(num) - + return None + if __name__ == "__main__": - print(to_sum([2, 7, 11, 15], 9)) \ No newline at end of file + print(to_sum([2, 7, 11, 15], 9)) From a075bfc118ac3f3e7db82462e893cb047faefcfb Mon Sep 17 00:00:00 2001 From: hiiamkarati Date: Wed, 6 Aug 2025 18:34:00 +0530 Subject: [PATCH 3/4] Two-Sum 01 --- interview-bootcamp/Two-Sum.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/interview-bootcamp/Two-Sum.py b/interview-bootcamp/Two-Sum.py index a5a5e68e6296..3a78022fc253 100644 --- a/interview-bootcamp/Two-Sum.py +++ b/interview-bootcamp/Two-Sum.py @@ -1,20 +1,21 @@ -def to_sum(nums, target): +def two_sum(nums: list[int], target: int) -> tuple[int, int] | None: """ - This function finds two numbers in the list 'nums' that add up to 'target'. - + Find two numbers in the list 'nums' that add up to 'target'. + :param nums: List of integers :param target: Integer target sum :return: Tuple of the two numbers that add up to target, or None if no such pair exists """ num_set = set() - + for num in nums: complement = target - num if complement in num_set: return (complement, num) num_set.add(num) - + return None + if __name__ == "__main__": - print(to_sum([2, 7, 11, 15], 9)) \ No newline at end of file + print(two_sum([2, 7, 11, 15], 9)) \ No newline at end of file From 58057f0ccc080f32c9237a8306c444c6c21138db Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 6 Aug 2025 13:15:18 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- interview-bootcamp/Two-Sum.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/interview-bootcamp/Two-Sum.py b/interview-bootcamp/Two-Sum.py index f3b6ceabb27c..8b2790c202fd 100644 --- a/interview-bootcamp/Two-Sum.py +++ b/interview-bootcamp/Two-Sum.py @@ -8,17 +8,14 @@ def two_sum(nums: list[int], target: int) -> tuple[int, int] | None: """ num_set = set() - for num in nums: complement = target - num if complement in num_set: return (complement, num) num_set.add(num) - return None - if __name__ == "__main__": - print(two_sum([2, 7, 11, 15], 9)) \ No newline at end of file + print(two_sum([2, 7, 11, 15], 9))