🚀 Learning Java the Right Way Today, I practiced a popular DSA problem 👉 Container With Most Water 📌 Problem: Given an array of heights, find two lines that together can store the maximum amount of water. Example: Array → {1, 8, 6, 2, 5, 4, 8, 3, 7} Output → 49 ✅ 🔹 Key Learning: Instead of using brute force (O(n²)), I used the Two Pointer approach to solve it in O(n) time. 📌 Approach: Start with two pointers (left & right) Calculate area = min(height) × width Move the pointer with smaller height Repeat to find maximum area This problem helped me understand: ✔ Two Pointer technique ✔ Optimization over brute-force ✔ Logical decision making ✔ Real interview-level problem solving Learning when and how to optimize is what truly improves coding skills 💪 📌 Think smart • Optimize logic • Solve efficiently 🚀 #java #javafullstack #javadeveloper #corejava #codingjourney #coding
Maximizing Water in Container with Java Two Pointer Approach
More Relevant Posts
-
🚀 Day 11.2 of Java DSA Journey — Trilogy Complete 🧠⚡ 📌 Problem: Power of Four (LeetCode 342) I didn’t just solve this problem… 👉 I connected everything from the last days: Power of 2 → Bitwise Power of 3 → Math Power of 4 → Both combined 💡 Breakthrough Idea To be a power of four, a number must: ✔️ Be positive ✔️ Be a power of two → (n & (n - 1)) == 0 ✔️ Follow a math rule → (n - 1) % 3 == 0 👉 That’s a multi-layered check in O(1) 🧠 Key Learnings 🔹 Not all powers of 2 are powers of 4 (Example: 8, 32 ❌) 🔹 Mathematical Signature Matters For every 4^x, (n - 1) is divisible by 3 🔹 Combining Concepts = Real Growth Bitwise + Math → Cleaner, faster solution ⚡ Complexity ⏱ Time: O(1) 📦 Space: O(1) 🔥 Pro Tips (Interview Level) 💡 Tip 1: Layer Your Conditions Break complex checks into smaller logical filters 💡 Tip 2: Don’t Stop at Bitwise Sometimes bit tricks need math support 💡 Tip 3: Know Alternative Tricks 👉 0x55555555 mask can validate correct bit position 💡 Tip 4: Pattern Recognition is Everything This entire trilogy is about identifying patterns in numbers 💡 Tip 5: Think Like an Engineer Combine approaches instead of forcing one technique 🔥 Real Insight This wasn’t just a problem… It was about learning: 👉 When to use bitwise 👉 When to use math 👉 When to combine both That’s real problem-solving. Consistency builds mastery 📈 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #InterviewPrep #Day11 #BitManipulation #InterviewPrep #CleanCode #Array #Optimization #MCA #lnct #100DaysOfCode #SoftwareEngineering #Algorithms #InPlaceAlgorithms #TechLearning #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Day 4 of My Java Learning Journey 💻 Today’s focus was on strengthening logic building with Pattern Programming and exploring the powerful Math class in Java through real-world examples 👇 🔹 🔸 Pattern Programming Practiced different patterns using loops to improve problem-solving skills. Example: * ** *** **** 👉 Helped me understand nested loops and structure thinking 🔹 🔸 Finding the Hypotenuse Applied Math class to solve: c = √(a² + b²) ✔ Used: "Math.sqrt()" and "Math.pow()" 🔹 🔸 Circle & Sphere Calculations - Circle Area = πr² - Sphere Volume = (4/3)πr³ ✔ Used: "Math.PI" for accurate calculations 🔹 🔸 Compound Interest Calculator 💰 Formula: A = P(1 + r/n)^(nt) 👉 Learned how Java can solve real-life financial problems 🔹 🔸 Weight Conversion ⚖️ Converted kg → pounds ✔ Simple but practical application 🔹 🔸 Java Math Class Essentials Explored: - "Math.sqrt()" - "Math.pow()" - "Math.abs()" - "Math.max()" / "Math.min()" - "Math.round()" ✨ Day 4 Insight: Small programs build strong logic. The more I practice, the better I understand how Java solves real-world problems efficiently. 📈 Progress is steady… consistency is key! #Day4 #Java #CodingJourney #100DaysOfCode #Programming #LearningJava #DeveloperJourney
To view or add a comment, sign in
-
🚀 Day 11 of Java with DSA Journey — This one blew my mind 🤯 📌 Problem: Power of Three (LeetCode 326) Yesterday, I used bit manipulation for Power of Two. Today? 👉 That approach completely fails. So I had to think differently… 💡 Breakthrough Idea Instead of loops or recursion… I used math + number theory to solve it in O(1) time. 👉 1162261467 % n == 0 Yes, one line. 🧠 Key Learnings 🔹 Bitwise isn’t universal Works great for base-2, but not for base-3 🔹 Prime Numbers Matter Since 3 is prime, its powers divide each other perfectly 🔹 Max Value Trick Largest power of 3 in 32-bit int = 3^19 = 1162261467 ⚡ Complexity ⏱ Time: O(1) 📦 Space: O(1) 🔥 Pro Tips (Interview Level) 💡 Tip 1: Know Your Data Type Limits Many O(1) tricks depend on constraints like 32-bit integer limits 💡 Tip 2: Prime Numbers Unlock Shortcuts If a number is prime, its powers have clean divisibility properties 💡 Tip 3: Always Question the Default Approach Most people write: while (n % 3 == 0) n /= 3; 💡 Tip 4: This is a Pattern Power of 2 → bitwise Power of 3 → math Power of 4 → hybrid 💡 Tip 5: Edge Cases First Always check n <= 0 🔥 Real Insight This problem forced me to shift my thinking: ❌ Rely on one technique ✅ Adapt based on the problem Consistency compounds 📈 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #NumberTheory #InterviewPrep #Day11 #BitManipulation #CleanCode #Array #Optimization #MCA #lnct #100DaysOfCode #SoftwareEngineering #Algorithms #InPlaceAlgorithms #TechLearning #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 𝐍𝐞𝐰 𝐕𝐢𝐝𝐞𝐨 𝐎𝐮𝐭 — 𝐖𝐡𝐲 𝐀𝐫𝐫𝐚𝐲 𝐈𝐧𝐝𝐞𝐱 𝐒𝐭𝐚𝐫𝐭𝐬 𝐟𝐫𝐨𝐦 𝟎? (Beginner Friendly) Ever wondered why arrays in Java start from 0 instead of 1? 🤔 This is one of the most common questions beginners have — and understanding this will level up your programming fundamentals. In this video, I’ve explained the concept in a simple and practical way — not just theory, but the real reason behind it. 🎬 𝐓𝐨𝐩𝐢𝐜: Why Index Starts at 0 in Arrays 💡 𝐈𝐧 𝐭𝐡𝐢𝐬 𝐯𝐢𝐝𝐞𝐨 𝐲𝐨𝐮’𝐥𝐥 𝐥𝐞𝐚𝐫𝐧: ✅ What is an Array & what is Index ✅ Why indexing starts from 0 (core concept) ✅ Memory concept behind arrays (important 🔥) ✅ How JVM calculates element position ✅ Formula: base_address + (index * size) ✅ Why starting from 0 makes access faster 💡 I’ve explained this using a simple memory visualization: • First element → base address (index 0) • Next elements → calculated using offset • No extra calculation needed → more efficient ⚡ This helps you understand how things work internally, not just remember syntax. 📺 Watch Video 👇 https://lnkd.in/ga3iaUNN 💬 Did you know this before, or did you think arrays should start from 1? 🔁 Share this with someone learning Java — this concept clears a lot of confusion 🚀 #Java #JavaCourse #LearnJava #Programming #SoftwareEngineering #Developers #Coding #Arrays #DataStructures #CodingJourney #NVerse
To view or add a comment, sign in
-
-
🚀 Day 18 / 100 Days of Java 💻 Today was all about going deeper into one of the most fundamental topics in programming — Arrays. Even though arrays seem simple at first, they are the backbone of many advanced data structures and algorithms. Here’s what I worked on today 👇 🔹 Understanding Arrays Learned how arrays are represented in memory and why they allow fast access using indexing. This helped me clearly understand how data is stored and retrieved efficiently. 🔹 Finding Maximum & Minimum Elements Practiced iterating through an array to identify the largest and smallest values — a simple yet powerful concept used in many real-world problems. 🔹 Finding the Third Largest Element This pushed me to think beyond basics and handle edge cases like duplicates and ordering without relying completely on sorting. 🔹 Searching an Element in Array Explored linear search and understood where it works best. Also got a glimpse of how search efficiency matters when data grows. 🔹 Finding Missing Number Solved problems using both brute force and optimized approaches. This improved my understanding of patterns and mathematical logic. 🔹 Finding Repeating Elements Learned different techniques to detect duplicates — from basic loops to more optimized methods using extra space. 💡 Key Learnings from Today: ✔ Arrays are not just beginner topics — they are the foundation of problem solving ✔ Writing clean logic is more important than jumping to complex solutions ✔ Edge cases (duplicates, boundaries, etc.) matter a lot ✔ There’s always a better (optimized) way to solve a problem 🔥 Reflection: Every day I realize that consistency beats intensity. Even small concepts, when practiced deeply, build strong problem-solving skills over time. 📈 Slowly but surely becoming better than yesterday. Let’s keep building, learning, and growing 💪 #Java #DSA #100DaysOfCode #CodingJourney #LearningInPublic #DeveloperLife #Programmer #CodingLife #SoftwareEngineering #ComputerScience #TechJourney #ProblemSolving #Algorithms #DataStructures #JavaDeveloper #CodeDaily #Consistency #GrowthMindset #SelfImprovement #StudentLife #EngineeringStudent #FutureEngineer #CodeNewbie #KeepLearning #BuildInPublic #Motivation #Discipline #DailyProgress #NeverGiveUp
To view or add a comment, sign in
-
-
Everyone asks: 👉 “Which is the best programming language?” But very few ask: 👉 “What logic does this language teach me?” The truth is — there is no “best” language. There is only the language that shapes your thinking. 🟢 C teaches you how memory actually works. 🟢 Java teaches you structured, object-oriented thinking. 🟢 Python teaches you clarity and simplicity. 🟢 JavaScript teaches you asynchronous thinking and real-world adaptability. But here’s the real secret 👇 Languages change. Logic stays. Frameworks evolve. Syntax updates. Trends come and go. But if you understand: ✔ How data flows ✔ How memory is managed ✔ How problems are broken into steps ✔ How systems communicate You can learn any language. The best journey in a developer’s career is not mastering one language. It’s mastering the way of thinking behind them. Because coding is not about typing faster. It’s about thinking deeper. Choose a language. Respect its logic. Learn the fundamentals. And you’ll never fear technology changes again. 🚀 #Programming #DeveloperJourney #CodingLife #TechGrowth #SoftwareDevelopment
To view or add a comment, sign in
-
-
Day 3 of Java with DSA Journey 🚀 📌 Topic: Guess Number Higher or Lower (LeetCode 374) 💬 Quote: "Efficiency is not about doing more; it's about eliminating what doesn't matter." ✨ What I Learned: 🔹 Binary Search Beyond Arrays: Binary Search isn’t limited to arrays — it works perfectly on a number range like [1...n]. 🔹 Working with APIs: Learned how to adapt logic based on API responses: -1 → Guess is too high 1 → Guess is too low 0 → Correct answer 🔹 Power of Efficiency: Even for a huge range (up to 2³¹ - 1), Binary Search finds the answer in ~31 steps 🤯 Compared to Linear Search → practically impossible! 🔹 Complexity: ⏱ Time: O(log n) 📦 Space: O(1) 🧠 Problem Solved: ✔️ Guess Number Higher or Lower 💡 Key Insight: This problem highlights the “Narrowing the Search Space” concept. Each step eliminates half the possibilities — that’s the magic of logarithmic algorithms ⚡ ⚡ Interview Insight (3-Way Decision Logic): Unlike boundary problems, here we deal with three outcomes: 1️⃣ 0 → Found the number (return immediately) 2️⃣ -1 → Move right = mid - 1 3️⃣ 1 → Move left = mid + 1 👉 Use while (left <= right) since the target is guaranteed to exist. 🔑 Takeaway: Consistency beats intensity. Showing up daily is what builds mastery. #DSA #LeetCode #Java #CodingJourney #BinarySearch #ProblemSolving #100DaysOfCode #JavaDeveloper #Algorithms
To view or add a comment, sign in
-
-
🚀 Mastering Time & Space Complexity in Java DSA When I started learning Data Structures & Algorithms in Java, the biggest mindset shift wasn’t coding… it was thinking in complexity. 📌 Time Complexity (⏱️) It tells how fast your code runs as input grows. O(1) → Constant (Best 👍) O(log n) → Logarithmic O(n) → Linear O(n log n) → Efficient sorting O(n²) → Slow (avoid when possible ⚠️) 📌 Space Complexity (💾) It tells how much memory your code uses. Efficient programs don’t just run fast — they also use less memory. 💡 Key Learnings: ✔️ Always analyze before optimizing ✔️ Nested loops ≠ always bad, but be careful ✔️ Trade-offs exist between time & space ✔️ Practice problems to build intuition 🔥 Current Focus: Improving problem-solving by writing optimized Java solutions and analyzing their complexity. Consistency > Motivation 💯 #Java #DSA #CodingJourney #TimeComplexity #SpaceComplexity #Programming #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 4 of Java with DSA Journey 🚀 📌 Topic: Search Insert Position (LeetCode 35) 💬 Quote: "Binary Search is about more than finding a needle in a haystack; it's about knowing exactly where to put a new needle." ✨ What I Learned: 🔹 Power of the low Pointer: If the target isn’t found, low directly gives the correct insertion index. 🔹 Finding Position Even When Missing: Binary Search doesn’t just search — it tells you where the element belongs. 🔹 Efficient Gap Detection: Even for missing values, we maintain O(log n) efficiency. 🔹 Complexity: ⏱ Time: O(log n) 📦 Space: O(1) 🧠 Problem Solved: ✔️ Search Insert Position 💡 Key Insight: Binary Search helps determine the rank/position of a number in a sorted array — whether it exists or not ⚡ ⚡ Interview Insight (Post-Loop Behavior): 👉 When the loop ends (low > high): low → first index greater than target high → last index smaller than target 🎯 That’s why low = insert position 🔑 Takeaway: Binary Search is not just about finding — it's about positioning. Consistency is the real key 🔑 #DSA #LeetCode #Java #CodingJourney #BinarySearch #ProblemSolving #100DaysOfCode #Algorithms #TechLearning #Day4 #Array #MCA #lnct
To view or add a comment, sign in
-
-
Day 9.2 of Java with DSA Journey 🚀 📌 Problem: Number of Steps to Reduce a Number to Zero (LeetCode 1342) At first glance, this looks too easy… But hidden inside is a powerful idea: 👉 Thinking in binary instead of decimal 💡 Core Idea Keep reducing the number until it becomes 0: Even → divide by 2 Odd → subtract 1 Simple rule. Powerful pattern. 🧠 Key Learnings 🔹 Iterative Thinking Used a loop to repeatedly transform the state 🔹 Decision Making per Step Even vs Odd → determines next move 🔹 Bitwise Insight num % 2 == 0 → (num & 1) == 0 num / 2 → num >> 1 ⚡ Complexity ⏱ Time: O(log n) 📦 Space: O(1) 🔥 Pro Tips (Interview Level) 💡 Tip 1: Think in Binary, Not Decimal Every division by 2 removes one bit → that's why complexity is logarithmic. 💡 Tip 2: Count Operations Without Simulation Steps = 👉 (Number of bits - 1) + (Number of 1s in binary) Example: 14 → 1110 Steps = (4 - 1) + 3 = 6 💡 Tip 3: Bitwise > Arithmetic (When Optimizing) Replace: % 2 → & 1 / 2 → >> 1 This shows low-level understanding. 💡 Tip 4: Pattern Recognition Matters This problem is not about loops… It’s about recognizing bit reduction patterns. 💡 Tip 5: Always Look for Hidden Math Even simple problems often have a mathematical shortcut behind them. 🔥 Real Insight This problem teaches a subtle shift: ❌ “Keep applying rules” ✅ “Understand what each operation does to the binary structure” That’s how you move from coding → engineering. Consistency compounds 📈 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Day9 #BitManipulation #InterviewPrep #CleanCode #Array #Optimization #MCA #lnct #100DaysOfCode #SoftwareEngineering #Algorithms #InPlaceAlgorithms #TechLearning #JavaDeveloper
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