Solving 725. Split Linked List in Parts on LeetCode

🚀 Day 76 of #100DaysOfCode Solved 725. Split Linked List in Parts on LeetCode 🔗 🧠 Key Insight: We need to split a linked list into k parts such that: 👉 Sizes are as equal as possible 👉 Earlier parts can have at most one extra node ⚙️ Approach (Length + Distribution): 1️⃣ Find length of linked list → len 2️⃣ Compute: 🔹 partSize = len / k 🔹 extra = len % k 👉 First extra parts will have partSize + 1 nodes 3️⃣ Traverse and split: 🔹 For each part:   • Assign size = partSize + (extra > 0 ? 1 : 0)   • Move pointer that many nodes   • Break link (next = null)   • Decrement extra 4️⃣ If len < k: 🔹 Some parts will be null ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(k) (result array) #100DaysOfCode #LeetCode #DSA #LinkedList #Simulation #Java #InterviewPrep #CodingJourney

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories