From 04bb35583b3d7928526091a11b5efe017c7c1bae Mon Sep 17 00:00:00 2001 From: Rashad M <82885442+rasharashe@users.noreply.github.com> Date: Tue, 18 Mar 2025 10:47:34 +0530 Subject: [PATCH 01/10] added readme file --- README.md | 150 +----------------------------------------------------- 1 file changed, 2 insertions(+), 148 deletions(-) diff --git a/README.md b/README.md index d922b9d..1769765 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 : Rashad M +Email : rashadbasheer.m@gmail.com \ No newline at end of file From eb1e05b2fe0ace0c0bca2a3180b14a3176fc4ae6 Mon Sep 17 00:00:00 2001 From: Rashad M <82885442+rasharashe@users.noreply.github.com> Date: Tue, 18 Mar 2025 15:03:39 +0530 Subject: [PATCH 02/10] moved readme file to challenge-1 --- README.md | 150 +++++++++++++++++++++++++++++++++++++++++- challenge-1/README.md | 2 + 2 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 challenge-1/README.md diff --git a/README.md b/README.md index 1769765..d922b9d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,148 @@ -Name : Rashad M -Email : rashadbasheer.m@gmail.com \ No newline at end of file +# 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! πŸš€ + diff --git a/challenge-1/README.md b/challenge-1/README.md new file mode 100644 index 0000000..1769765 --- /dev/null +++ b/challenge-1/README.md @@ -0,0 +1,2 @@ +Name : Rashad M +Email : rashadbasheer.m@gmail.com \ No newline at end of file From 17a81e9e38d0142feb1e61c80b1feed69d1c84da Mon Sep 17 00:00:00 2001 From: Rashad M <82885442+rasharashe@users.noreply.github.com> Date: Wed, 19 Mar 2025 09:19:08 +0530 Subject: [PATCH 03/10] solution for two sum --- challenge-2/two-sum.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 challenge-2/two-sum.py diff --git a/challenge-2/two-sum.py b/challenge-2/two-sum.py new file mode 100644 index 0000000..d872b96 --- /dev/null +++ b/challenge-2/two-sum.py @@ -0,0 +1,13 @@ +def two_sum(nums, target): + """ + :type nums: List[int] + :type k: int + :rtype: float + """ + num_dict = {} + n = len(nums) + for i in range(n): + dif = target - nums[i] + if dif in num_dict: + return [num_dict[dif], i] + num_dict[nums[i]] = i \ No newline at end of file From da05d15213abe63dd0406ab70b8f18122077a497 Mon Sep 17 00:00:00 2001 From: Rashad M <82885442+rasharashe@users.noreply.github.com> Date: Fri, 21 Mar 2025 11:18:55 +0530 Subject: [PATCH 04/10] add solution for best time to buy and sell stock --- Challenge-3/solution.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Challenge-3/solution.py diff --git a/Challenge-3/solution.py b/Challenge-3/solution.py new file mode 100644 index 0000000..a20c805 --- /dev/null +++ b/Challenge-3/solution.py @@ -0,0 +1,16 @@ +class Solution(object): + def maxProfit(self, prices): + """ + :type prices: List[int] + :rtype: int + """ + left = 0 + right = 1 + maxprofit = 0 + while right < len(prices): + if prices[right] > prices[left]: + maxprofit = max(prices[right] - prices[left], maxprofit) + else: + left = right + right += 1 + return maxprofit From 240cd39612b07dd57a2f819ae391ef6028c0fc70 Mon Sep 17 00:00:00 2001 From: Rashad M <82885442+rasharashe@users.noreply.github.com> Date: Fri, 21 Mar 2025 11:25:42 +0530 Subject: [PATCH 05/10] added solution for contain duplicate --- Challenge-4/solution.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Challenge-4/solution.py diff --git a/Challenge-4/solution.py b/Challenge-4/solution.py new file mode 100644 index 0000000..0d7bd35 --- /dev/null +++ b/Challenge-4/solution.py @@ -0,0 +1,12 @@ +class Solution(object): + def containsDuplicate(self, nums): + """ + :type nums: List[int] + :rtype: bool + """ + dic = {} + for i, n in enumerate(nums): + if n in dic: + return True + dic[n] = i + return False From d3b0bad43e5912debdd72a72ad944ef90923a5bb Mon Sep 17 00:00:00 2001 From: Rashad M <82885442+rasharashe@users.noreply.github.com> Date: Mon, 24 Mar 2025 10:46:12 +0530 Subject: [PATCH 06/10] added solution for challenge 5 --- Challenge-5/solution.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Challenge-5/solution.py diff --git a/Challenge-5/solution.py b/Challenge-5/solution.py new file mode 100644 index 0000000..184e3c4 --- /dev/null +++ b/Challenge-5/solution.py @@ -0,0 +1,14 @@ +class Solution(object): + def getSum(self, a, b): + """ + :type a: int + :type b: int + :rtype: int + """ + carry = 0 + mask = 0xffffffff + while b & mask != 0: + carry = (a & b) << 1 + a = a ^ b + b = carry + return a & mask if b > mask else a From d507c8c10deb6e0a61ff3bdbf67afc30d5817d68 Mon Sep 17 00:00:00 2001 From: Rashad M <82885442+rasharashe@users.noreply.github.com> Date: Tue, 25 Mar 2025 16:08:21 +0530 Subject: [PATCH 07/10] Create solution.py for challenge 6 --- Challenge-6/solution.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Challenge-6/solution.py diff --git a/Challenge-6/solution.py b/Challenge-6/solution.py new file mode 100644 index 0000000..64a23c8 --- /dev/null +++ b/Challenge-6/solution.py @@ -0,0 +1,16 @@ +class Solution(object): + def productExceptSelf(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + res = [1] * len(nums) + prefix = 1 + for i in range(1, len(nums)): + prefix = prefix * nums[i-1] + res[i] = prefix + suffix = 1 + for j in range(len(nums) - 2, -1, -1): + suffix = suffix * nums[j+1] + res[j] = res[j] * suffix + return res From cc11e406c812b2c01601e0ba7d37e3887aafad61 Mon Sep 17 00:00:00 2001 From: Rashad M <82885442+rasharashe@users.noreply.github.com> Date: Tue, 25 Mar 2025 16:22:14 +0530 Subject: [PATCH 08/10] Create solution.py for challenge-7 --- Challenge-7/solution.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Challenge-7/solution.py diff --git a/Challenge-7/solution.py b/Challenge-7/solution.py new file mode 100644 index 0000000..c0a785d --- /dev/null +++ b/Challenge-7/solution.py @@ -0,0 +1,12 @@ +class Solution(object): + def maxSubArray(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + maxsum = nums[0] + cursum = nums[0] + for i in range(1, len(nums)): + cursum = max(cursum + nums[i], nums[i]) + maxsum = max(maxsum, cursum) + return maxsum From 3183efcad0fc67cdb2d7ce1d75a91564a4b832ba Mon Sep 17 00:00:00 2001 From: Rashad M <82885442+rasharashe@users.noreply.github.com> Date: Tue, 25 Mar 2025 17:16:30 +0530 Subject: [PATCH 09/10] Create solution.py for challenge 8 --- Challenge-8/solution.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Challenge-8/solution.py diff --git a/Challenge-8/solution.py b/Challenge-8/solution.py new file mode 100644 index 0000000..9d3e31c --- /dev/null +++ b/Challenge-8/solution.py @@ -0,0 +1,15 @@ +class Solution(object): + def maxProduct(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + res = nums[0] + maxsum = 1 + minsum = 1 + for i in nums: + curpro = maxsum * i + maxsum = max(curpro, minsum * i, i) + minsum = min(curpro, minsum * i, i) + res = max(res, maxsum) + return res From 7eee40983f29d9ea67152699006845b5d17bf754 Mon Sep 17 00:00:00 2001 From: Rashad M <82885442+rasharashe@users.noreply.github.com> Date: Wed, 26 Mar 2025 08:01:46 +0530 Subject: [PATCH 10/10] Create solution.py for challenge 9 --- Challenge-9/solution.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Challenge-9/solution.py diff --git a/Challenge-9/solution.py b/Challenge-9/solution.py new file mode 100644 index 0000000..0912b0f --- /dev/null +++ b/Challenge-9/solution.py @@ -0,0 +1,16 @@ +class Solution(object): + def findMin(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + lo, hi = 0, len(nums) - 1 + while lo < hi: + if nums[lo] < nums[hi]: + return nums[lo] + + mid = (lo + hi) // 2 + if nums[mid] > nums[hi]: + lo = mid + 1 + else: + hi = mid