Max Distance Between Different Color Houses in Array

🚀 Day 69/100 – DSA Challenge Another day, another step closer to mastery 💯 Today’s problem was about finding the maximum distance between two houses with different colors. 🔍 Problem: Given an array where each element represents the color of a house, find the maximum distance between two houses such that their colors are different. 🧠 Approach: Instead of checking all pairs (which would be inefficient), the key idea is: Compare elements from the start with the end Find the farthest positions where colors differ Maximize the distance using smart observations rather than brute force 💡 Key Insight: The maximum distance will always involve either the first or the last house — this reduces the problem from quadratic to linear time. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) 📌 Learning: This problem reinforced how identifying patterns and constraints can help avoid brute force and lead to optimal solutions. Consistency streak continues 🔥 On to Day 70 🚀 #100DaysOfCode #DSA #Java #ProblemSolving #Consistency #CodingJourney #KeepLearning

  • graphical user interface

To view or add a comment, sign in

Explore content categories