Minimum Distance Between Three Equal Elements in Array with Java

🔥 Day 36 of #LeetCode Journey ✅ Problem: Minimum Distance Between Three Equal Elements I Today’s problem was about finding the minimum distance between three equal elements in an array. 💡 Key Idea: Instead of checking all combinations, we track indices efficiently: Store the last two occurrences of each number When a third occurrence appears, calculate the distance Keep updating the minimum distance 🧠 What I Learned: Optimizing from brute force to O(n) approach Using HashMap effectively for tracking indices Thinking in terms of patterns instead of combinations ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(n) 🔍 Example: Input: [1,2,1,1,3,1] Output: 3 Small optimizations make a big difference 💡 Staying consistent and improving every day! #Java #DSA #LeetCode #CodingJourney #100DaysOfCode #Programming #ProblemSolving

  • text

To view or add a comment, sign in

Explore content categories