From e302428472c3dc0d83a599b894ac96ae159ba479 Mon Sep 17 00:00:00 2001 From: siyadmohammed Date: Thu, 27 Mar 2025 05:25:49 +0530 Subject: [PATCH 1/6] Added solution for Two Sum --- Challenge-1/two-sum.py | 15 +++++++++++++++ 1 file changed, 15 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..3cfd199 --- /dev/null +++ b/Challenge-1/two-sum.py @@ -0,0 +1,15 @@ +class Solution(object): + def twoSum(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: List[int] + """ + prev_map = dict() + for i, num in enumerate(nums): + if target - num in prev_map: + return(i , prev_map[target-num]) + else: + prev_map[num] = i + + return -1 \ No newline at end of file From e4c0b33c18c81b60b224a3e834b9a24d923f3739 Mon Sep 17 00:00:00 2001 From: siyadmohammed Date: Thu, 27 Mar 2025 06:56:23 +0530 Subject: [PATCH 2/6] maximum profit solution for Challenge 2 --- Challenge-2/maxprofit.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Challenge-2/maxprofit.py diff --git a/Challenge-2/maxprofit.py b/Challenge-2/maxprofit.py new file mode 100644 index 0000000..665b26a --- /dev/null +++ b/Challenge-2/maxprofit.py @@ -0,0 +1,18 @@ +class Solution(object): + def maxProfit(self, prices): + """ + :type prices: List[int] + :rtype: int + """ + min_price = prices[0] + max_price = 0 + profit = 0 + + for price in prices: + if price < min_price: + min_price = price + max_price = price + elif price > max_price: + max_price = price + profit = max(max_price - min_price, profit) + return profit \ No newline at end of file From d0437f4a24546b14b40da36fc68c554c46f5eea9 Mon Sep 17 00:00:00 2001 From: siyadmohammed Date: Thu, 27 Mar 2025 07:14:35 +0530 Subject: [PATCH 3/6] return true or false if duplicate element is present in list --- Challenge-3/duplicatefinding.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Challenge-3/duplicatefinding.py diff --git a/Challenge-3/duplicatefinding.py b/Challenge-3/duplicatefinding.py new file mode 100644 index 0000000..9a749b4 --- /dev/null +++ b/Challenge-3/duplicatefinding.py @@ -0,0 +1,3 @@ +class Solution(object): + def containsDuplicate(self, nums): + return len(nums) != len(set(nums)) \ No newline at end of file From 9d93e7a71dc712343bc065105d1e6ae965ede001 Mon Sep 17 00:00:00 2001 From: siyadmohammed Date: Sat, 29 Mar 2025 06:56:38 +0530 Subject: [PATCH 4/6] sum of tow integers with XOR and AND operation --- Challenge-4/sumofintegers.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Challenge-4/sumofintegers.py diff --git a/Challenge-4/sumofintegers.py b/Challenge-4/sumofintegers.py new file mode 100644 index 0000000..9547add --- /dev/null +++ b/Challenge-4/sumofintegers.py @@ -0,0 +1,14 @@ +class Solution(object): + def getSum(self, a, b): + """ + :type a: int + :type b: int + :rtype: int + """ + bitshortner = 0xffffffff + + while(b & bitshortner) > 0: + carry = (a&b)<<1 + a =(a^b) + b = carry + return (a&bitshortner) if b > 0 else a \ No newline at end of file From c35909afc5dbf325ef244a9a0ca44c89e1615ab2 Mon Sep 17 00:00:00 2001 From: siyadmohammed Date: Sat, 29 Mar 2025 08:33:10 +0530 Subject: [PATCH 5/6] product of array using prefix and postfix --- Challenge-6/productofarray.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Challenge-6/productofarray.py diff --git a/Challenge-6/productofarray.py b/Challenge-6/productofarray.py new file mode 100644 index 0000000..a2423b3 --- /dev/null +++ b/Challenge-6/productofarray.py @@ -0,0 +1,12 @@ +def productExceptSelf(nums): + res = [1]* len(nums) + + prefix = 1 + for i in range(len(nums)): + res[i] = prefix + prefix = prefix*nums[i] + postfix = 1 + for i in range(len(nums) -1,-1,-1): + res[i]= res[i]*postfix + postfix = postfix * nums[i] + return res From f18a2089ad1985ec6f9bd7314d29ca69a86f7dac Mon Sep 17 00:00:00 2001 From: siyadmohammed Date: Sun, 30 Mar 2025 10:56:50 +0530 Subject: [PATCH 6/6] computed the sum of maximum subarray in a array --- Challenge-7/maxsubarray.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Challenge-7/maxsubarray.py diff --git a/Challenge-7/maxsubarray.py b/Challenge-7/maxsubarray.py new file mode 100644 index 0000000..543541e --- /dev/null +++ b/Challenge-7/maxsubarray.py @@ -0,0 +1,14 @@ +class Solution(object): + def maxSubArray(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + maxsubarr = nums[0] + carrsum = 0 + for n in nums: + if carrsum < 0: + carrsum = 0 + carrsum += n + maxsubarr = max(maxsubarr , carrsum) + return maxsubarr \ No newline at end of file