100DaysOfCode Day 27: Majority Element & LinkedList Sorting

🚀 #100DaysOfCode – Day 27 Update Today I solved two DSA problems and explored different approaches. 🔹 Problem 1: Find Majority Element (n/2) ✅ Solved using Moore’s Voting Algorithm — an optimal approach. ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) 📌 Learned how voting/cancellation logic helps find the majority element efficiently without extra space. --- 🔹 Problem 2: Sort a Linked List ✅ Approach 1 — Brute Force - Traversed the linked list and stored all node data in a temporary ArrayList. - Sorted the ArrayList. - Traversed the linked list again and updated node values. ⏱ Time Complexity: O(n) + O(n log n) + O(n) ≈ O(n log n) 💾 Space Complexity: O(n) 📌 Understood how extra space can simplify logic but is not optimal. 🔥 Tomorrow I will explore the optimal approach for sorting a linked list. #Day27 #100DaysOfCode #DSA #LinkedList #Java #ProblemSolving #CodingJourney

To view or add a comment, sign in

Explore content categories