From 17c308fbabbe3817bac4d0ad554586ad605dfa54 Mon Sep 17 00:00:00 2001 From: Asish Jose Date: Wed, 23 Apr 2025 15:39:26 +0530 Subject: [PATCH 01/10] Added solution for Challenge 1 --- Challenge-1/solution.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 Challenge-1/solution.py diff --git a/Challenge-1/solution.py b/Challenge-1/solution.py new file mode 100644 index 0000000..9b0bf51 --- /dev/null +++ b/Challenge-1/solution.py @@ -0,0 +1 @@ +#here my solution goes \ No newline at end of file From ce4200ffc62c99a2c6d508d47e5be05b4084563a Mon Sep 17 00:00:00 2001 From: Asish Jose Date: Wed, 23 Apr 2025 16:43:02 +0530 Subject: [PATCH 02/10] Added solution for challenge 1 --- Challenge-1/two_sum.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Challenge-1/two_sum.py diff --git a/Challenge-1/two_sum.py b/Challenge-1/two_sum.py new file mode 100644 index 0000000..9d56efb --- /dev/null +++ b/Challenge-1/two_sum.py @@ -0,0 +1,8 @@ +class Solution: + def twoSum(self, nums: list[int], target: int) -> list[int]: + hash = {} + for i in range(len(nums)): + temp = target - nums[i] + if temp in hash: + return [hash[temp], i] + hash[nums[i]] = i From 542936c5e9d8a7316e9f0b9261ea0a523a09a858 Mon Sep 17 00:00:00 2001 From: Asish Jose Date: Thu, 24 Apr 2025 13:38:37 +0530 Subject: [PATCH 03/10] Adding solution for Challege 2 --- Challenge-2/Best_time_to_buy_and_sell_stock.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Challenge-2/Best_time_to_buy_and_sell_stock.py diff --git a/Challenge-2/Best_time_to_buy_and_sell_stock.py b/Challenge-2/Best_time_to_buy_and_sell_stock.py new file mode 100644 index 0000000..57b75d6 --- /dev/null +++ b/Challenge-2/Best_time_to_buy_and_sell_stock.py @@ -0,0 +1,11 @@ +class Solution: + def maxProfit(self, prices: list[int]) -> int: + max_profit = 0 + l = 0 + for r in range(1,len(prices)): + if prices[r]>prices[l]: + profit = prices[r]-prices[l] + max_profit = max(profit, max_profit) + else: + l = r + return max_profit \ No newline at end of file From daf38cfd624d602f472869feba6d1ebe47690918 Mon Sep 17 00:00:00 2001 From: Asish Jose Date: Thu, 24 Apr 2025 15:56:33 +0530 Subject: [PATCH 04/10] Added solution for Challenge 3 --- "\303\207hallenge-3/contains_duplicate.py" | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 "\303\207hallenge-3/contains_duplicate.py" diff --git "a/\303\207hallenge-3/contains_duplicate.py" "b/\303\207hallenge-3/contains_duplicate.py" new file mode 100644 index 0000000..55b0677 --- /dev/null +++ "b/\303\207hallenge-3/contains_duplicate.py" @@ -0,0 +1,8 @@ +class Solution: + def containsDuplicate(self, nums: list[int]) -> bool: + seen = set() + for num in nums: + if num in seen: + return True + seen.add(num) + return False \ No newline at end of file From 5a339b418089167c319044550455edf782504972 Mon Sep 17 00:00:00 2001 From: Asish Jose Date: Fri, 25 Apr 2025 10:50:53 +0530 Subject: [PATCH 05/10] Added solution for Challenge 4 --- Challenge-4/product_of_array_except_self.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Challenge-4/product_of_array_except_self.py diff --git a/Challenge-4/product_of_array_except_self.py b/Challenge-4/product_of_array_except_self.py new file mode 100644 index 0000000..410952e --- /dev/null +++ b/Challenge-4/product_of_array_except_self.py @@ -0,0 +1,14 @@ +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 j in range(n - 1, -1, -1): + answer[j] *= suffix + suffix *= nums[j] + return answer + From 02e3cf217d47d7670bd09e8a0e4e47aa4e27815f Mon Sep 17 00:00:00 2001 From: Asish Jose Date: Thu, 1 May 2025 11:38:25 +0530 Subject: [PATCH 06/10] Added solution for Challenge 5 --- Challenge-5/max_subarray.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Challenge-5/max_subarray.py diff --git a/Challenge-5/max_subarray.py b/Challenge-5/max_subarray.py new file mode 100644 index 0000000..934af27 --- /dev/null +++ b/Challenge-5/max_subarray.py @@ -0,0 +1,11 @@ +class Solution: + def maxSubArray(self, nums: list[int]) -> int: + max_sum = nums[0] + curr_sum = 0 + for n in nums: + if curr_sum<0: + curr_sum=0 + curr_sum += n + if max_sum Date: Thu, 8 May 2025 09:37:25 +0530 Subject: [PATCH 07/10] Added solution for Challenge 6 --- Challenge-6/max_product_subarrray.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Challenge-6/max_product_subarrray.py diff --git a/Challenge-6/max_product_subarrray.py b/Challenge-6/max_product_subarrray.py new file mode 100644 index 0000000..54e9107 --- /dev/null +++ b/Challenge-6/max_product_subarrray.py @@ -0,0 +1,10 @@ +class Solution: + def maxProduct(self, nums: list[int]) -> int: + result = nums[0] + curmax, curmin = 1,1 + for n in nums: + temp = curmax*n + curmax = max(temp, curmin*n, n) + curmin = min(temp, curmin*n, n) + result = max(curmax, result) + return result \ No newline at end of file From 846ad59c7718d4ccfdf683cec5c8b1a4e7630ad7 Mon Sep 17 00:00:00 2001 From: Asish Jose Date: Thu, 8 May 2025 10:52:56 +0530 Subject: [PATCH 08/10] Added solution for Challenge 7 --- Challenge-7/min_in_rotated_sorted_array.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Challenge-7/min_in_rotated_sorted_array.py diff --git a/Challenge-7/min_in_rotated_sorted_array.py b/Challenge-7/min_in_rotated_sorted_array.py new file mode 100644 index 0000000..3a23bf4 --- /dev/null +++ b/Challenge-7/min_in_rotated_sorted_array.py @@ -0,0 +1,16 @@ +class Solution: + def findMin(self, nums: list[int]) -> int: + n = len(nums) + left = 0 + right = n-1 + if nums[left]nums[mid+1]: + return nums[mid+1] + else: + if nums[mid]>nums[0]: + right = mid + else: + left = mid From 26c858221f9f708e02a8765c17053b74ec71becc Mon Sep 17 00:00:00 2001 From: Asish Jose Date: Wed, 14 May 2025 17:35:55 +0530 Subject: [PATCH 09/10] Added solution for Challenge 8 --- Challenge-8/search_in_sorted_rotated_array.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Challenge-8/search_in_sorted_rotated_array.py diff --git a/Challenge-8/search_in_sorted_rotated_array.py b/Challenge-8/search_in_sorted_rotated_array.py new file mode 100644 index 0000000..2b14aef --- /dev/null +++ b/Challenge-8/search_in_sorted_rotated_array.py @@ -0,0 +1,21 @@ +class Solution: + def search(self, nums: list[int], target: int) -> int: + left = 0 + right = len(nums) - 1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] == target: + return mid + # left half is sorted + if nums[left] <= nums[mid]: + if nums[left] <= target < nums[mid]: + right = mid-1 + else: + left = mid+1 + # right half is sorted + else: + if nums[mid] < target <= nums[right]: + left = mid+1 + else: + right = mid-1 + return -1 \ No newline at end of file From fc0c04861ba5ce91d6a98c35ce91f3f27bb1dfcd Mon Sep 17 00:00:00 2001 From: Asish Jose Date: Fri, 16 May 2025 11:39:17 +0530 Subject: [PATCH 10/10] Added solution for Challenge 9 --- Challenge-9/three_sum.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Challenge-9/three_sum.py diff --git a/Challenge-9/three_sum.py b/Challenge-9/three_sum.py new file mode 100644 index 0000000..5bae42c --- /dev/null +++ b/Challenge-9/three_sum.py @@ -0,0 +1,32 @@ +class Solution: + def threeSum(self, nums: list[int]) -> list[list[int]]: + nums.sort() + n = len(nums) + result=[] + + for i in range(n): + if i>0 and nums[i]==nums[i-1]: + continue + + left,right = i+1,n-1 + + while left