Just wrapped up a take home assessment where I built an LRU (Least Recently Used) Cache from scratch in Java, and I decided to take it a step further. Instead of stopping at the basic implementation, I: • Designed it using a combination of HashMap and Doubly LinkedList to achieve O(1) time complexity for both get and put operations • Applied generics to make the cache reusable and type-safe • Extended it into a Spring Boot REST API to simulate real world backend usage • Recorded a walkthrough loom video explaining my design decisions and trade-offs. This exercise was a good reminder that writing code is only one part of the job, being able to clearly explain "WHY" you made certain decisions is just as important. Key takeaway: Clean design + clear communication > just “working code”. Looking forward to more opportunities to build and share. #Java #BackendDevelopment #SystemDesign #SpringBoot #SoftwareEngineering #LRUCache
LRU Cache Implementation in Java with Spring Boot
More Relevant Posts
-
If your class name looks like CoffeeWithMilkAndSugarAndCream… you’ve already lost. This is how most codebases slowly break: You start with one clean class. Then come “small changes”: add logging add validation add caching So you create: a few subclasses… then a few more or pile everything into if-else Now every change touches existing code. And every change risks breaking something. That’s not scaling. That’s slow decay. The Decorator Pattern fixes this in a simple way: Don’t modify the original class. Wrap it. Start with a base object → then layer behavior on top of it. Each decorator: adds one responsibility doesn’t break existing code can be combined at runtime No subclass explosion. No god classes. No fragile code. Real-world example? Java I/O does this everywhere: you wrap streams on top of streams. The real shift is this: Stop thinking inheritance. Start thinking composition. Because most “just one more feature” problems… are actually design problems. Have you ever seen a codebase collapse under too many subclasses or flags? #DesignPatterns #LowLevelDesign #SystemDesign #CleanCode #Java #SoftwareEngineering #OOP Attaching the decorator pattern diagram with a simple example.
To view or add a comment, sign in
-
-
Taking the Two-Pointer technique to LeetCode! Today's challenge: Remove Duplicates from a Sorted Array. After practicing the Two-Pointer pattern for reversing arrays and swapping 0s and 1s, I applied it to a classic LeetCode problem. The challenge? Remove duplicates from an array in-place with O(1) extra memory. Because the array is already sorted, all duplicates are grouped together. • The Slow Pointer (The Writer): Keeps track of where the next unique element should be placed. • The Fast Pointer (The Reader): Scans ahead through the array to find new, unique numbers. • The Logic: If the Reader finds a duplicate, it just skips it. But the moment the Reader finds a new number, the Writer records it at the front of the array and steps forward. #DSA #Java #LeetCode #RemoveDuplicate
To view or add a comment, sign in
-
-
Just dropped a FREE 50+ question guide on Spring Boot Dependency Injection & Configuration — covering everything from basics to expert-level pitfalls! Whether you're prepping for a Java interview or leveling up your Spring skills, this covers what most engineers get wrong in production: ✅ Constructor vs Field Injection — and why one can silently break your singletons ✅ Circular dependencies — Spring Boot 2.6+ now throws errors by default ✅ CGLIB proxying pitfalls in @Configuration vs @Component (lite mode) ✅ The self-invocation trap with @Transactional, @Cacheable & @Async ✅ Prototype beans inside Singletons — a classic stale-instance bug ✅ Thread-safety in singleton beans with mutable state ✅ BeanPostProcessor "too early" instantiation issues ✅ Auto-configuration internals and custom starter creation 🔑 The one thing most people overlook: Calling a @Bean method from another @Bean method inside a @Component gives you a NEW instance, not the singleton — silently breaking your app. The guide includes real code examples, pro tips, and a cheat sheet you can bookmark and revisit before any backend interview. 💬 What Spring pitfall caught YOU off guard the most? Drop it in the comments 👇 #SpringBoot #Java #BackendDevelopment #SoftwareEngineering #CodingInterview #SpringFramework #JavaDeveloper #ProgrammingTips #TechInterview #CleanCode
To view or add a comment, sign in
-
Day 96 - LeetCode Journey Solved LeetCode 901: Online Stock Span in Java ✅ This problem is all about recognizing the pattern and using the right data structure. Instead of checking previous prices one by one, I used a Monotonic Stack to efficiently calculate spans. Every element is pushed and popped at most once → super optimized 🔥 Key idea: Keep removing smaller or equal previous prices and accumulate their spans. Key takeaways: • Monotonic Stack concept (very important) • Avoiding nested loops using stack optimization • Efficient span calculation • Thinking in patterns, not brute force ✅ All test cases passed ⚡ O(n) time and O(n) space This is one of those problems that truly levels up your stack game 💯 #LeetCode #DSA #Java #Stack #MonotonicStack #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
Many RAG examples skip the hardest part: getting useful structure out of real enterprise documents. In this article I build a local Java RAG application with #Quarkus, #Docling, #pgvector, #LangChain4j, and #Ollama. The focus is not only retrieval, but the operational pieces around it: background ingestion, readiness checks, embedding dimension alignment, timeouts, and guardrails around the assistant. https://lnkd.in/dHSJA62w
To view or add a comment, sign in
-
💻 Day 35 of #LeetCode Journey 🔥 Solved: 19. Remove Nth Node From End of List Today’s problem was all about mastering Linked Lists and understanding the power of the Two Pointer technique. 🔍 Key Idea: Instead of calculating the length, I used a smart approach with fast and slow pointers. Move the fast pointer n steps ahead Then move both pointers together This helps locate the node to remove in a single pass ⚡ Why this approach? Efficient: O(n) time complexity No extra space required Clean and optimal solution 🧠 What I learned: Using a dummy node simplifies edge cases (like removing the head) Two-pointer technique is very powerful in linked list problems 📌 Problem Link: https://lnkd.in/gxXDR-YV #Java #DataStructures #LinkedList #CodingJourney #100DaysOfCode #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Your switch-case multiplied again. Here's the refactoring that kills it. When your type code only affects data - not behavior - you can replace switch-case with a class. Not if-else chains, not pattern matching. A class where each type is an instance that carries its own data. This works in Java, JavaScript, Kotlin, C# - any language with classes. The idea is simple: if price, weight, and label all depend on a type code, why scatter that knowledge across three switch statements? Put it in one place. Let the constructor enforce completeness. Add a new type? Create a new instance. The compiler tells you what's missing. No grep. No "did I forget a case somewhere". (When types also change behavior, you need a different approach. That's the next post, next week.) I walked through the full refactoring with a pizza example. From int constants to enums to smart classes. Link in the first comment. #cleancode #refactoring #softwarecraft #codequality
To view or add a comment, sign in
-
-
Struggling with a 'Java heap space error' in your application? 🤯 It is a frustrating but solvable issue! Troubleshooting these OutOfMemoryErrors is a clear, multi-step process: 1️⃣ Collect GC Logs: Enable GC logging to get a timeline of memory pressure, which helps you understand whether your heap is gradually filling up from a leak or if there was a sudden traffic burst. 2️⃣ Capture a Heap Dump: Grab a snapshot of your application memory right before the JVM throws the error (e.g., using -XX:+HeapDumpOnOutOfMemoryError) to see exactly what objects are present, their references, and their sizes. 3️⃣ Analyze the Dump: Use tools like HeapHero or JHat to dig into the dump and uncover valuable insights into your application's memory usage patterns. 4️⃣ Capture a Thread Dump: If your app becomes unresponsive before crashing, a thread dump can reveal stuck threads that are holding onto large object graphs and preventing garbage collection. Ready to dive deeper into these steps and master Java memory issues? Read the full guide here: 👉 https://lnkd.in/gQu6cy5w #Java #JavaDevelopment #SoftwareEngineering #PerformanceTuning #HeapDump #GarbageCollection #HeapHero #OutOfMemoryError
To view or add a comment, sign in
-
-
The Two-Pointer streak continues! Today’s LeetCode Problem: Is Subsequence. After using multiple pointers to sort arrays and move zeroes, I applied the exact same pattern to string manipulation today. The challenge was figuring out if a shorter string (s) is a valid subsequence of a longer string (t) without disturbing the relative order of the characters. Instead of generating all possible subsequences (which would be a massive O(2ⁿ) performance drain), the Two-Pointer approach solves this beautifully in a single pass. Knocking this out in O(n) time and O(1) space is another great reminder of how incredibly versatile this algorithmic pattern is for both arrays and strings. #DSA #Java #LeetCode #IsSebsequenceProblem
To view or add a comment, sign in
-
-
Day 14 of LeetCode — Longest Common Prefix Today I solved the classic problem: finding the longest common prefix among a list of strings. Approach I used: Start with the first string as the prefix Compare it with each string in the array Shrink the prefix until it matches the start of every string If it becomes empty → no common prefix Time Complexity: O(n * m) (n = number of strings, m = length of prefix) This problem reinforced string manipulation and edge case handling (empty arrays, no matches). #Java #DSA #CodingJourney #LeetCode #ProblemSolving #TechGrowth
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
👍