Tanisha Gupta
Learner || JAVA|| C || HTML|| CSS|| JAVASCRIPT || PYTHON
- Report this post
🌟 Day 25/50: Trapping Rain Water 🌧️Hello, Connections!Today marks Day 25 of my 50-day challenge, and I’m diving into an intriguing problem: Trapping Rain Water.Problem Statement: Given an array of non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.Algorithm Overview: To solve this problem efficiently, I’ve implemented an algorithm with a time complexity of O(N) and a space complexity of O(N).Approach:Initialize Arrays: Create two arrays, left_max and right_max, to store the maximum heights to the left and right of each element.Compute Left Max Array: Traverse the array from left to right, filling left_max such that each element at index i contains the maximum height encountered so far from the left.Compute Right Max Array: Traverse the array from right to left, filling right_max such that each element at index i contains the maximum height encountered so far from the right.Calculate Trapped Water: For each element in the array, calculate the water trapped at that index by taking the minimum of left_max[i] and right_max[i], subtracting the height at that index, and summing up the results.This efficient solution leverages pre-computed information to ensure we only pass through the array a few times, maintaining linear time complexity.🔗 #CodingChallenge #TrappingRainWater #AlgorithmDesign #50DaysOfCode
9
1 Comment
Creds
2h
- Report this comment
Congratulations, Tanisha Gupta! This accomplishment is truly exceptional! Keep moving forward, and we're here to provide support and celebrate your success! 👏🎉
1Reaction
To view or add a comment, sign in
More Relevant Posts
-
Tanisha Gupta
Learner || JAVA|| C || HTML|| CSS|| JAVASCRIPT || PYTHON
- Report this post
Hello Connections! 👋Day 24/50: Best Time to Buy and Sell Stock IIToday's challenge focuses on maximizing profits from stock prices over a series of days. The key is to identify the best times to buy and sell stocks to achieve the highest possible profit.Problem Statement:Given an array of prices where each element represents the price of a stock on a given day, our task is to determine the maximum profit we can achieve through multiple transactions (buying and selling stocks on different days).Example:Input: prices = [7, 1, 5, 3, 6, 4]Output: 7Explanation:Buy on day 2 (price = 1) and sell on day 3 (price = 5) for a profit of 5 - 1 = 4.Buy on day 4 (price = 3) and sell on day 5 (price = 6) for a profit of 6 - 3 = 3.Total Profit: 4 + 3 = 7Algorithm:Initialize Profit: Set total profit to 0.Iterate Through Prices: Loop through the prices array from the second day onward.Check Price Increase: If the price on a given day is higher than the previous day, calculate the difference and add it to the total profit.Continue to Next Day: Repeat this for the entire array to accumulate the total profit.Output Result: Return the total calculated profit.Complexity:Time Complexity: O(N), where N is the number of days.Space Complexity: O(1), as we're using a constant amount of extra space.This approach ensures that we capture all upward trends in prices, maximizing our gains efficiently.Excited to continue the journey of learning and growing with these daily challenges! 🚀#CodingChallenge #Day23 #StockTrading #Algorithm #ProblemSolving #TechLearning
12
Like CommentTo view or add a comment, sign in
-
Tanisha Gupta
Learner || JAVA|| C || HTML|| CSS|| JAVASCRIPT || PYTHON
- Report this post
Hello, Connections!Day 23/50: Subarray Sum Equals KToday’s challenge is to find the number of continuous subarrays within a given array whose sum equals a target value, k. This problem is an excellent exercise in using hash maps to optimize for time complexity.Approach:Time Complexity: O(N)Space Complexity: O(N)Solution Overview: To solve this problem efficiently, we utilize a hash map to store the cumulative sum up to each index. By checking the difference between the current cumulative sum and the target sum k, we can determine if there is a subarray that meets the condition. This approach allows us to avoid the naive O(N^2) solution, significantly improving performance.#java #problemsolving #50daysChallenge
12
Like CommentTo view or add a comment, sign in
-
Tanisha Gupta
Learner || JAVA|| C || HTML|| CSS|| JAVASCRIPT || PYTHON
- Report this post
Hello Connections!Day 22/50 of my coding challenge is here, and today’s task is all about finding the leaders in an array! 🚀A leader in an array is an element that is greater than all the elements to its right. The goal is to find all such leaders in a given array with a time complexity of O(n).Approach:Start from the End:Traverse the array from right to left, starting with the last element, which is always a leader.Keep Track of Maximum:Maintain a variable to keep track of the maximum element found so far as you move from right to left.Compare and Collect Leaders:For each element, compare it with the current maximum.If the element is greater than the maximum, it is a leader, and update the maximum to this element.Continue this process until the beginning of the array is reachedThis problem not only highlights the importance of optimizing for time complexity but also showcases the elegance of linear scanning techniques. #coding #problemSolving #arrayLeaders #50DaysChallenge #Day22
15
Like CommentTo view or add a comment, sign in
-
Tanisha Gupta
Learner || JAVA|| C || HTML|| CSS|| JAVASCRIPT || PYTHON
- Report this post
Hello Connections!!🔹 Day 21 of My 50-Day Coding Challenge 🔹Problem: Rotate an array by k stepsInput: nums = [1, 2, 3, 4, 5, 6, 7], k = 3Output: [5, 6, 7, 1, 2, 3, 4]Explanation:1 If k is greater than the array length, compute k = k % n to handle cases where k exceeds the length of the array.2 First rev the array from 0 to n-k-1 then rev the array from n-k to n-1 then rev the array from 0 to n-13 then check if i<jswap (arr[i],arr[j])i++;j--;Complexity:Time Complexity: O(2N)Space Complexity: O(1) This approach leverages the power of array reversal to achieve the desired rotation with minimal space usage, demonstrating how optimizing basic operations can lead to efficientsolution
19
Like CommentTo view or add a comment, sign in
-
Tanisha Gupta
Learner || JAVA|| C || HTML|| CSS|| JAVASCRIPT || PYTHON
- Report this post
🚀 Day 20/50: Solving the "Max Consecutive Ones" Problem! 🚀Hello everyone! Today marks Day 20 of my 50-day coding challenge. 🎉Problem Statement:Given a binary array, find the maximum number of consecutive 1s.Input: nums = [1,1,0,1,1,1]Output: 3Constraints:Time Complexity: O(n)Space Complexity: O(1)This approach efficiently finds the longest sequence of consecutive 1s with linear time complexity and constant space complexity, showcasing the power of simple yet effective algorithms.Looking forward to Day 21! Thanks for following along. 🌟#50DaysOfCode #CodingChallenge #Algorithm #java #LinkedInLearning
14
Like CommentTo view or add a comment, sign in
-
Tanisha Gupta
Learner || JAVA|| C || HTML|| CSS|| JAVASCRIPT || PYTHON
- Report this post
Hello Everyone!!Day 19 of my 50-day challenge!Today's problem: Majority ElementInput: nums = [3,2,3]Output: 3Constraints:Time Complexity: O(n log n)Space Complexity: O(1)Stay tuned for my solution!#CodingChallenge #Day19 #Algorithms #ProblemSolving #DataStructures
12
2 Comments
Like CommentTo view or add a comment, sign in
-
Tanisha Gupta
Learner || JAVA|| C || HTML|| CSS|| JAVASCRIPT || PYTHON
- Report this post
Hello Everyone!!Day 18/50Problem: Binary SearchTime Complexity: O(log N)Space Complexity: O(1)#50DayChallenge #Coding #BinarySearch #Algorithms #TechJourney
11
Like CommentTo view or add a comment, sign in
-
Tanisha Gupta
Learner || JAVA|| C || HTML|| CSS|| JAVASCRIPT || PYTHON
- Report this post
Hey connections 🌟 I am thrilled to share that I've been offered an internship opportunity at CodSoft where I will be delving into Java Programming! 🚀This internship represents a pivotal moment in my career journey, offering a platform to apply my passion for coding in a professional setting. I am eager to immerse myself in the world of Java, sharpening my skills and gaining hands-on experience under the guidance of CodSoft's talented team.I am grateful for this opportunity and determined to make the most of it. Stay tuned as I embark on this enriching journey with CodSoft! 🌐#Internship #JavaProgramming #Codsoft #CareerDevelopment #SoftwareEngineering #LearningAndDevelopment #TechInnovation #ExcitingTimesAhead
14
1 Comment
Like CommentTo view or add a comment, sign in
-
Tanisha Gupta
Learner || JAVA|| C || HTML|| CSS|| JAVASCRIPT || PYTHON
- Report this post
🚀 Day 17/50: Best Time to Buy and Sell Stock 🚀Today's challenge was to solve the classic "Best Time to Buy and Sell Stock" problem. The goal is to maximize profit by choosing a single day to buy and a different day in the future to sell.🔍 Problem Statement:Given an array of prices where prices[i] is the price of a given stock on the i-th day, find the maximum profit you can achieve. You may only complete one transaction: buy one and sell one share of the stock.💡 Example:Input: prices = [7,1,5,3,6,4]Output: 5(Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5)📊 Time Complexity: O(N)📦 Space Complexity: O(1)The solution involves iterating through the list while keeping track of the minimum price encountered so far and the maximum profit possible.#50DaysChallenge #Coding #ProblemSolving #Algorithm #TechJourney
13
Like CommentTo view or add a comment, sign in
366 followers
- 28 Posts
View Profile
FollowExplore topics
- Sales
- Marketing
- Business Administration
- HR Management
- Content Management
- Engineering
- Soft Skills
- See All