Hitting a 0ms runtime is the developer equivalent of hitting a game-winning shot at the buzzer. I just optimized my solution for finding the Intersection of Two Linked Lists and reached that "Beats 100%" milestone. The beauty of Linked List problems isn't just in solving them—it’s in the pointer magic that makes them run instantly. For this one, the two-pointer approach kept the logic clean and the execution lightning-fast. The Stats: * Runtime: 0ms (Beats 100.00% of Java users). * Complexity: Pure O(m + n) efficiency. Coding is often about trade-offs, but when you find that sweet spot where simplicity meets peak performance, you have to celebrate it. Keep grinding, keep optimizing. #LeetCode #Java #SoftwareEngineering #DataStructures #CodingLife #Optimization
Optimized Linked List Intersection Solution Beats 100% of Java Users
More Relevant Posts
-
0ms. 100% Beats. Thinking outside the box. There is nothing quite like the feeling of seeing your code hit a 0ms runtime. Today’s win was the "Delete Node in a Linked List" problem. At first glance, it feels impossible—how do you delete a node when you don't have access to the head of the list? The Solution: Instead of trying to "delete" the node in the traditional sense, I just copied the data from the next node into the current one and skipped the next node entirely. The Result: * Runtime: 0ms (Beats 100.00% of Java users). * Logic: O(1) Time and Space complexity. * Efficiency: 41/41 test cases passed instantly. In software engineering, we often get stuck trying to solve a problem the "standard" way. This was a great reminder that sometimes, the best solution is to reframe the problem itself. One optimization at a time. Do you prefer clever "hacks" like this, or do you stick to standard procedural logic? Let’s discuss in the comments! 👇 #Java #LeetCode #SoftwareEngineering #CodingLife #DataStructures #Optimization #TechCommunity
To view or add a comment, sign in
-
-
0ms Runtime. 100% Beats. The Power of Two Pointers. There is nothing quite like the feeling of seeing your code hit that 0ms mark on LeetCode. It’s that instant feedback that tells you your logic isn’t just correct—it’s optimized. I just solved the "Remove Nth Node From End of List" challenge using the Two-Pointer (Fast & Slow) technique. The Strategy: By moving a 'fast' pointer n steps ahead first, I created a fixed gap. Then, I moved both 'fast' and 'slow' pointers together until the end. This allowed me to find the target node and remove it in a single pass (O(n) time complexity). The Results: * Runtime: 0ms (Beats 100.00% of Java users). * Test cases: 208/208 passed. * Complexity: Efficient pointer manipulation with no extra space needed. In software engineering, we often look for complex tools to solve problems. This was a great reminder that sometimes, the most elegant solution is just a clever bit of pointer arithmetic. Keep pushing, keep optimizing. #Java #LeetCode #DataStructures #SoftwareEngineering #CodingLife #Algorithms
To view or add a comment, sign in
-
-
🧩 final is not just a keyword — it’s a design decision Marking something as final means: • The value won’t change • The behavior won’t be overridden • The design is intentional In backend systems, final helps with: ➝ Thread safety ➝ Predictable behavior ➝ Easier reasoning about code Small keywords often carry big architectural meaning. #Java #CoreJava #CleanCode #BackendEngineering
To view or add a comment, sign in
-
That 2ms runtime feeling. I just optimized the Delete the Middle Node of a Linked List problem. While it’s a standard challenge, hitting that near-perfect efficiency mark is always a great reminder: Clean logic beats heavy code every single time. The Breakdown: * The Approach: Used a "Fast and Slow" pointer strategy to find and remove the middle in a single pass. * The Result: 2ms runtime, beating 99.68% of Java submissions. * Consistency: All 70/70 test cases passed. In software engineering, it's easy to get lost in complex frameworks. But mastering these fundamental data structures is what truly sharpens your problem-solving "intuition." One step at a time, one optimization at a time. #LeetCode #Java #DataStructures #SoftwareEngineering #ProblemSolving #CodingLife
To view or add a comment, sign in
-
-
𝑷𝒐𝒕𝒆𝒏𝒕𝒊𝒂𝒍 𝑩𝒖𝒈 𝑰𝒅𝒆𝒏𝒕𝒊𝒇𝒊𝒆𝒅 𝒊𝒏 𝑳𝒆𝒆𝒕𝑪𝒐𝒅𝒆 𝑬𝒙𝒆𝒄𝒖𝒕𝒊𝒐𝒏 𝑻𝒊𝒎𝒆 𝑪𝒂𝒍𝒄𝒖𝒍𝒂𝒕𝒊𝒐𝒏 I recently noticed an issue with how LeetCode calculates and displays code execution time. By adding a simple static block with a shutdown hook, it is possible to alter the displayed runtime of a submitted solution. This indicates that the execution time can be influenced outside the actual algorithm logic, which should ideally not be possible. Below is the code snippet that demonstrates this behavior: static { Runtime.getRuntime().addShutdownHook(new Thread(() -> { try (FileWriter writer = new FileWriter("display_runtime.txt")) { writer.write("0"); } catch (IOException e) { e.printStackTrace(); } })); } This suggests a bug on LeetCode’s end, where execution time tracking may be relying on artifacts that can be manipulated during JVM shutdown. Sharing this for awareness and hoping the LeetCode team can look into it to ensure fair and accurate performance measurement for all submissions. #LeetCode #Java #JVM #CompetitiveProgramming #SoftwareEngineering #Performance #Debugging LeetCode
To view or add a comment, sign in
-
🚨 Potential Bug Identified in LeetCode Execution Time Calculation 🚨 I recently noticed an issue with how LeetCode calculates and displays code execution time. By adding a simple static block with a shutdown hook, it is possible to alter the displayed runtime of a submitted solution. This indicates that the execution time can be influenced outside the actual algorithm logic, which should ideally not be possible. Below is the code snippet that demonstrates this behavior: static { Runtime.getRuntime().addShutdownHook(new Thread(() -> { try (FileWriter writer = new FileWriter("display_runtime.txt")) { writer.write("0"); } catch (IOException e) { e.printStackTrace(); } })); } This suggests a bug on LeetCode’s end, where execution time tracking may be relying on artifacts that can be manipulated during JVM shutdown. Sharing this for awareness and hoping the LeetCode team can look into it to ensure fair and accurate performance measurement for all submissions. hashtag #LeetCode #Java #TimeComplexity #Algorithms #CompetitiveProgramming #SoftwareEngineering #Programming #BugReport #DeveloperCommunity #TechLearning
To view or add a comment, sign in
-
-
We went from 200 req/s to 92,000 req/s with ONE config change Our production API was struggling: ❌ 200 concurrent users = system meltdown ❌ Thread pools are constantly exhausted ❌ Reactive code = debugging nightmare ❌ Team velocity 📉 Then we discovered Java 21 Virtual Threads. 🔧 What we changed Literally one line in application.properties: spring.threads.virtual.enabled=true That’s it. 📈 What happened next Throughput: 200 → 92,000 req/s (🚀 460x) Memory usage: ↓ 85% Code complexity: Deleted 3,000 lines of reactive code Bug rate: ↓ 70% Team velocity: ↑ 3x 🤯 How is this even possible? Virtual Threads are JVM-managed, ultra-lightweight threads. 1M virtual threads ≈ ~1GB RAM 1M platform threads ≈ ~2TB RAM 💀 The JVM multiplexes millions of virtual threads onto a small number of OS (carrier) threads. When a virtual thread blocks (DB call, HTTP call, sleep): It unmounts from the carrier thread The carrier thread immediately runs something else When I/O completes, execution resumes exactly where it left off Blocking code — without blocking the OS. 🗓️ Our migration journey Week 1: Read docs, skeptical 🤔 Week 2: Tested in staging, shocked 😮 Week 3: Rolled to production, relieved 😌 Week 4: Deleted reactive code, celebrating 🎉 ⚠️ Key learnings ✔ Start with one microservice ✔ Watch for thread pinning (use ReentrantLock, not synchronized) ✔ Profile with JFR before & after ✔ Load test aggressively ✔ Monitor ThreadLocal usage 💡 The real win? Our junior developers can now work on high-concurrency production code without learning reactive programming. Lower cognitive load Easier debugging Faster onboarding Happier team This isn’t just a performance upgrade. 👉 It’s a paradigm shift for Java backend development. If you’re on Java 21+, you owe it to your team to try Virtual Threads. 👇 Drop a 🚀 if you’re planning to migrate! #Java #VirtualThreads #ProjectLoom #SoftwareEngineering #TechLeadership #Performance #Scalability #ProductionStories
To view or add a comment, sign in
-
𝗪𝗵𝗲𝗻 𝗝𝗮𝘃𝗮 𝗙𝗲𝗲𝗹𝘀 𝗙𝗿𝗲𝘀𝗵 A few weeks ago, I was writing another class just to hold some data. Getters, setters, equals(), hashCode() etc the usual way of doing. I stopped and thought if there was a simpler way or any other way of doing this??? That’s when I started exploring some of 𝗝𝗮𝘃𝗮’𝘀 𝗺𝗼𝗱𝗲𝗿𝗻 𝗳𝗲𝗮𝘁𝘂𝗿𝗲𝘀, and they completely changed how I write code: • 𝗥𝗘𝗖𝗢𝗥𝗗𝗦: Create immutable data objects in a single line. No more endless repetitive code. • 𝗦𝗘𝗔𝗟𝗘𝗗 𝗖𝗟𝗔𝗦𝗦𝗘𝗦: Control exactly which classes can extend a parent. Safer and easier to maintain. • 𝗩𝗜𝗥𝗧𝗨𝗔𝗟 𝗧𝗛𝗥𝗘𝗔𝗗𝗦: Handle thousands of tasks concurrently without eating up memory. Lightweight and practical for high concurrency. • 𝗣𝗔𝗧𝗧𝗘𝗥𝗡 𝗠𝗔𝗧𝗖𝗛𝗜𝗡𝗚: Simplifies complex conditional logic and makes code much cleaner. So Java is not just old and reliable but with its features it keeps evolving. Using these features helps reduce routine code, write safer code, and build applications that are easier to maintain while staying in the JVM enviornment. 👉 Have you tried any of these modern Java features? Which one made the biggest difference in your projects? #Java #ModernJava #JVM #BackendDevelopment #SoftwareEngineering #Programming
To view or add a comment, sign in
-
-
Logic behind LeetCode’s "Add Two Numbers" (Linked List) 🚀 Ever wondered how to add two numbers when they are stored in a Linked List in reverse order? The trick isn't to convert them to integers (as they might overflow!), but to simulate manual addition. Key Learnings: ✅ Use of a Dummy Node to simplify head management. ✅ Managing the Carry (sum / 10). ✅ Handling lists of different lengths. #DataStructures #Java #CodingLife #LeetCode #SoftwareEngineering
To view or add a comment, sign in
-
-
Here : https://lnkd.in/gZNV5bdp Just went LIVE for 1 full hour 🚀 Built and implemented all core Entity classes for a Lovable-style clone, purely from a system design perspective — no shortcuts, no boilerplate thinking. This session focused on: Translating system design → domain models Designing entities the way real products need Laying a scalable foundation before writing services or APIs Building in public. Learning by doing. Explaining while coding. More LIVE backend builds coming soon 👨💻🔥 #SystemDesign #BackendDevelopment #SpringBoot #Java #BuildInPublic #SoftwareArchitecture #LearningInPublic
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development