From 1cf0e8feb1e8988e03f28274bd2554b47837d24d Mon Sep 17 00:00:00 2001 From: Amal Prasad <78908990+amalprasad0@users.noreply.github.com> Date: Tue, 18 Mar 2025 09:13:23 +0530 Subject: [PATCH 1/9] added solution for challenge 1 --- Two-sum_C1/two-sum.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Two-sum_C1/two-sum.py diff --git a/Two-sum_C1/two-sum.py b/Two-sum_C1/two-sum.py new file mode 100644 index 0000000..85e018b --- /dev/null +++ b/Two-sum_C1/two-sum.py @@ -0,0 +1,15 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + res=[] + numSet={} + for i in range(len(nums)): + if(target-nums[i] in numSet): + res.append(i) + res.append(numSet[target-nums[i]]) + numSet.pop(target-nums[i]) + else: + numSet[nums[i]]=i + return res + + +# TC=> O(n) and SC => O(n) \ No newline at end of file From cb09eb23d6b9159896f5c23dba80c1fdb8467277 Mon Sep 17 00:00:00 2001 From: Amal Prasad <78908990+amalprasad0@users.noreply.github.com> Date: Thu, 20 Mar 2025 08:16:26 +0530 Subject: [PATCH 2/9] Added solution for day 3 --- .../best-time-to-buy-and-sell.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 best-time-to-buy-and-sell/best-time-to-buy-and-sell.py diff --git a/best-time-to-buy-and-sell/best-time-to-buy-and-sell.py b/best-time-to-buy-and-sell/best-time-to-buy-and-sell.py new file mode 100644 index 0000000..a3f3175 --- /dev/null +++ b/best-time-to-buy-and-sell/best-time-to-buy-and-sell.py @@ -0,0 +1,14 @@ +class Solution: + def maxProfit(self, prices: List[int]) -> int: + l,r=0,1 + res=0 + + while(rprices[l]): + res=max(res,prices[r]-prices[l]) + else: + l=r + r+=1 + return res if res!=0 else 0 +# TC=o(n) +# SC=o(1) \ No newline at end of file From 370440dde9da552826b58088ca35258a36958166 Mon Sep 17 00:00:00 2001 From: Amal Prasad <78908990+amalprasad0@users.noreply.github.com> Date: Fri, 21 Mar 2025 08:05:42 +0530 Subject: [PATCH 3/9] Added Solution for contains duplicates --- contains-duplicate/contains-duplicate.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 contains-duplicate/contains-duplicate.py diff --git a/contains-duplicate/contains-duplicate.py b/contains-duplicate/contains-duplicate.py new file mode 100644 index 0000000..29002e4 --- /dev/null +++ b/contains-duplicate/contains-duplicate.py @@ -0,0 +1,9 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + numSet=set() + for num in nums: + if num in numSet: + return True + else: + numSet.add(num) + return False \ No newline at end of file From 4a77054e351ea8c92b9ccd430ebeda9dde45a30e Mon Sep 17 00:00:00 2001 From: Amal Prasad <78908990+amalprasad0@users.noreply.github.com> Date: Sun, 23 Mar 2025 10:16:28 +0530 Subject: [PATCH 4/9] Added Sum of Integer --- sum-of-integer/two-integer-sum.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 sum-of-integer/two-integer-sum.py diff --git a/sum-of-integer/two-integer-sum.py b/sum-of-integer/two-integer-sum.py new file mode 100644 index 0000000..fe70954 --- /dev/null +++ b/sum-of-integer/two-integer-sum.py @@ -0,0 +1,7 @@ +class Solution: + def getSum(self, a: int, b: int) -> int: + c=a+b + return c + +# TC: o(n) +# SC: o(n) \ No newline at end of file From 3241de9391d33d48839c8f2ad512e15bdcb143ec Mon Sep 17 00:00:00 2001 From: Amal Prasad <78908990+amalprasad0@users.noreply.github.com> Date: Mon, 24 Mar 2025 08:22:41 +0530 Subject: [PATCH 5/9] Add solution for product of array except self --- .../product-array-execpt-self.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 product-of-array-execpt-self/product-array-execpt-self.py diff --git a/product-of-array-execpt-self/product-array-execpt-self.py b/product-of-array-execpt-self/product-array-execpt-self.py new file mode 100644 index 0000000..2747977 --- /dev/null +++ b/product-of-array-execpt-self/product-array-execpt-self.py @@ -0,0 +1,15 @@ +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + result=[1] *len(nums) + left = [1] *len(nums) + right = [1] *len(nums) + for i in range(1,len(nums)): + left[i]=nums[i-1]*left[i-1] + for j in range(len(nums)-2,-1,-1): + right[j] = nums[j+1]*right[j+1] + for k in range(len(nums)): + result[k]= left[k]*right[k] + + return result +# TC: o(n) +# SC: 3o(n) -> o(n) \ No newline at end of file From 5f35470aa81caac6549beff18e8f6cca368ae8a9 Mon Sep 17 00:00:00 2001 From: Amal Prasad <78908990+amalprasad0@users.noreply.github.com> Date: Wed, 26 Mar 2025 00:11:30 +0530 Subject: [PATCH 6/9] Added solution for Day 7 --- sum-of-subarray/sum-of-subarry.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 sum-of-subarray/sum-of-subarry.py diff --git a/sum-of-subarray/sum-of-subarry.py b/sum-of-subarray/sum-of-subarry.py new file mode 100644 index 0000000..9069108 --- /dev/null +++ b/sum-of-subarray/sum-of-subarry.py @@ -0,0 +1,9 @@ +class Solution: + def maxSubArray(self, nums: List[int]) -> int: + currSum=nums[0] + maxSum=nums[0] + + for i in range(1,len(nums)): + currSum=max(nums[i],currSum+nums[i]) + maxSum=max(currSum,maxSum) + return maxSum \ No newline at end of file From fe8688a0498a4309c6aa24dfaa7f235aeaf07376 Mon Sep 17 00:00:00 2001 From: Amal Prasad <78908990+amalprasad0@users.noreply.github.com> Date: Wed, 26 Mar 2025 00:13:28 +0530 Subject: [PATCH 7/9] Added Solution for day 8 --- sum-of-product-array/solution.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sum-of-product-array/solution.py diff --git a/sum-of-product-array/solution.py b/sum-of-product-array/solution.py new file mode 100644 index 0000000..050a6db --- /dev/null +++ b/sum-of-product-array/solution.py @@ -0,0 +1,19 @@ +class Solution: + def maxProduct(self, arr: List[int]) -> int: + if not arr: + return 0 + + max_ending_here = arr[0] + min_ending_here = arr[0] + max_so_far = arr[0] + + for i in range(1, len(arr)): + if arr[i] < 0: + max_ending_here, min_ending_here = min_ending_here, max_ending_here + + max_ending_here = max(arr[i], max_ending_here * arr[i]) + min_ending_here = min(arr[i], min_ending_here * arr[i]) + + max_so_far = max(max_so_far, max_ending_here) + + return max_so_far \ No newline at end of file From 7a89a781648403d9a28fa50287645b91329fd7ee Mon Sep 17 00:00:00 2001 From: Amal Prasad <78908990+amalprasad0@users.noreply.github.com> Date: Wed, 26 Mar 2025 00:14:49 +0530 Subject: [PATCH 8/9] Added solution for day 9 --- find-min-in-rotated-arry/solution.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 find-min-in-rotated-arry/solution.py diff --git a/find-min-in-rotated-arry/solution.py b/find-min-in-rotated-arry/solution.py new file mode 100644 index 0000000..50516f4 --- /dev/null +++ b/find-min-in-rotated-arry/solution.py @@ -0,0 +1,18 @@ + +class Solution: + def findMin(self, nums: List[int]) -> int: + res=nums[0] + l,r=0,len(nums)-1 + while(l<=r): + if nums[l] < nums[r]: + res = min(res, nums[l]) + break + m=(r+l)//2 + res=min(res,nums[m]) + if(nums[l]<=nums[m]): + l=m+1 + else: + r=m-1 + return res + + \ No newline at end of file From 23affd54a0682acb45ab9e003782770c5bd0205a Mon Sep 17 00:00:00 2001 From: Amal Prasad <78908990+amalprasad0@users.noreply.github.com> Date: Sat, 29 Mar 2025 10:38:31 +0530 Subject: [PATCH 9/9] Add solution for searching in a rotated sorted array --- .../search-in-rotated-sorted-arrya.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 search-in-rotated-sorted-array/search-in-rotated-sorted-arrya.py diff --git a/search-in-rotated-sorted-array/search-in-rotated-sorted-arrya.py b/search-in-rotated-sorted-array/search-in-rotated-sorted-arrya.py new file mode 100644 index 0000000..82c338b --- /dev/null +++ b/search-in-rotated-sorted-array/search-in-rotated-sorted-arrya.py @@ -0,0 +1,21 @@ +class Solution: + def search(self, nums: List[int], target: int) -> int: + left,right=0,len(nums)-1 + while (left<=right): + mid=(right+left)//2 + if nums[mid]==target: + return mid + if nums[left]<=nums[mid]: + if nums[left] <=target