From 5a2e05869c4499feecb64403b54f4452c7438e10 Mon Sep 17 00:00:00 2001 From: MUHAMMED ZULFIKER A <54462409+M-zulfiker-A@users.noreply.github.com> Date: Tue, 18 Mar 2025 06:24:59 +0530 Subject: [PATCH 01/11] add readme --- Challenge-1/readme.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Challenge-1/readme.md diff --git a/Challenge-1/readme.md b/Challenge-1/readme.md new file mode 100644 index 0000000..1f6c3e5 --- /dev/null +++ b/Challenge-1/readme.md @@ -0,0 +1,2 @@ +Muhammed Zulfiker A +muhammedzulfiker\*\*\*\*@gmail.com From 48c623332a3abf4e103d6a1deed17c6d4b6b73dd Mon Sep 17 00:00:00 2001 From: MUHAMMED ZULFIKER A <54462409+M-zulfiker-A@users.noreply.github.com> Date: Tue, 18 Mar 2025 06:59:36 +0530 Subject: [PATCH 02/11] add solution to two-sum in typescript --- Challenge-1/two-sum.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Challenge-1/two-sum.ts diff --git a/Challenge-1/two-sum.ts b/Challenge-1/two-sum.ts new file mode 100644 index 0000000..7eb8805 --- /dev/null +++ b/Challenge-1/two-sum.ts @@ -0,0 +1,13 @@ +function twoSum(nums: number[], target: number): number[] { + const map: Map = new Map(); + for (let i = 0; i < nums.length; i++) { + const complement = target - nums[i]; + if (map.has(complement)) { + return [map.get(complement)!, i]; + } + map.set(nums[i], i); + } + return []; +} + +twoSum([2, 7, 11, 15], 9); // [0, 1] From 48dc5ae8b24069923be534f10a611b71b71169ac Mon Sep 17 00:00:00 2001 From: MUHAMMED ZULFIKER A <54462409+M-zulfiker-A@users.noreply.github.com> Date: Thu, 20 Mar 2025 07:05:48 +0530 Subject: [PATCH 03/11] add solution for buy and sell stock --- Challenge-1/Best Time to Buy and Sell Stock.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Challenge-1/Best Time to Buy and Sell Stock.ts diff --git a/Challenge-1/Best Time to Buy and Sell Stock.ts b/Challenge-1/Best Time to Buy and Sell Stock.ts new file mode 100644 index 0000000..2afa7b2 --- /dev/null +++ b/Challenge-1/Best Time to Buy and Sell Stock.ts @@ -0,0 +1,17 @@ +function maxProfit(prices: number[]): number { + let start, end; + start = 0; + end = 1; + let profit = 0; + while (end < prices.length) { + const difference = prices[end] - prices[start]; + if (difference > 0) { + end += 1; + profit = Math.max(profit, difference); + } else { + start = end; + end += 1; + } + } + return profit; +} From 6ebfe070362bdc922ca269eb7816a8fefc2e9ab1 Mon Sep 17 00:00:00 2001 From: MUHAMMED ZULFIKER A <54462409+M-zulfiker-A@users.noreply.github.com> Date: Fri, 21 Mar 2025 05:21:41 +0530 Subject: [PATCH 04/11] Add solution for contains duplicate --- Challenge-1/Contains duplicate.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Challenge-1/Contains duplicate.ts diff --git a/Challenge-1/Contains duplicate.ts b/Challenge-1/Contains duplicate.ts new file mode 100644 index 0000000..c87b5cf --- /dev/null +++ b/Challenge-1/Contains duplicate.ts @@ -0,0 +1,10 @@ +function containsDuplicate(nums: number[]): boolean { + const freqCounter = new Map() + for(let i = 0; i< nums.length; i++){ + if(freqCounter.get(nums[i])){ + return true + } + freqCounter.set(nums[i], 1) + } + return false +}; From d6981947d2faf13be128a0d4f5687334ed0ba0ad Mon Sep 17 00:00:00 2001 From: MUHAMMED ZULFIKER A <54462409+M-zulfiker-A@users.noreply.github.com> Date: Sat, 22 Mar 2025 05:03:48 +0530 Subject: [PATCH 05/11] Create Sum of Two Integers.ts --- Challenge-1/Sum of Two Integers.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Challenge-1/Sum of Two Integers.ts diff --git a/Challenge-1/Sum of Two Integers.ts b/Challenge-1/Sum of Two Integers.ts new file mode 100644 index 0000000..2cf1794 --- /dev/null +++ b/Challenge-1/Sum of Two Integers.ts @@ -0,0 +1,7 @@ +function getSum(a: number, b: number): number { + if(b === 0) { + return a + } + const carry = (a & b) << 1 + return getSum((a ^ b), carry) +}; From 5dea8ce4952551ba2df9b5e4d2563136912d3438 Mon Sep 17 00:00:00 2001 From: MUHAMMED ZULFIKER A <54462409+M-zulfiker-A@users.noreply.github.com> Date: Sun, 23 Mar 2025 06:51:23 +0530 Subject: [PATCH 06/11] Create Product of Array Except Self.ts --- Challenge-1/Product of Array Except Self.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Challenge-1/Product of Array Except Self.ts diff --git a/Challenge-1/Product of Array Except Self.ts b/Challenge-1/Product of Array Except Self.ts new file mode 100644 index 0000000..e5fa25a --- /dev/null +++ b/Challenge-1/Product of Array Except Self.ts @@ -0,0 +1,19 @@ +function productExceptSelf(nums: number[]): number[] { + let output = [] + for(let i = 0; i < nums.length ; i++){ + let previous = i === 0 ? 1 : output[i -1] + //prefix + if(i === 0 ){ + output.push(previous) + continue + } + output.push(previous * nums[i-1]) + } + + let postFix = nums.at(-1) + for(let i = nums.length - 2; i > -1 ; i--){ + output[i] = postFix * output[i] + postFix *= nums[i] + } + return output +}; From cb2973f7064f9696225db4303b3d9005eaaf16eb Mon Sep 17 00:00:00 2001 From: MUHAMMED ZULFIKER A <54462409+M-zulfiker-A@users.noreply.github.com> Date: Mon, 24 Mar 2025 07:18:22 +0530 Subject: [PATCH 07/11] Create Maximum Subarray.ts --- Challenge-1/Maximum Subarray.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Challenge-1/Maximum Subarray.ts diff --git a/Challenge-1/Maximum Subarray.ts b/Challenge-1/Maximum Subarray.ts new file mode 100644 index 0000000..00eaae8 --- /dev/null +++ b/Challenge-1/Maximum Subarray.ts @@ -0,0 +1,10 @@ +function maxSubArray(nums: number[]): number { + let currSum = nums[0] + let maxSum = currSum + for(let i = 1; i< nums.length; i++){ + currSum = Math.max(nums[i], (currSum + nums[i])) + maxSum = Math.max(maxSum, currSum) + } + return maxSum + +}; From e5b9bea6cdf96ff77e55539c0bcc0262867fc528 Mon Sep 17 00:00:00 2001 From: MUHAMMED ZULFIKER A <54462409+M-zulfiker-A@users.noreply.github.com> Date: Tue, 25 Mar 2025 05:49:12 +0530 Subject: [PATCH 08/11] Create Maximum Product Subarray.ts --- Challenge-1/Maximum Product Subarray.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Challenge-1/Maximum Product Subarray.ts diff --git a/Challenge-1/Maximum Product Subarray.ts b/Challenge-1/Maximum Product Subarray.ts new file mode 100644 index 0000000..b6c2473 --- /dev/null +++ b/Challenge-1/Maximum Product Subarray.ts @@ -0,0 +1,14 @@ +function maxProduct(nums: number[]): number { + let currMin = nums[0] + let currMax = nums[0] + let maxProd = nums[0] + + for(let i = 1; i< nums.length; i++){ + let temp = currMax * nums[i] + currMax = Math.max(nums[i],temp, currMin * nums[i]) + currMin = Math.min(nums[i],temp, currMin * nums[i]) + maxProd = Math.max(currMax, maxProd) + } + + return maxProd +}; From 633fdb3b0c1a841b4317b692c242a72837d03bf2 Mon Sep 17 00:00:00 2001 From: MUHAMMED ZULFIKER A <54462409+M-zulfiker-A@users.noreply.github.com> Date: Wed, 26 Mar 2025 07:36:40 +0530 Subject: [PATCH 09/11] Create Find Minimum in Rotated Sorted Array.ts --- .../Find Minimum in Rotated Sorted Array.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Challenge-1/Find Minimum in Rotated Sorted Array.ts diff --git a/Challenge-1/Find Minimum in Rotated Sorted Array.ts b/Challenge-1/Find Minimum in Rotated Sorted Array.ts new file mode 100644 index 0000000..1b8aaf9 --- /dev/null +++ b/Challenge-1/Find Minimum in Rotated Sorted Array.ts @@ -0,0 +1,24 @@ +function findMin(nums: number[]): number { + let l,r,m + l= 0; + r = nums.length -1 + let res = nums[0] + do { + m = Math.floor((l + r) / 2) + let left = nums[l] + let right = nums[r] + let curr = nums[m] + //check for sorted array + if(left < right) { + return Math.min(res, left) + } + res = Math.min(curr, res) + if(left <= curr) { + l = m + 1 + } else if(right >= curr) { + r = m - 1 + } + + }while(l<=r); + return res +}; From 6a381587a03d5c3563705822cda36ceb68cf1bd6 Mon Sep 17 00:00:00 2001 From: MUHAMMED ZULFIKER A <54462409+M-zulfiker-A@users.noreply.github.com> Date: Thu, 27 Mar 2025 05:00:35 +0530 Subject: [PATCH 10/11] Create Search in Rotated Sorted Array.ts --- Challenge-1/Search in Rotated Sorted Array.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Challenge-1/Search in Rotated Sorted Array.ts diff --git a/Challenge-1/Search in Rotated Sorted Array.ts b/Challenge-1/Search in Rotated Sorted Array.ts new file mode 100644 index 0000000..d491204 --- /dev/null +++ b/Challenge-1/Search in Rotated Sorted Array.ts @@ -0,0 +1,27 @@ +function search(nums: number[], target: number): number { + let l,r,m + l= 0; + r = nums.length -1 + + while(l<=r){ + m = Math.floor((l + r) / 2) + if(nums[m] === target) { + return m + } + if(nums[l] <= nums[m]){ + if(target <= nums[m] && target >= nums[l]){ + r = m - 1 + } else { + l = m + 1 + } + + } else { + if(target >= nums[m] && target <= nums[r]){ + l = m + 1 + } else { + r = m - 1 + } + } + } + return -1 +}; From a438e695cd17b53f3d646cd16a17b5fd522e6d1a Mon Sep 17 00:00:00 2001 From: MUHAMMED ZULFIKER A <54462409+M-zulfiker-A@users.noreply.github.com> Date: Fri, 28 Mar 2025 06:41:38 +0530 Subject: [PATCH 11/11] Create 3 Sum.ts --- Challenge-1/3 Sum.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Challenge-1/3 Sum.ts diff --git a/Challenge-1/3 Sum.ts b/Challenge-1/3 Sum.ts new file mode 100644 index 0000000..baaa6e4 --- /dev/null +++ b/Challenge-1/3 Sum.ts @@ -0,0 +1,30 @@ +function threeSum(nums: number[]): number[][] { + const sortedNums = nums.toSorted((a,b) => a - b) + let prevFirst = null + let result = [] + for(let i=0; i< nums.length ; i++) { + let first = sortedNums[i] + if(prevFirst === first){ + continue + } + let j,k + j = i + 1 + k = nums.length - 1 + while(j