diff --git a/AKASH KUMAR/1.TrappingRainWater/Readme.md b/AKASH KUMAR/1.TrappingRainWater/Readme.md new file mode 100644 index 0000000..26b9288 --- /dev/null +++ b/AKASH KUMAR/1.TrappingRainWater/Readme.md @@ -0,0 +1,12 @@ +Trapping Rain Water problem cam be done in 2 ways + +1.Brute Force:Taking 2 arrays prefix and suffix prefix will store the height of the largest building till that index on traversal form left to right and suffix will store the height of the largest building till that index on traversal form right to left.And then min(prefix(i),suffix(i)) will be taken and subtracted with with the height of the i'th building i.e. min(prefix(i),suffix(i))-arr(i) and the value will be added in the ans varible which will return the total uints of water that can be stored in between the building at the end of the loop. + +Time Complexity=0(n) +Space COmplexity=0(2n) .Since we are taking 2 extra arrays{prefix & suffix) + + +2.Optimal Solution:We can do it without using extra space by taking 2 pointers l & r(i.e. left and right) l will be at index 0(l=0) and r will be at last index(i.e.r=n-1).It will be traversed till l& height) + { + int n=height.size(); + int l,r,ans=0,lmax=0,rmax=0; + l=0,r=n-1; + while(lheight[l]) + { + ans+=lmax-height[l]; + } + else + { + lmax=height[l]; + } + l++; + } + else + { + if(rmax>height[r]) + { + ans+=rmax-height[r]; + } + else + { + rmax=height[r]; + } + r--; + } + } + return ans; + + + } +}; + + + + + + + + + + + + + + + + + +//For Local enviroment +//Time Complexity=0(n) +//Space COmplexity=0(1) +#include +using namespace std; +int trap(vector& height) +{ + int n=height.size(); + int l,r,ans=0,lmax=0,rmax=0; + l=0,r=n-1; + while(lheight[l]) + { + ans+=lmax-height[l]; + } + else + { + lmax=height[l]; + } + l++; + } + else + { + if (rmax>height[r]) + { + ans+=rmax-height[r]; + } + else + { + rmax=height[r]; + } + r--; + } + } + return ans; +} + +int main() +{ + int n; + cout<<"Enter number of elements:"; + cin>>n; + vector height(n); + cout << "Enter the heights:"; + for (int i=0;i>height[i]; + } + int result=trap(height); + cout << "Amount of trapped water: " << result << endl; + + return 0; +} diff --git a/AKASH KUMAR/1.TrappingRainWater/soln.exe b/AKASH KUMAR/1.TrappingRainWater/soln.exe new file mode 100644 index 0000000..3791736 Binary files /dev/null and b/AKASH KUMAR/1.TrappingRainWater/soln.exe differ diff --git a/AKASH KUMAR/2.Spiral Matrix/Screenshot .png b/AKASH KUMAR/2.Spiral Matrix/Screenshot .png new file mode 100644 index 0000000..1d22c57 Binary files /dev/null and b/AKASH KUMAR/2.Spiral Matrix/Screenshot .png differ diff --git a/AKASH KUMAR/2.Spiral Matrix/soln.cpp b/AKASH KUMAR/2.Spiral Matrix/soln.cpp new file mode 100644 index 0000000..6c1f0c6 --- /dev/null +++ b/AKASH KUMAR/2.Spiral Matrix/soln.cpp @@ -0,0 +1,127 @@ +//For Local enviroment +//Time Complexity=0(m*n) +//Space COmplexity=0(m*n) +#include +using namespace std; +class Solution +{ +public: + vector spiralOrder(vector>& matrix) + { + vectorans; + int n=matrix.size(); + if (n==0) + { + return ans; + } + int m=matrix[0].size(); + int top=0,bottom=n-1; + int left=0,right=m-1; + while (top<=bottom&&left<=right) + { + for (int i=left;i<=right;i++) + { + ans.push_back(matrix[top][i]); + } + top++; + for (int i=top;i<=bottom;i++) + { + ans.push_back(matrix[i][right]); + } + right--; + if (top<=bottom) + { + for (int i=right;i>=left;i--) + { + ans.push_back(matrix[bottom][i]); + } + bottom--; + } + if (left<=right) + { + for (int i=bottom;i>=top;i--) + { + ans.push_back(matrix[i][left]); + } + left++; + } + } + return ans; + } +}; +int main() +{ + int n,m; + cin>>n>>m; + vector>matrix(n,vector(m)); + for (int i=0;i>matrix[i][j]; + } + } + Solution obj; + vectorresult=obj.spiralOrder(matrix); + for (int i=0;i spiralOrder(vector>& matrix) { + vectorans; + int n=matrix.size(); + if (n==0) + { + return ans; + } + int m=matrix[0].size(); + int top=0,bottom=n-1; + int left=0,right=m-1; + while (top<=bottom&&left<=right) + { + for (int i=left;i<=right;i++) + { + ans.push_back(matrix[top][i]); + } + top++; + for (int i=top;i<=bottom;i++) + { + ans.push_back(matrix[i][right]); + } + right--; + if (top<=bottom) + { + for (int i=right;i>=left;i--) + { + ans.push_back(matrix[bottom][i]); + } + bottom--; + } + + if (left<=right) + { + for (int i=bottom;i>=top;i--) + { + ans.push_back(matrix[i][left]); + } + left++; + } + } + + return ans; + } +}; diff --git a/Leetcode DSA sheet by Fraz 1.xlsx b/Leetcode DSA sheet by Fraz 1.xlsx deleted file mode 100644 index 748e670..0000000 Binary files a/Leetcode DSA sheet by Fraz 1.xlsx and /dev/null differ diff --git a/README.md b/README.md deleted file mode 100644 index b7f3b83..0000000 --- a/README.md +++ /dev/null @@ -1,142 +0,0 @@ -# 🌟 CodeResite Assignment-1 - Git & GitHub Practice - -Welcome to the **CodeResite Assignment** πŸ‘¨β€πŸ« -This task is designed to help you practice Git, GitHub, and basic coding workflows. - ---- - -## πŸ™Œ Before You Begin - -Please complete these two simple steps to support the community: - -1. **⭐ Star this repository** - - Click the ⭐ icon at the top-right of this page. - -2. **πŸ‘€ Follow the creator's GitHub profile** - - Visit [@0xsec-debug](https://github.com/0xsec-debug) and click **Follow**. - ---- - -## πŸ“‹ Objective - -- Learn how to **fork a repository**, **push code**, and **create a pull request**. -- Solve **any 2 coding questions** from the provided Excel sheet. -- Submit your **solution code** and a **screenshot of passed test cases**. - ---- - -## πŸ“ Steps to Complete the Assignment - -### βœ… Step 1: Fork the Repository -- Click the **Fork** button on the top-right of [this repo](https://github.com/0xsec-debug/Assignment-1). -- This will create your own copy under your GitHub account. - ---- - -### πŸ–₯️ Step 2: Clone Your Fork -1. Go to your forked repository. -2. Click the green **Code** button β†’ Copy the URL. -3. Open your terminal and run: - ```bash - git clone - ``` -4. Move into the folder: - ```bash - cd Assignment-1 - ``` - ---- - -### πŸ“– Step 3: Choose & Solve 2 Questions -1. Open the file: `CodeResite_Assignment_Questions.xlsx`. -2. Choose **any 2 questions** of your choice. -3. Solve them using your preferred programming language (Python, C++, Java, etc.). - ---- - -### πŸ“ Step 4: Add Your Files - -For each question, create a folder like: - -``` -submissions/// -``` - -**Example**: `submissions/RiyaVerma/ReverseArray/` - -Inside each folder, include: -- βœ… `solution.py` (or `.cpp`, `.java`, etc.) -- πŸ–Ό `screenshot.png` (showing test case(s) passed) -- πŸ“„ Optional: `README.md` explaining your approach (if you wish) - -Example folder structure: -``` -submissions/ -└── YourName/ - β”œβ”€β”€ Question1/ - β”‚ β”œβ”€β”€ solution.py - β”‚ └── screenshot.png - └── Question2/ - β”œβ”€β”€ solution.cpp - └── screenshot.png -``` - ---- - -### πŸ’‘ Step 5: Add, Commit, and Push - -Run these commands in the terminal: - -```bash -git add . -git commit -m "Added solutions by " -git push origin main -``` - -> Replace `main` with your branch name if it’s different (like `master`). - ---- - -### πŸ” Step 6: Create a Pull Request - -1. Visit your forked repo on GitHub. -2. Click **"Compare & pull request"**. -3. Fill in: - - Your name - - The questions you solved - - Any short note or message - -4. Click **Create pull request**. - -βœ… Done! You’ve successfully submitted your assignment. - ---- - -## ⚠️ Important Notes - -- 🧠 Solve **any 2 questions only**. -- πŸ“Έ Submit your **solution code** + **test case screenshot**. -- βœ… LeetCode, HackerRank, CodeChef, or any platform is accepted. -- 🧾 Please organize your submission files properly. - ---- - -## πŸ“… Deadline - -**Submit your pull request before: 30 June 2025** - ---- - -## πŸ’» Tools & Platforms You Can Use - -Languages: -- Python, C++, Java, JavaScript, etc. - -Platforms: -- LeetCode, CodeChef, HackerRank, Replit, or your local IDE - ---- - -Thank you for participating! -Let’s code, commit, and grow πŸš€ -β€” *CodeResite & [0xsec-debug](https://github.com/0xsec-debug) Team*