Odd Even Linked List Solution on LeetCode

🚀 Day 51 of #100DaysOfCode Solved 328. Odd Even Linked List on LeetCode 🔗 🧠 Key Insight: We need to rearrange the linked list such that: 🔹All odd-indexed nodes come first 🔹Followed by all even-indexed nodes 🔹While preserving the relative order ⚠️ Important: This is based on node position (index), not value. ⚙️ Approach: 1️⃣ Create two separate lists: 🔹odd → nodes at odd positions 🔹even → nodes at even positions 2️⃣ Traverse the list and distribute nodes accordingly 3️⃣ Connect: 🔹End of odd list → head of even list 4️⃣ Return the new head 🎯 This ensures a clean separation while maintaining order. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) (in-place re-linking) #100DaysOfCode #LeetCode #DSA #LinkedList #Algorithms #Java #InterviewPrep #CodingJourney

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories