From ba35594546e3e98e610aea1d6b39cac056bef91a Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Mon, 17 Mar 2025 16:46:49 +0530 Subject: [PATCH 01/16] Challenge 1 two sum solution --- Challenge-01/two-sum.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Challenge-01/two-sum.js diff --git a/Challenge-01/two-sum.js b/Challenge-01/two-sum.js new file mode 100644 index 0000000..aaee71d --- /dev/null +++ b/Challenge-01/two-sum.js @@ -0,0 +1,24 @@ +/** + * @param {number[]} nums + * @param {number} target + * @return {number[]} + */ + + /** + Approach : hashmap + + */ + var twoSum = function(nums, target) { + const prevMap = new Map() + + + for(let i= 0 ; i < nums.length ; i++){ + let answer = target - nums[i] + if(prevMap.has(answer)){ + return [prevMap.get(answer),i] + }else{ + prevMap.set(nums[i],i) + } + } + +}; \ No newline at end of file From fe3abe624e86855497b683f576a949d36d773460 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Mon, 17 Mar 2025 16:51:44 +0530 Subject: [PATCH 02/16] Updated Readme --- README.md | 150 +----------------------------------------------------- 1 file changed, 2 insertions(+), 148 deletions(-) diff --git a/README.md b/README.md index d922b9d..2ec271e 100644 --- a/README.md +++ b/README.md @@ -1,148 +1,2 @@ -# GitHub Guide for Submitting Challenge Solutions - -Welcome to the GitHub repository for coding challenges! This guide will walk you through the process of creating a branch under your name and uploading your solution files step by step. If you are new to Git and GitHub, follow these instructions carefully. - ---- - -## πŸš€ Setting Up Git and GitHub - -### 1️⃣ Install Git -If you haven't installed Git yet, download and install it from [Git's official website](https://git-scm.com/downloads). - -### 2️⃣ Create a GitHub Account -If you don’t have a GitHub account, create one at [GitHub](https://github.com/). - -### 3️⃣ Fork the Repository -1. Go to the repository URL shared by your instructor. -2. Click on the **Fork** button in the top-right corner to create a copy in your GitHub account. - -### 4️⃣ Clone the Repository Locally -1. Open **Terminal** (Linux/macOS) or **Command Prompt/Powershell** (Windows). -2. Run the following command, replacing `your-username` with your GitHub username: - - ```sh - git clone https://github.com/WeCode-Community-Dev/blind-75-challenge.git - ``` - -3. Navigate into the repository folder: - - ```sh - cd blind-75-challenge - ``` - ---- - -## 🌿 Creating a Branch Under Your Name -Each student must create a separate branch with their name before making any changes. - -1. Check the current branches: - - ```sh - git branch - ``` - -2. Create a new branch with your name (make sure this is unique - add some unique number or characters to make sure it is not already there): - - ```sh - git checkout -b your-branch-name - ``` - -3. Verify the branch was created and switched to it: - - ```sh - git branch - ``` - - Your name should now be highlighted, meaning you are on that branch. - ---- - -## πŸ” Setting Upstream and Pulling Latest Changes -Before working on a new challenge, ensure your repository is up to date. - -1. Add the original repository as the upstream remote (only required once): - - ```sh - git remote add upstream https://github.com/WeCode-Community-Dev/blind-75-challenge.git - ``` - -2. Fetch the latest changes: - - ```sh - git fetch upstream - ``` - -3. Merge the latest changes into your branch: - - ```sh - git merge upstream/main - ``` - ---- - -## ✏️ Adding Your Challenge Solution -Upload only the solution file for each challenge (e.g., `solution.py`, `solution.cpp`, `solution.java`). -you can name the file .py or .cpp or .java etc. -example: two-sum.py or two-sum.cpp or two-sum.java as per the programming language you choose - -1. Navigate to the folder for the challenge you are working on. -2. Place your solution file inside the appropriate challenge folder. - -Example structure: - -``` -repository-name/ -β”‚-- Challenge-1/ -β”‚ β”‚-- solution.py # Your file -β”‚-- Challenge-2/ -β”‚ β”‚-- solution.cpp # Another file -``` - ---- - -## πŸ“€ Committing and Pushing Your Code - -Replace the "challenge-1" with problem name - -1. Add the file you modified: - - ```sh - git add Challenge-1/solution.py - ``` - -2. Commit your changes with a meaningful message: - - ```sh - git commit -m "Added solution for Challenge 1" - ``` - -3. Push your branch to your GitHub repository: - - ```sh - git push origin your-branch-name - ``` - ---- - -## πŸ”„ Creating a Pull Request (Not Required) -Once you've pushed your changes, you need to create a **Pull Request (PR)**. - -1. Go to your GitHub repository. -2. Switch to your branch (`your-branch-name`). -3. Click on **Compare & pull request**. -4. Add a meaningful **title** and **description**. -5. Click **Create pull request**. - -Your code will now be reviewed and merged by the instructor! πŸŽ‰ - ---- - -## ❗ Important Rules -βœ… Always create a branch under your name. -βœ… Upload only the solution file (no unnecessary files or folders). -βœ… Keep your repository updated by pulling the latest changes. -βœ… Use meaningful commit messages. -βœ… Create a pull request for every challenge. - -Happy coding! πŸš€ - +Name : Jeevan Abraham Joji +Email : ambrahamjeevan@gmail.com \ No newline at end of file From 08f1a2e4cb2d40d5f7dbc7dff5de93426092a977 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Mon, 17 Mar 2025 16:54:10 +0530 Subject: [PATCH 03/16] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2ec271e..7ed608e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -Name : Jeevan Abraham Joji -Email : ambrahamjeevan@gmail.com \ No newline at end of file +

