100 Days of Code: LeetCode Robot Collisions

🚀 #100DaysOfCode – Day 10 Consistency is kicking in. Small wins adding up 🔥 ✅ What I accomplished today: 🧠 LeetCode Problem – Robot Collisions 📌 Problem Overview: Given robots with positions, health, and directions (L or R), simulate collisions: Robots moving toward each other collide The robot with lower health gets destroyed If equal → both destroyed Survivors continue moving 💡 My Approach (Sorting + Stack Simulation): 🔹 Sorted robots based on positions to process collisions in order 🔹 Used a stack to track right-moving robots 🔹 When a left-moving robot appears → simulate collisions with stack top 🔹 Carefully handled 3 cases: ✔ Smaller health → robot destroyed ✔ Greater health → reduce health & continue ✔ Equal health → both destroyed 🔹 Stored original indices to return result in correct order ⚡ Time Complexity: O(n log n) (sorting + single pass) ⚡ Space Complexity: O(n) 🧩 Key Insight: This problem helped me understand: ✔ How to convert simulation problems into stack-based solutions ✔ Importance of sorting before processing interactions ✔ Handling multiple collision scenarios cleanly ✔ Writing state-driven logic without brute force 🔗 LeetCode Submission Link: https://lnkd.in/gKGk8GFM ☕ Spring Boot Learning – Revision + Concepts 🔹 Revised all previously learned concepts to strengthen fundamentals 🔹 Learned the difference between: 📌 PUT vs PATCH ✔ PUT → Updates the entire resource (full replacement) ✔ PATCH → Updates only specific fields (partial update) 📌 H2 Database (In-Memory DB): ✔ Runs in memory → data is lost after application restart ✔ Useful for testing & development ✔ Not suitable for persistent production data 📌 Key Takeaways: ✔ Use PUT when updating full objects ✔ Use PATCH for partial updates (better performance) ✔ H2 is great for testing, but not for long-term storage ✔ Revision is as important as learning new things 📝 Spring Boot Notes: https://lnkd.in/gNZWz96m 🔥 Learning Streak: Day 10/100 Double digits now. Staying consistent 💪 #100DaysOfCode #Java #SpringBoot #BackendDevelopment #LeetCode #DSA #CodingJourney #ProblemSolving #SoftwareDevelopment #LearningInPublic #Developers #Consistency #BuildInPublic

  • text

To view or add a comment, sign in

Explore content categories