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 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 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 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 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 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 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 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 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 diff --git a/Challenge-11/three-sum.js b/Challenge-11/three-sum.js new file mode 100644 index 0000000..6f3b224 --- /dev/null +++ b/Challenge-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 acc+cur,0) + return expectedNumsSum - currentSum +}; \ No newline at end of file diff --git a/README.md b/README.md index d922b9d..7ed608e 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