Name : Jeevan Abraham Joji


+

Email : ambrahamjeevan@gmail.com

From 1adf7ef3f45f90b905d604f24b80d4d253a76c44 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Wed, 19 Mar 2025 21:06:32 +0530 Subject: [PATCH 04/16] Challenge 03 best time to buy and sell stock completed --- Challenge-03/best-timeTo-buy-sell.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Challenge-03/best-timeTo-buy-sell.js diff --git a/Challenge-03/best-timeTo-buy-sell.js b/Challenge-03/best-timeTo-buy-sell.js new file mode 100644 index 0000000..0e67474 --- /dev/null +++ b/Challenge-03/best-timeTo-buy-sell.js @@ -0,0 +1,15 @@ +/** + * @param {number[]} prices + * @return {number} + */ +var maxProfit = function(prices) { + let minPrice = Infinity + let maxPrice = 0 + + for(let i of prices){ + minPrice = Math.min(minPrice,i) + const profit = i-minPrice + maxPrice = Math.max(maxPrice,profit) + } + return maxPrice +}; \ No newline at end of file From 83f839fada6d2d2f2eb19c9c0927b20b63ccdc6b Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Fri, 21 Mar 2025 04:48:20 +0530 Subject: [PATCH 05/16] Challenge 4 solution submitted --- Challenge-04/contains-duplicate.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Challenge-04/contains-duplicate.py diff --git a/Challenge-04/contains-duplicate.py b/Challenge-04/contains-duplicate.py new file mode 100644 index 0000000..df1a8d9 --- /dev/null +++ b/Challenge-04/contains-duplicate.py @@ -0,0 +1,8 @@ +class Solution(object): + def containsDuplicate(self,nums): + seen = set() + for i in nums: + if i in seen: + return True + seen.add(i) + return False \ No newline at end of file From 0ae5a0badcb3b3a50bad67e3af68dfbc1b563828 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Fri, 21 Mar 2025 16:55:02 +0530 Subject: [PATCH 06/16] Challenge 5 completed --- Challenge-05/sum-without-arithematic-operator.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Challenge-05/sum-without-arithematic-operator.js diff --git a/Challenge-05/sum-without-arithematic-operator.js b/Challenge-05/sum-without-arithematic-operator.js new file mode 100644 index 0000000..63bc55b --- /dev/null +++ b/Challenge-05/sum-without-arithematic-operator.js @@ -0,0 +1,15 @@ +/** + * @param {number} a + * @param {number} b + * @return {number} + */ +var getSum = function(a, b) { + + while (b !== 0) { + let carry = a & b; // Find carry bits + a = a ^ b; // Add without carry + b = carry << 1; // Shift carry left + } + return a; + +}; \ No newline at end of file From 857f01e5a1d970e8d9182bcd215d2b9365679c20 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Sat, 22 Mar 2025 13:47:50 +0530 Subject: [PATCH 07/16] Challenge 06 solution created --- Challenge-06/product-of-arrayExcept-selft.js | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Challenge-06/product-of-arrayExcept-selft.js diff --git a/Challenge-06/product-of-arrayExcept-selft.js b/Challenge-06/product-of-arrayExcept-selft.js new file mode 100644 index 0000000..5bd51b5 --- /dev/null +++ b/Challenge-06/product-of-arrayExcept-selft.js @@ -0,0 +1,31 @@ +/** + * @param {number[]} nums + * @return {number[]} + */ + +/** +approach : prefix , sufix +step1 : calculate all prefix in one loop and create an array of prefix +step 2 : in second loop modify prefix[i] *= suffix + : make sufix *= original[i] + */ + var productExceptSelf = function(nums) { + let answer = [] + let len = nums.length + let productofPrifix = 1 + let productofSufix = 1 + for(let i = 0 ; i < len ; i++){ + answer[i] = productofPrifix + productofPrifix *= nums[i] + } + + for(let j = len-1 ; j >= 0 ; j--){ + answer[j] *= productofSufix + productofSufix *= nums[j] + } + + return answer + + + + }; \ No newline at end of file From 291f6b4cf36e5eb8edbc87538a73e74216629b36 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Mon, 24 Mar 2025 01:32:57 +0530 Subject: [PATCH 08/16] completed challenge 06 --- Challenge-07/subarray-sum.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Challenge-07/subarray-sum.js diff --git a/Challenge-07/subarray-sum.js b/Challenge-07/subarray-sum.js new file mode 100644 index 0000000..ace9986 --- /dev/null +++ b/Challenge-07/subarray-sum.js @@ -0,0 +1,16 @@ +/** + * @param {number[]} nums + * @return {number} + */ +var maxSubArray = function(nums) { + let curSum = 0; + let maxSum = nums[0]; + + for (let i of nums) { + if (curSum < 0) curSum = 0; + curSum += i; + maxSum = Math.max(maxSum, curSum); + } + + return maxSum; +}; \ No newline at end of file From f9b3348912b77e1e096623d8af5a7cb267714413 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Mon, 24 Mar 2025 21:16:41 +0530 Subject: [PATCH 09/16] Challenge 8 solution added (maximum product of subArray) --- Challenge-08/max-prod-of-subArray.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Challenge-08/max-prod-of-subArray.js diff --git a/Challenge-08/max-prod-of-subArray.js b/Challenge-08/max-prod-of-subArray.js new file mode 100644 index 0000000..d412efe --- /dev/null +++ b/Challenge-08/max-prod-of-subArray.js @@ -0,0 +1,21 @@ +/** + * @param {number[]} nums + * @return {number} + */ + +var maxProduct = function(nums) { + let curMin = 1 + let curMax = 1 + let result = nums[0] + + + for(let i of nums){ + + let temp = curMin* i + curMin = Math.min(i,curMax*i,temp,) + curMax = Math.max(i,curMax*i,temp) + result = Math.max(result,curMax) + } + + return result +}; \ No newline at end of file From d66966e80475c2b718e9b207a7d52290f1e10fd6 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Tue, 25 Mar 2025 14:16:44 +0530 Subject: [PATCH 10/16] Challenge 09 solution submitted --- Challenge-09/minimumIn-rotated-sortedArray.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Challenge-09/minimumIn-rotated-sortedArray.js diff --git a/Challenge-09/minimumIn-rotated-sortedArray.js b/Challenge-09/minimumIn-rotated-sortedArray.js new file mode 100644 index 0000000..2533d34 --- /dev/null +++ b/Challenge-09/minimumIn-rotated-sortedArray.js @@ -0,0 +1,34 @@ +/** + * @param {number[]} nums + * @return {number} + */ + + /** + Approach : Binary search since solution needs to be in o(log n) + + step 1 : loop till left < right + step 2 : mid = fllor((left+right)/2) + step 2 : if(mid > right) it means smaller value is in right so we mode left to mid + 1 + : else right = mid and find its mid and continue + : when the left > right loop exits and last nums[left] will be the smallest + + */ + + +// condition the solution should be of o(log n) time complexity + var findMin = function(nums) { + let left = 0 + let right = nums.length-1 + while(left < right){ + let mid = Math.floor((left+right)/2) + + if(nums[mid] > nums[right]){ + left = mid+1 + }else{ + right = mid + } + } + + return nums[left] + + }; \ No newline at end of file From 5cec672b858d6d85017923cbdb8ff2c4d1e3fa00 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Thu, 27 Mar 2025 01:15:58 +0530 Subject: [PATCH 11/16] Challenge 10 completed search target in rotated sorted array --- Challenge-10/searchIn-sortedArray.js | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Challenge-10/searchIn-sortedArray.js diff --git a/Challenge-10/searchIn-sortedArray.js b/Challenge-10/searchIn-sortedArray.js new file mode 100644 index 0000000..c11a0cd --- /dev/null +++ b/Challenge-10/searchIn-sortedArray.js @@ -0,0 +1,31 @@ +/** + * @param {number[]} nums + * @param {number} target + * @return {number} + */ +var search = function(nums, target) { + let left = 0, right = nums.length - 1; + + while (left <= right) { + let mid = Math.floor((left + right) / 2); + + if (nums[mid] === target) return mid; + + // Identify which half is sorted + if (nums[left] <= nums[mid]) { // Left half is sorted + if (nums[left] <= target && target < nums[mid]) { + right = mid - 1; // Search in left half + } else { + left = mid + 1; // Search in right half + } + } else { // Right half is sorted + if (nums[mid] < target && target <= nums[right]) { + left = mid + 1; // Search in right half + } else { + right = mid - 1; // Search in left half + } + } + } + + return -1; // Target not found +}; \ No newline at end of file From a3d4a5315d3bdbac4e1f20b98f47cd3afb27bd49 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Fri, 28 Mar 2025 10:58:46 +0530 Subject: [PATCH 12/16] three-sum --- Chalenge-11/three-sum.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Chalenge-11/three-sum.js diff --git a/Chalenge-11/three-sum.js b/Chalenge-11/three-sum.js new file mode 100644 index 0000000..6f3b224 --- /dev/null +++ b/Chalenge-11/three-sum.js @@ -0,0 +1,34 @@ +/** + * @param {number[]} nums + * @return {number[][]} + */ +var threeSum = function(num) { + let res = [] + let len = num.length + let nums = num.sort((a,b)=> a-b) + + for(let i = 0 ; i< nums.length ; i++){ + if(i>0 && nums[i] ==nums[i-1]) continue; + + let L = i+1; + let R = len-1 + + while(L0){ + R -= 1 + } + else if(sum<0){ + L += 1 + } + else{ + res.push([nums[i],nums[L],nums[R]]) + L+=1; + while(L Date: Sat, 29 Mar 2025 05:34:30 +0530 Subject: [PATCH 13/16] Challenge 12 container with most water --- {Chalenge-11 => Challenge-11}/three-sum.js | 0 Challenge-12/container-with-most-water.js | 27 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) rename {Chalenge-11 => Challenge-11}/three-sum.js (100%) create mode 100644 Challenge-12/container-with-most-water.js diff --git a/Chalenge-11/three-sum.js b/Challenge-11/three-sum.js similarity index 100% rename from Chalenge-11/three-sum.js rename to Challenge-11/three-sum.js diff --git a/Challenge-12/container-with-most-water.js b/Challenge-12/container-with-most-water.js new file mode 100644 index 0000000..11f3fc7 --- /dev/null +++ b/Challenge-12/container-with-most-water.js @@ -0,0 +1,27 @@ +/** + * @param {number[]} height + * @return {number} + */ +var maxArea = function(height) { + let left = 0, right = height.length - 1; + let maxWater = 0; + + while (left < right) { + // Calculate the area with the current left and right pointers + const minHeight = Math.min(height[left], height[right]); + const width = right - left; + const area = minHeight * width; + + // Update the maximum area + maxWater = Math.max(maxWater, area); + + // Move the pointer pointing to the smaller height + if (height[left] < height[right]) { + left++; + } else { + right--; + } + } + + return maxWater; +}; \ No newline at end of file From 19f13ad88107c948f41634a3c71b4265fa313315 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Fri, 4 Apr 2025 10:47:11 +0530 Subject: [PATCH 14/16] Challenge 13 completed --- Challenge-13/find-setBits.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Challenge-13/find-setBits.js diff --git a/Challenge-13/find-setBits.js b/Challenge-13/find-setBits.js new file mode 100644 index 0000000..83c71f2 --- /dev/null +++ b/Challenge-13/find-setBits.js @@ -0,0 +1,8 @@ +/** + * @param {number} n + * @return {number} + */ +var hammingWeight = function(n) { + + return n.toString(2).split('0').join('').length + }; \ No newline at end of file From ec5cdce2fe464be9699811be25d48d4ed2ecab9f Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Fri, 4 Apr 2025 11:04:10 +0530 Subject: [PATCH 15/16] Challenge 14 completed --- Challenge-14/counting_bits.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Challenge-14/counting_bits.js diff --git a/Challenge-14/counting_bits.js b/Challenge-14/counting_bits.js new file mode 100644 index 0000000..afaf05a --- /dev/null +++ b/Challenge-14/counting_bits.js @@ -0,0 +1,11 @@ +/** + * @param {number} n + * @return {number[]} + */ +var countBits = function(n) { + let result = [] + for(let i = 0 ; i <= n ; i++){ + result.push(i.toString(2).split('0').join('').length) + } + return result +}; \ No newline at end of file From e26ddab73b181ce2a643a236d82ce99601051632 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Tue, 5 Aug 2025 10:09:03 +0530 Subject: [PATCH 16/16] challenge 14 , 15 --- Challenge-14/counting_bits.js | 17 ++++++++++------- Challenge-15/missing-numbers.js | 7 +++++++ 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 Challenge-15/missing-numbers.js diff --git a/Challenge-14/counting_bits.js b/Challenge-14/counting_bits.js index afaf05a..59f0b9b 100644 --- a/Challenge-14/counting_bits.js +++ b/Challenge-14/counting_bits.js @@ -1,11 +1,14 @@ +const { count } = require("console"); + /** * @param {number} n * @return {number[]} */ -var countBits = function(n) { - let result = [] - for(let i = 0 ; i <= n ; i++){ - result.push(i.toString(2).split('0').join('').length) - } - return result -}; \ No newline at end of file +var countBits = function (n) { + let result = []; + for (let i = 0; i <= n; i++) { + result.push(i.toString(2).split("0").join("").length); + } + + return result; +}; diff --git a/Challenge-15/missing-numbers.js b/Challenge-15/missing-numbers.js new file mode 100644 index 0000000..6b93dd8 --- /dev/null +++ b/Challenge-15/missing-numbers.js @@ -0,0 +1,7 @@ +var missingNumber = function(nums) { + let arrLen = nums.length + let expectedNumsSum = (arrLen * (arrLen+1))/2 + + let currentSum = nums.reduce((acc,cur)=> acc+cur,0) + return expectedNumsSum - currentSum +}; \ No newline at end of file