📌 Day 12/100 – 100 Days of Code Challenge 🚀 Today’s LeetCode challenge: “Trapping Rain Water” (LeetCode #42) – one of the most popular Hard-level problems that strengthens logic building and array manipulation skills. 🔹 Approach: Used precomputed leftMax and rightMax arrays to determine how much water each bar can trap. For every index, the trapped water = min(leftMax[i], rightMax[i]) - height[i]. 🔹 Key Learnings: Improved understanding of prefix and suffix computations. Reinforced problem-solving using array-based preprocessing. Time Complexity: O(n) Space Complexity: O(n) #100DaysOfCode #LeetCode #Java #DSA #Arrays #TwoPointer #ProblemSolving #CodingJourney #DynamicProgramming #DailyChallenge
Solved "Trapping Rain Water" problem on LeetCode with Java and arrays.
More Relevant Posts
-
🚀 Day 87/100 of #100DaysOfCode 💡 Problem: 3321. Find X-Sum of All K-Long Subarrays II (Hard) 🔗 Platform: LeetCode Today’s challenge was all about optimizing sliding window logic with frequency-based ordering! The task — find the “x-sum” of every k-sized subarray, keeping only the top x most frequent elements (and if tied, prefer larger values). 🧠 Key Learnings: How to maintain frequency counts efficiently in a sliding window. Managing top-x elements dynamically using TreeSet and custom comparators. Overcoming TLE issues by switching from naive sorting (O(n*k)) to a balanced TreeSet approach (O(n log n)). ⚙️ Concepts Used: → Sliding Window → Frequency Map (HashMap) → Ordered Sets (TreeSet) → Custom Comparator Logic 🔥 This one really tested both logic & optimization — but once it clicked, it felt amazing! #LeetCode #100DaysOfCode #Java #CodingChallenge #ProblemSolving #DSA #SlidingWindow #Optimization
To view or add a comment, sign in
-
-
📌 Day 159 of Coding - Make Array Elements Equal to Zero (LeetCode - Easy) 🎯 Goal: Given an integer array nums, find the number of valid starting positions and directions such that by repeatedly decrementing and reversing direction (based on the rules), all elements eventually become 0. 💡Approach & Debugging: First computed total sum using Arrays.stream(nums).sum(). Maintained two prefix sums : left and right. For each index i where nums[i] == 0: Incremented left and decremented right progressively. Checked whether the left and right sums balance according to the movement rules. Counted valid selections when the balance was perfect or off by just one. ✔️ Time Complexity: O(N) - single pass through the array. ✔️ Space Complexity: O(1) - constant extra space. #Day159 #LeetCode #Simulation #Arrays #PrefixSum #Java #ProblemSolving #DSA #CodingChallenge #100DaysOfCode #Algorithms #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
💻 Day 51 of #LeetCode100DaysChallenge Solved LeetCode 13: Roman to Integer — a problem that tests mapping, iteration, and conditional logic. 🧩 Problem: Given a Roman numeral, convert it to an integer. Roman numerals use symbols I, V, X, L, C, D, and M. Normally, symbols are added from largest to smallest. However, in six cases (IV, IX, XL, XC, CD, CM), subtraction is applied. 💡 Approach — Mapping & Iteration: 1️⃣ Create a map of Roman symbols to integer values. 2️⃣ Iterate through the string: Add the value if the current symbol is greater than or equal to the next. Subtract the value if the current symbol is smaller than the next. 3️⃣ Sum all values to get the final integer. ⚙️ Complexity: Time: O(N) Space: O(1) ✨ Key Takeaways: ✅ Practiced mapping and iteration. ✅ Handled edge cases with subtraction logic. ✅ Reinforced sequential decision-making in string processing. #LeetCode #100DaysOfCode #Java #Mapping #Iteration #ConditionalLogic #DSA #CodingJourney #WomenInTech #RomanToInteger
To view or add a comment, sign in
-
-
✅ Day 54 of LeetCode Medium/Hard Edition Today’s challenge was “Maximum Sum of 3 Non-Overlapping Subarrays” — a brilliant mix of prefix sums, dynamic programming, and optimization logic 🎯 📦 Problem: You’re given an integer array nums and a fixed length k. You must select three non-overlapping subarrays of length k such that their total sum is maximized, and return the starting indices of these subarrays. 🔗 Problem Link: https://lnkd.in/g76A35cZ ✅ My Submission: https://lnkd.in/gB-nDGqu 💡 Thought Process: First, precompute the sum of every k-length window using prefix sums. Then, maintain two helper arrays: left[i] → index of best (maximum sum) window from the left up to i right[i] → index of best window from the right starting at i For each possible middle window, combine it with the best left and right windows to form the maximum total sum. Track and update the maximum configuration across all possible middle positions. ⏱ Complexity: Time: O(n) Space: O(n) 🔥 Key Takeaway: This problem highlights the power of prefix sums and precomputation — turning what could be a brute-force O(n³) nightmare into a sleek, linear-time solution. Sometimes, the smartest code isn’t recursive… it’s prepared! 💪 #LeetCodeMediumHardEdition #100DaysChallenge #DynamicProgramming #PrefixSum #ProblemSolving #Java #CodingJourney
To view or add a comment, sign in
-
-
🌳 Day 62 of 100 Days of LeetCode 🌳 Today’s challenge: LeetCode 226 – Invert Binary Tree 🔄 🧩 Problem Summary: Given the root of a binary tree, invert it — meaning swap the left and right children of every node. Essentially, you’re mirroring the entire tree! 🌲✨ 💡 Key Takeaways: 🔹 Strengthened understanding of tree traversal using recursion. 🔹 Learned how a simple DFS (Depth-First Search) can elegantly solve structural transformations. 🔹 Practiced reasoning about symmetry and recursion base cases. 🧠 Approach: 1️⃣ If the tree is empty, return null. 2️⃣ Recursively invert the left and right subtrees. 3️⃣ Swap the left and right children of the current node. 4️⃣ Return the root once the tree is fully inverted. 🚀 A great example of how recursion simplifies complex problems into smaller, intuitive steps! #LeetCode #100DaysOfCode #Java #DSA #BinaryTree #CodingJourney #Recursion #ProblemSolving
To view or add a comment, sign in
-
-
🔹 Day 45: Move Zeroes (LeetCode #283) 📌 Problem Statement: Given an integer array nums, move all 0s to the end of it while maintaining the relative order of the non-zero elements. The operation must be done in-place, without making a copy of the array. ✅ My Approach: I used a two-pointer technique — one pointer tracks the position to place the next non-zero element, and the other iterates through the array. Whenever a non-zero element is found, it is swapped with the element at the tracking pointer position. This efficiently pushes all zeroes to the end while keeping the order intact. 📊 Complexity: Time Complexity: O(n) Space Complexity: O(1) ⚡ Submission Stats: Runtime: 3 ms (Beats 20.93%) Memory: 45.96 MB (Beats 86.42%) 💡 Reflection: A clean and efficient in-place array manipulation problem that reinforced the importance of pointer management for space optimization. 🚀 #LeetCode #Java #Array #TwoPointers #100DaysOfCode #Day45
To view or add a comment, sign in
-
-
🔥 LeetCode Daily Challenge – Day 14 🧩 Problem: 3312. Number of Substrings With One’s Count at Least Square of Zero’s Count 🚀 Approach: Zero-Positions + Prefix Optimization Today’s problem was an interesting blend of math and string analysis. The key insight was recognizing that zero-count grows slowly, and feasible substrings can be efficiently tracked using prefix logic and previous zero positions. ⭐ My approach: Precompute previous zero indices for fast block calculations Track zeros and compute required ones using ones ≥ zeros² Use a mathematical bound (sqrt(n)) to safely prune infeasible ranges Achieved near-linear behavior on large inputs Clean, optimized, and significantly faster than brute force. 💡 This method avoids triple-nested loops and leverages structure in binary strings. 📈 Result: ✔️ Accepted ⚡ Runtime: 115ms (Beats 83.33%) 📦 Memory: 47.07MB (Beats 26.85%) Day 14 streak still going strong! 🔥 #LeetCode #DailyChallenge #Java #DSA #ProblemSolving #DailyCodingChallenge #CodingStreak
To view or add a comment, sign in
-
-
📌 Day 154 of Coding - Check If Digits Are Equal in String After Operations I (LeetCode - Medium) 🎯 Goal: Given a numeric string s, repeatedly replace it with a new string formed by taking the sum (mod 10) of every pair of adjacent digits, until only two characters remain. Return whether the final two digits are equal. 💡Approach & Debugging: Used a simple iterative simulation approach. For each iteration, formed a new string res by summing adjacent digits modulo 10. Replaced s with res and continued until the string length dropped to 2. Finally, compared both digits for equality. ✔️ Time Complexity: O(N*N) - since the string shrinks gradually each iteration. ✔️ Space Complexity: O(N) - temporary strings. 🧠 Key Takeaways: Some problems test simulation and string manipulation more than algorithms. Always track how input size evolves after each iteration. #Day154 #LeetCode #StringManipulation #Java #ProblemSolving #DSA #CodingChallenge #Algorithms #100DaysOfCode #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
🚀 Day 60 of My LeetCode Challenge Problem: Defanging an IP Address — LeetCode #1108 Today’s problem was a straightforward yet insightful string manipulation task. The goal was to replace every . in an IP address with [.]. 💡 Approach: Used a StringBuilder to efficiently construct the modified string: • Traversed each character in the given address. • When encountering a ., appended [.] to the builder. • For all other characters, appended them directly. • Converted the StringBuilder to a string and returned the result. This method ensures both clarity and efficiency while avoiding unnecessary string object creation. ⏱️ Time Complexity: O(n) — Single traversal of the string. 💾 Space Complexity: O(n) — New string built proportional to input length. Each day adds a small step toward mastering clean code and algorithmic thinking 💪 #LeetCode #Day60 #LeetCode1108 #Java #CodingChallenge #ProblemSolving #StringManipulation
To view or add a comment, sign in
-
-
Day 25 of #LeetCode Challenge 🔹 Problem: 3354. Make Array Elements Equal to Zero 🔹 Difficulty: Easy 🔹 Topic: Array | Simulation | Prefix Sum Today’s problem was a fun logic-based simulation involving movement and balance between left and right sums. The goal was to find how many starting positions (and directions) could lead to every element becoming zero. The trick here is realizing that you don’t actually need to simulate every move — just track prefix sums and compare left and right totals. If they’re equal (or differ by 1), it’s a valid starting point. A neat mix of math and logic! #LeetCode #100DaysOfCode #Day25 #Java #CodingChallenge #ProblemSolving #LearnToCode #LeetCodeDaily #ProgrammingJourney #DSA #Algorithms
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development