Why Activity Selection Sorts by End Time, Not Start Time

Why does the Activity Selection Problem sort activities by their ending time instead of their starting time? In this video, you’ll first see a greedy approach that looks correct—but actually fails. Then we’ll build the optimal solution step by step and understand why choosing the earliest finishing activity always maximizes the number of non-overlapping activities. 🎯 In this video you’ll learn: ✅ Why sorting by starting time doesn't always work ✅ Why sorting by ending time always gives the optimal answer ✅ The intuition behind the Greedy Algorithm ✅ Activity Selection using a Movie Marathon example ✅ Java implementation using Pair class & Comparator ✅ Time Complexity: O(N log N) ✅ Space Complexity: O(N) 📺 This video is part of the Greedy Algorithms Playlist. Watch the complete playlist to master Greedy Algorithms from basics to interview-level problems. ▶️ Greedy    • Greedy Algorithms   🚀 If you’re serious about mastering Data Structures & Algorithms, welcome to AlgoXploration! Here, you’ll learn DSA from the ground up with intuitive explanations, real examples, coding interview insights, and step-by-step problem-solving—not just memorizing solutions. 📚 DSA Playlists (Learn in a Structured Order) ▶️ DSA Problems    • DSA Problems   ▶️ Queue    • Queue Problem Solving Series   ▶️ Stack    • Stack Problem Solving Series   ▶️ Linked List    • LinkedList Problem Solving Series   ▶️ Binary Search    • Binary Search Problem Solving Series   ▶️ Recursion    • Recursion Problem Solving Series   ▶️ Hashing    • Hashing Problem Solving Series   ▶️ Bit Manipulation https://www.youtube.com/playlist?list... ▶️ Two Pointer Technique    • Two Pointers Problem Solving Series   ▶️ Arrays    • Array Problem Solving Series   ▶️ Sorting    • Sorting Series   🤝 Join the Community 📢 Telegram (Notes • Discussions • Daily Quizzes) https://t.me/algoxploration_hub 💻 Coding Profiles LeetCode https://leetcode.com/u/sameervhatkar/ GitHub https://github.com/sameervhatkar 🔗 Connect with Me LinkedIn   / sameer-vhatkar   ⭐ Subscribe for beginner-friendly DSA videos every week! #DSA #GreedyAlgorithm #ActivitySelection #Java #CodingInterview