diff --git a/Challenge-1/two-sum.ts b/Challenge-1/two-sum.ts new file mode 100644 index 0000000..5168173 --- /dev/null +++ b/Challenge-1/two-sum.ts @@ -0,0 +1,13 @@ +function twoSum(nums: number[], target: number): number[] | undefined { + const map = new Map(); + for (let i = 0; i < nums.length; i++) { + console.log('i',i); + const changeDiff = target - nums[i]; + if (map.has(changeDiff)) { + return [map.get(changeDiff)!, i]; + } + map.set(nums[i], i); + } + return undefined; +} + diff --git a/Challenge-2/best-time-to-buy-and-sell-stock.ts b/Challenge-2/best-time-to-buy-and-sell-stock.ts new file mode 100644 index 0000000..336582a --- /dev/null +++ b/Challenge-2/best-time-to-buy-and-sell-stock.ts @@ -0,0 +1,21 @@ +function maxProfit(prices: number[]): number { + let left: number = 0; + let right: number = 1; + let currentProfit: number = 0; + + while (right !== prices.length) { + if (prices[right] > prices[left]) { + // push to currentProfit if currentProfit less than new Profit + const newProfit = prices[right] - prices[left]; + if (newProfit > currentProfit) { + currentProfit = newProfit; + } + + right++; + } else { + left = right; + right++; + } + } + return currentProfit; +} diff --git a/Challenge-3/contains-duplicate.ts b/Challenge-3/contains-duplicate.ts new file mode 100644 index 0000000..5496993 --- /dev/null +++ b/Challenge-3/contains-duplicate.ts @@ -0,0 +1,8 @@ +function containsDuplicate(nums: number[]): boolean { + const arraySet = new Set(); + for (const num of nums) { + if (arraySet.has(num)) return true; + arraySet.add(num); + } + return false; +} diff --git a/README.md b/README.md index d922b9d..8688cb2 100644 --- a/README.md +++ b/README.md @@ -1,148 +1,3 @@ -# 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! πŸš€ +Kiran +kirankalak4@gmail.com \ No newline at end of file