Minimum Absolute Difference in Array with Sorting and Observation

🚀 Day 16 of #100DaysOfCode Today’s problem: Minimum Absolute Difference 📊 🔍 Problem Understanding: Given an array of distinct integers, find all pairs with the minimum absolute difference. 🧠 Approach: First, I sorted the array Then compared adjacent elements (since minimum difference will always be between neighbors in sorted order) Tracked the minimum difference and stored all valid pairs 👉 Key Insight: Sorting reduces unnecessary comparisons and simplifies the problem ⚙️ Concepts Used: Sorting (Arrays.sort) Greedy observation (check only neighbors) List handling for storing pairs 📊 Complexity: ⏱️ Time Complexity: O(N log N) (due to sorting) 💾 Space Complexity: O(N) (for storing result pairs) 📚 Key Learnings: Learned how sorting simplifies problems Understood how to reduce complexity from brute force O(N²) → O(N log N) Improved thinking in terms of patterns and optimization 💯 Result: ✔️ Accepted (All test cases passed) ✔️ Runtime: 1 ms (100%) 🔥 ✔️ Clean and efficient solution Sometimes the best optimization is just sorting + observation 💡 Let’s keep building consistency 🚀 #Day16 #100DaysOfCode #Java #DSA #LeetCode #ProblemSolving #Sorting

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories