From 4b887326eab357c199186cb34b993aea296a097a Mon Sep 17 00:00:00 2001 From: Rifana-E Date: Tue, 18 Mar 2025 01:01:26 +0530 Subject: [PATCH 01/10] Added solution for Two Sum --- 1-Two-Sum/solution.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 1-Two-Sum/solution.py diff --git a/1-Two-Sum/solution.py b/1-Two-Sum/solution.py new file mode 100644 index 0000000..d88ba6b --- /dev/null +++ b/1-Two-Sum/solution.py @@ -0,0 +1,10 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + num_dict = {} + for i, first_num in enumerate(nums): + second_num =target - first_num + if second_num in num_dict: + return [i, nums.index(second_num)] + else: + num_dict[first_num] = i + return -1 From 1d78cd346b9e3e7e944c404a418f424f3df741ed Mon Sep 17 00:00:00 2001 From: Rifana-E Date: Tue, 18 Mar 2025 01:20:15 +0530 Subject: [PATCH 02/10] Added README file with name and email --- 1-Two-Sum/README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 1-Two-Sum/README.md diff --git a/1-Two-Sum/README.md b/1-Two-Sum/README.md new file mode 100644 index 0000000..4896c62 --- /dev/null +++ b/1-Two-Sum/README.md @@ -0,0 +1,4 @@ + +Name: Rifana E +Email: rifaaaah88@gmail.com + From da8feadf34f1b07e8c615c5772a6dd6ba499da90 Mon Sep 17 00:00:00 2001 From: Rifana-E Date: Thu, 20 Mar 2025 10:32:23 +0530 Subject: [PATCH 03/10] Added solution for Best Time To Buy and Sell Stock --- Best-Time-To-Buy-and-Sell-Stock/solution.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Best-Time-To-Buy-and-Sell-Stock/solution.py diff --git a/Best-Time-To-Buy-and-Sell-Stock/solution.py b/Best-Time-To-Buy-and-Sell-Stock/solution.py new file mode 100644 index 0000000..e9ba1e4 --- /dev/null +++ b/Best-Time-To-Buy-and-Sell-Stock/solution.py @@ -0,0 +1,13 @@ +class Solution: + def maxProfit(self, prices: List[int]) -> int: + left, right = 0, 1 + profit = 0 + while right < len(prices): + if prices[right] > prices[left]: + profit = max(profit, prices[right] - prices[left]) + else: + left = right + + right+=1 + + return profit From 5482f18cdd1135e2e55cbfcb94adeaadd29133fe Mon Sep 17 00:00:00 2001 From: Rifana-E Date: Thu, 20 Mar 2025 11:52:14 +0530 Subject: [PATCH 04/10] Added solution for Contains Duplicate --- Contains-Duplicate/solution.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Contains-Duplicate/solution.py diff --git a/Contains-Duplicate/solution.py b/Contains-Duplicate/solution.py new file mode 100644 index 0000000..e008691 --- /dev/null +++ b/Contains-Duplicate/solution.py @@ -0,0 +1,9 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + hash_set = set() + for num in nums: + if num not in hash_set: + hash_set.add(num) + else: + return True + return False From 79c63792092f8e559dcd2cbe75f446285356f417 Mon Sep 17 00:00:00 2001 From: Rifana-E Date: Fri, 21 Mar 2025 14:26:27 +0530 Subject: [PATCH 05/10] Added solution For Sum of Two Integers --- Sum-of-Two-Integers/solution.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Sum-of-Two-Integers/solution.py diff --git a/Sum-of-Two-Integers/solution.py b/Sum-of-Two-Integers/solution.py new file mode 100644 index 0000000..b6301c4 --- /dev/null +++ b/Sum-of-Two-Integers/solution.py @@ -0,0 +1,11 @@ +# while b != 0: +# sum = a ^ b +# carry = (a & b) << 1 +# a = sum +# b = carry +# return a + +class Solution: + def getSum(self, a: int, b: int) -> int: + sum_int = add(a, b) + return sum_int From 2b66fc3cca847cb652740ccc5c5a3082a320fe8e Mon Sep 17 00:00:00 2001 From: Rifana-E Date: Sun, 23 Mar 2025 06:53:24 +0530 Subject: [PATCH 06/10] Added solution for Product of array Except self --- Product-Of-Array-Except-Self/solution.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Product-Of-Array-Except-Self/solution.py diff --git a/Product-Of-Array-Except-Self/solution.py b/Product-Of-Array-Except-Self/solution.py new file mode 100644 index 0000000..685cdc1 --- /dev/null +++ b/Product-Of-Array-Except-Self/solution.py @@ -0,0 +1,20 @@ +import math + +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + n = len(nums) + answer = [1] * n + + prefix = 1 + for i in range(n): + answer[i] = prefix + prefix *= nums[i] + + suffix = 1 + for i in range(n - 1, -1, -1): + answer[i] *= suffix + suffix *= nums[i] + + return answer + + From f31b5d7edc07f177c7f0cdadb01707688a5811fe Mon Sep 17 00:00:00 2001 From: Rifana-E Date: Mon, 24 Mar 2025 09:36:08 +0530 Subject: [PATCH 07/10] Added Solution for Maximum Subarray --- Maximum-Subarray/solution.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Maximum-Subarray/solution.py diff --git a/Maximum-Subarray/solution.py b/Maximum-Subarray/solution.py new file mode 100644 index 0000000..e6e8804 --- /dev/null +++ b/Maximum-Subarray/solution.py @@ -0,0 +1,12 @@ +class Solution: + def maxSubArray(self, nums: List[int]) -> int: + max_sum = nums[0] + calc_sum = 0 + + for n in nums: + if calc_sum < 0: + calc_sum = 0 + + calc_sum += n + max_sum = max(max_sum, calc_sum) + return max_sum From e58d181d529d8fa3ec5885d81edd3f25136c823e Mon Sep 17 00:00:00 2001 From: Rifana-E Date: Mon, 24 Mar 2025 12:47:24 +0530 Subject: [PATCH 08/10] Added Solution for Maximum Product Subarray --- Maximum-Product-Subarray/solution.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Maximum-Product-Subarray/solution.py diff --git a/Maximum-Product-Subarray/solution.py b/Maximum-Product-Subarray/solution.py new file mode 100644 index 0000000..ad91add --- /dev/null +++ b/Maximum-Product-Subarray/solution.py @@ -0,0 +1,11 @@ +class Solution: + def maxProduct(self, nums: List[int]) -> int: + max_product = nums[0] + calc_max = 1 + calc_min = 1 + for n in nums: + temp = calc_max * n + calc_max = max(temp, calc_min*n, n) + calc_min = min(temp, calc_min*n, n) + max_product = max(max_product, calc_max) + return max_product From 17037a225e4fa4d282a348ac1851110cc10bd8ef Mon Sep 17 00:00:00 2001 From: Rifana-E Date: Wed, 26 Mar 2025 10:32:57 +0530 Subject: [PATCH 09/10] Added Solution for Find Minimum in Rotated Sorted Array --- .../solution.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Find-Minimum-in-Rotated-Sorted-Array/solution.py diff --git a/Find-Minimum-in-Rotated-Sorted-Array/solution.py b/Find-Minimum-in-Rotated-Sorted-Array/solution.py new file mode 100644 index 0000000..c950d6b --- /dev/null +++ b/Find-Minimum-in-Rotated-Sorted-Array/solution.py @@ -0,0 +1,20 @@ +class Solution: + def findMin(self, nums: List[int]) -> int: + res = nums[0] + + l = 0 + r =len(nums) - 1 + + while l <= r: + if nums[l] < nums[r]: + res = min(res, nums[l]) + break + + m = (l+r)//2 + res = min(res, nums[m]) + + if nums[l] <= nums[m]: + l = m + 1 + else: + r = m - 1 + return res From a9c295d16efd0bb177c414ac3d917094f3c29e4e Mon Sep 17 00:00:00 2001 From: Rifana-E Date: Wed, 26 Mar 2025 12:34:34 +0530 Subject: [PATCH 10/10] Added Solution for Search in Rotated Sorted Array --- Search-in-Rotated-Sorted-Array/solution.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Search-in-Rotated-Sorted-Array/solution.py diff --git a/Search-in-Rotated-Sorted-Array/solution.py b/Search-in-Rotated-Sorted-Array/solution.py new file mode 100644 index 0000000..3fd0337 --- /dev/null +++ b/Search-in-Rotated-Sorted-Array/solution.py @@ -0,0 +1,22 @@ +class Solution: + def search(self, nums: List[int], target: int) -> int: + + l = 0 + r =len(nums) - 1 + + while l <= r: + mid = (l+r)//2 + if nums[mid] == target: + return mid + if nums[l] <= nums[mid]: + if nums[l] <= target < nums[mid]: + r = mid -1 + else: + l = mid+1 + else: + if nums[mid]< target <= nums[r]: + l = mid+1 + else: + r = mid-1 + + return -1