Max Consecutive Ones in Java with DSA

Day 6 of Java with DSA Journey 🚀 📌 Topic: Max Consecutive Ones (LeetCode 485) 💭 Quote: "Progress is about maintaining momentum—just like a streak of consecutive ones." ✨ What I learned today: 🔹 State Tracking: Learned how to maintain a current streak vs a maximum streak — a key concept for sequence-based problems. 🔹 The Power of Resetting: Understanding when to reset the counter (on encountering 0) is crucial to solving streak problems correctly. 🔹 Simple Yet Powerful Logic: No complex data structures needed — just a clean linear scan with strong logic. 🔹 Performance: ✔️ Time Complexity: O(n) (Single pass) ✔️ Space Complexity: O(1) (Only variables used) 🧠 Problem Solved: ✔️ Max Consecutive Ones 💡 Key Insight: This problem is a foundation for the Sliding Window pattern. Instead of managing two pointers, we track a running window of 1s that resets when a 0 appears. ⚡ Interview Insight – Using Math.max(): Instead of writing: if (current > max) max = current; Using: max = Math.max(max, current); makes the code cleaner and more professional — a small detail that reflects strong coding practices. 📈 Growth Reflection: With each problem, I’m focusing on: 🔹 Explaining logic clearly and step-by-step (important for interviews) 🔹 Thinking in patterns (like Sliding Window & State Tracking) 🔹 Writing clean and optimized code like a software engineer Consistency is the real key 🔑 #DSA #LeetCode #Java #CodingJourney #SlidingWindow #ProblemSolving #Day6 #SoftwareEngineer #Algorithms #Array #MCA #lnct #100DaysOfCode #Algorithms #SoftwareEngineering #InPlaceAlgorithms #TechLearning #JavaDeveloper

  • graphical user interface

To view or add a comment, sign in

Explore content categories