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
Ayush Mishra’s Post
More Relevant Posts
-
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
-
Backend Engineering Is More Than Coding For me, backend development includes: designing APIs database performance monitoring & debugging writing maintainable code The goal is reliability, not just features. #Java #BackendDeveloper #SoftwareEngineering
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
-
The moment Java systems begin handling snapshots, events, concurrent state, or domain aggregates, object copying stops being trivial. This is where the Copy Constructor approach becomes essential. A copy constructor gives developers: 🔹 full control over what gets duplicated 🔹 guaranteed avoidance of Cloneable's broken contract 🔹 clear semantics for nested objects 🔹 deterministic behavior under concurrency 🔹 predictable memory and lifecycle boundaries clone() suffers from reflection, shallow copying traps, CloneNotSupportedException, and inheritance fragility. Copy constructors avoid all of this by tying copying logic directly to the domain — not to a runtime mechanism. The result is a design where every replicated object is intentional, safe, and structurally consistent. This is exactly what high-integrity systems — financial flows, rule engines, schedulers, auditing pipelines — depend on. When correctness matters, explicit copying wins. Hashtags: #Java #CopyConstructor #AdvancedJava #JavaInternals #BackendEngineering #CleanArchitecture #ObjectOrientedDesign #CodeQuality #SoftwareEngineering #ConcurrencyControl #Immutability #ProgrammingBestPractices #DeepWork #JavaCommunity #HighPerformanceJava #TechLearning
To view or add a comment, sign in
-
⏱️ How much time does System.out.println() actually take? (You might be surprised) Most of us use System.out.println() everywhere — for debugging, logging, and quick checks. But have you ever asked: how expensive is it? 🧠 The short answer System.out.println() is slow compared to normal Java operations. ⏳ On average: 1–5 milliseconds per call (can be more) Depends on OS, console, and I/O buffering That may look small… until you put it inside a loop. ⚠️ Why is it slow? Because System.out.println(): 🔹 Writes to I/O stream (not memory) 🔹 Is synchronized (thread-safe → slower) 🔹 Flushes output to the console 🔹 Waits for the OS to handle the write This is thousands of times slower than in-memory operations. 🔁 Real impact for(int i = 0; i < 10000; i++) { System.out.println(i); } 👉 This can take seconds, not milliseconds. Now imagine this inside: REST APIs Microservices High-traffic applications 😬 ✅ What to do instead? ✔️ Use logging frameworks (Logback, Log4j2) ✔️ Log at proper levels (DEBUG, INFO) ✔️ Avoid console printing in production code 🏁 Final thought System.out.println() is great for learning and quick debugging, but in real applications — it can silently kill performance. 🔔 Follow for more insights on Java internals & backend performance 🚀 #Java #JavaDeveloper #CoreJava #AdvancedJava #JavaProgramming #Spring #SpringBoot #Hibernate #JPA #BackendDevelopment #Microservices #RESTAPI #SoftwareEngineering #CleanCode #TechLearning #CodingJourney #Programming
To view or add a comment, sign in
-
-
💻 Crash vs 🧩 Exception 💻 Errors / Crashes OS/JVM/Hardware level serious issues 🔴 Serious system-level issues 🔴 Usually unrecoverable Examples: OutOfMemoryError StackOverflowError 🧩 Exceptions 🟡 Program logic or runtime issues 🟡 Can be handled Examples: Divide by zero Null pointer File not found 💥Exception An exception is an unexpected problem during program execution that breaks the normal flow of a program 🚧 📌 Key clarity: 👉 An exception is NOT the user’s mistake itself 👉 It is the error event created because of that mistake 🧠 Example: User enters 0 ➝ Code tries 15 / 0 ➝ 💥 ArithmeticException ➗ Division by Zero — Important Clarity ⚖️ ✅ Integer division: 15 / 0 💥 Throws ArithmeticException ❌ Program stops if not handled ⚠️ Floating-point division: 15.0 / 0 ♾️ Result = Infinity ✅ No exception thrown 👉 So yes, “it gives infinity” is correct, but only for float/double, not int ✔️ 🚨 What Happens When an Exception Is NOT Handled When an exception occurs: ✔️ Execution stops from that exact line ✔️ Java creates an exception object ✔️ JVM searches for a handler ✔️ No handler found ➝ 💀 program terminates ✔️ Stack trace printed 📄 📌 This behavior is called: 👉 Abnormal termination of the program ⏱️ Compile-Time vs Runtime Exceptions ✅ Checked Exceptions (Compile-time checked) 🔹 Compiler forces handling 🔹 Example: File handling (IOException) ✅ Unchecked Exceptions (Runtime) 🔹 Occur during execution 🔹 Compiler does NOT force handling Examples: ArithmeticException NullPointerException 🧠 Throwable Hierarchy Object ↓ Throwable ↓ Exception ↓ ↓ CTE RTE 🔖Frontlines EduTech (FLM) #Java #ExceptionHandling #ProgrammingConcepts #CoreJava #DeveloperMindset #TechAustralia #AustraliaJobs #SydneyTech #MelbourneTech #BrisbaneTech #AustraliaIT #LearningInPublic #SoftwareEngineering #CodingLife #TechExplained
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
-
-
Clean code is a love letter to the person who has to maintain your tests in 6 months. Most automation frameworks don't fail because they’re complex. They fail because they're messy. Here's how we structure a basic POST request with validation using RestAssured in Java: • Simple. • Readable. • Intentional. What makes it clean? • No hardcoded data • Centralized base URI • Assertions that validate behavior, not implementation • Exception handling Good test code should: • Explain itself • Be easy to refactor • Fail loudly and clearly If someone else can't understand your test in 30 seconds, it's not clean enough. What's your personal rule for writing maintainable automation code? #RestAssured #Java #APITesting #CleanCode #TestAutomation #QualityEngineering #SoftwareDevelopment
To view or add a comment, sign in
-
-
A Copy Constructor is more than an alternative to clone() — it’s a deliberate design choice that brings clarity and control to how object state is replicated. Unlike Cloneable, which hides behavior behind reflection and shallow defaults, a copy constructor makes every replication step explicit: 🔹 precise control over deep vs shallow copying 🔹 predictable object graph boundaries 🔹 compatibility with final fields 🔹 no hidden exceptions or fragile casts 🔹 clean integration with immutable and thread-safe designs In concurrent or state-heavy systems, correctness depends on isolating state without guessing what the clone operation actually did. A well-crafted copy constructor turns state replication into a transparent, deterministic, and debuggable part of your design. This is why architecture-level Java code often avoids clone() entirely — and prefers explicit copying where invariants are preserved by design, not by assumption. Hashtags: #Java #AdvancedJava #OOPDesign #JVM #JavaInternals #Immutability #BackendEngineering #SoftwareArchitecture #CleanCode #Concurrency #HighPerformanceJava #JavaDeveloper #ProgrammingConcepts #DeepWork #TechLearning #EngineeringExcellence
To view or add a comment, sign in
-
𝗝𝗮𝘃𝗮 𝗕𝗮𝗰𝗸𝗲𝗻𝗱 𝗗𝗲𝘃𝘀 — 𝗦𝘁𝗼𝗽 𝗖𝗿𝗲𝗮𝘁𝗶𝗻𝗴 𝗧𝗵𝗿𝗲𝗮𝗱𝘀 𝗠𝗮𝗻𝘂𝗮𝗹𝗹𝘆. 𝗦𝘁𝗮𝗿𝘁 𝗕𝘂𝗶𝗹𝗱𝗶𝗻𝗴 𝗦𝗰𝗮𝗹𝗮𝗯𝗹𝗲 𝗦𝘆𝘀𝘁𝗲𝗺𝘀. Most backend performance issues don’t come from bad algorithms. They come from: ❌ Blocking threads ❌ Poor async design ❌ Uncontrolled thread creation That’s exactly why Java gives us: ✅ Executor Framework ✅ Future ✅ CompletableFuture These aren’t “advanced concepts” anymore — they’re real-world production fundamentals. This is what they power every single day: ⚡ Parallel REST calls ⚡ Async database queries ⚡ Payment processing ⚡ Notification systems ⚡ Report generation ⚡ Background jobs If your backend touches any of these… you MUST understand Java concurrency. 💡 Simple Breakdown 🔹 Executor Framework → Manages thread pools efficiently (no thread explosion, better CPU usage) 🔹 Future → Async result… but blocking (get() waits) 🔹 CompletableFuture → Modern non-blocking async pipelines (chaining + callbacks + parallelism) ✅ In short: 👉 Executor saves resources 👉 CompletableFuture saves time 👉 Proper concurrency saves your system Concurrency doesn’t make your code faster — it makes your architecture smarter. If you’re building scalable backend systems, this knowledge is mandatory — not optional. 💬 Good developers write working code. 💬 Great developers write concurrent, scalable code. Inspired By Suresh Bishnoi Sir #Java #BackendDevelopment #Concurrency #Multithreading #CompletableFuture
To view or add a comment, sign in
Explore related topics
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
Smart way of thinking—this is a great example of solving the problem by changing how you look at it