Solved Maximum Gap problem using Bucket Sort in Java

Day 31/100 – #100DaysOfCode 🚀 | #Java #LeetCode #Sorting #Arrays ✅ Problem Solved: Maximum Gap ⚙️ 🧩 Problem Summary: Given an unsorted array, find the maximum difference between successive elements in its sorted form. You must solve it in linear time and space. 💡 Approach Used: Used Bucket Sort (Pigeonhole Principle) to achieve linear performance — ➤ Calculated global min & max. ➤ Divided range into buckets based on array size. ➤ Placed elements into buckets tracking min & max of each. ➤ Found maximum gap between successive non-empty buckets. ⚙️ Time Complexity: O(N) 📦 Space Complexity: O(N) ✨ Takeaway: This problem sharpened my understanding of bucket-based approaches and how sorting principles can be applied efficiently without direct sorting. ⚡ #Java #LeetCode #BucketSort #Sorting #ProblemSolving #100DaysOfCode #CodingChallenge

  • graphical user interface, text, application, chat or text message

To view or add a comment, sign in

Explore content categories