🚀 11/03/26 — Building the Backbone: Custom Stack Implementation Today was a test of resilience. Despite heavy rain and no electricity, I made sure to stay consistent by implementing a Stack from scratch. Even when power is low, the motivation to keep the streak alive is high! 🏗️ Designing a Custom Stack I built a functional Stack using an ArrayList as the underlying container. This structure follows the LIFO (Last-In-First-Out) principle, which is essential for everything from undo buttons to recursion management. The Logic: push(n): Appends an element to the end of the list, which serves as the "top" of the stack. pop(): Removes the element from the last index of the list if it's not empty. top(): Retrieves the value at the last index without removing it. isEmpty(): Checks if the internal list size is zero. Performance Metrics: Time Complexity: O(1) for push, pop, and top operations (average case for ArrayList). Space Complexity: O(N) where N is the number of elements stored. 📊 Implementation Highlights FeatureQueue (March 2nd)Stack (Today)LogicFIFO (First-In-First-Out)LIFO (Last-In-First-Out)ControlHead and Tail pointersSingle "Top" pointer (end of list)Use CaseBFS / BufferingDFS / Undo / Function Calls📈 Consistency Report Consistency isn't just about the days when everything goes right; it's about showing up when things go wrong. Today, even with a machine going down due to low power, completing this implementation reinforces the core principles of memory management I've been studying. Seeing the Stack logic I used iteratively for Trees on March 6th now built from the ground up is another major milestone. Huge thanks to Anuj Kumar (a.k.a CTO Bhaiya on YouTube) for the roadmap. Every bit of code counts toward mastery! My tested Stack implementation is saved (just in time)! 📄👇 #DSA #Java #CodingJourney #Stack #DataStructures #LIFO #Consistency #LearningInPublic #CTOBhaiya
Implementing Custom Stack with ArrayList
More Relevant Posts
-
🚀 #100DaysOfCode – Day 4 Consistency is building up… one concept at a time 💪 ✅ What I accomplished today: 🧠 Spring Boot Learning – REST Controllers & Flow 📌 Key Learnings: Learned about @RestController in Spring Boot → It is a shorthand for @Controller + @ResponseBody → All methods directly return JSON/XML response Understood why using only @Controller is not enough for REST APIs → We need extra configurations, which @RestController simplifies Explored Request Mapping (GET API flow) → How client request hits the controller → How response is returned back Learned about Component Scanning → Spring Boot automatically scans and manages components → Helps in dependency injection & auto-configuration 💻 DSA Practice – Equal Sum Grid Partition 📌 Problem Overview: Given a grid, determine if it's possible to partition it into two parts such that: The sum of both partitions is equal, OR By removing a specific element, the partition can be made equal 📌 Approach: Calculated total sum and maintained two running parts: → topSum and bottomSum Used frequency arrays to track elements in both partitions For every possible split: → Checked if sums are equal → If not, checked whether removing a valid element can balance it Also handled edge cases: → Single row / single column partitions Finally, transposed the grid to reuse logic for vertical splits Submission Link🔗 https://lnkd.in/ewjyGh3N 📌 Key Concepts Used: Prefix-like sum tracking Frequency counting Matrix transformation (transpose) Edge case handling 💡 Reflection: Today was a mix of backend fundamentals + problem-solving Understanding how requests flow in Spring Boot while solving a complex grid problem really helped connect logic with real-world backend thinking. 🔥 Day 4 Done. Moving forward stronger. #SpringBoot #Java #BackendDevelopment #DSA #LeetCode #Consistency #LearningJourney
To view or add a comment, sign in
-
-
🚀 Solved: Product of Array Except Self (LeetCode 238) Today I solved a very interesting problem that strengthens array + prefix-suffix concepts. 🔹 Problem: Given an array, return a new array where each element is the product of all elements except itself — without using division and in O(n) time. 🔹 Approach: Instead of brute force, I used an optimized approach: ✅ Prefix Product (Left side) ✅ Suffix Product (Right side) This avoids division and keeps space & time efficient. 🔹 Key Idea: First pass: store product of all elements to the left Second pass: multiply with product of all elements to the right 🔹 Code Insight: Efficient use of a single array + running suffix variable 🔹 Complexity:🚀 Solved: Product of Array Except Self (LeetCode 238) Today, I tackled an interesting problem that enhances understanding of array concepts, particularly prefix and suffix approaches. 🔹 **Problem:** Given an array, the task is to return a new array where each element is the product of all other elements, excluding itself—without using division and ensuring an O(n) time complexity. 🔹 **Approach:** Instead of using a brute-force method, I opted for an optimized solution: ✅ Compute a Prefix Product (for the left side) ✅ Compute a Suffix Product (for the right side) This method avoids division while maintaining efficiency in both time and space. 🔹 **Key Idea:** - **First pass:** Store the product of all elements to the left of each element. - **Second pass:** Multiply these results by the product of all elements to the right of each element. 🔹 **Code Insight:** Utilizing a single array along with a running suffix variable enhances efficiency. 🔹 **Complexity:** - Time: O(n) - Space: O(1) (excluding the output array) 💡 This problem deepened my understanding of how prefix and suffix patterns can significantly optimize brute-force solutions. #DSA #LeetCode #Java #CodingJourney #100DaysOfCode #ProblemSolving #TechLearning🚀 Solved: Product of Array Except Self
To view or add a comment, sign in
-
-
𝗪𝗲 𝗿𝗲𝗽𝗹𝗮𝗰𝗲𝗱 𝗚𝘂𝗮𝘃𝗮 𝗜𝗺𝗺𝘂𝘁𝗮𝗯𝗹𝗲𝗠𝗮𝗽 𝘄𝗶𝘁𝗵 𝗝𝗮𝘃𝗮 𝗠𝗮𝗽.𝗼𝗳. 𝗔𝗻𝗱 𝘁𝗵𝗲 𝘀𝘆𝘀𝘁𝗲𝗺 𝗯𝗿𝗼𝗸𝗲. 💥 The code still compiled ✅ Nothing looked suspicious 👀 It was a small refactor 🔧 But after the change, behavior was different. Tests started failing ❌ Output changed 📦 Part of the system behaved differently ⚠️ At first glance, this looked strange. We replaced one immutable map with another immutable map. So why did anything break? Because the system had a hidden dependency 🧠 It turned out part of our logic was relying on iteration order. Not explicitly. Not by design. Just implicitly, through how the map was being used. And that was the real problem. Nobody on the team expected that a map would become part of the behavior in that way 🤯 But it already had. So the issue was not just "Guava vs JDK". The issue was that we changed a piece of code without fully understanding what the surrounding system had started to depend on. The quick fix was simple: use LinkedHashMap and restore deterministic ordering ⚡ But the more interesting lesson was not about LinkedHashMap. The real lesson was this: When you replace something that looks equivalent, you may still be changing behavior. Same shape of API does not mean same semantics ❗ Same return type does not mean same guarantees ⚠️ And "it worked before" does not mean the dependency was valid. It may simply have been hidden. That is why before replacing a method, collection, or utility, it is worth understanding 2 things: 1️⃣ The behavior of the thing you are introducing 2️⃣ The behavior your system already depends on #java #springboot #backend #softwareengineering #refactoring #engineering #distributedsystems
To view or add a comment, sign in
-
-
🚀 Day 34 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Maximum Product of Two Digits Problem Insight: Given a number, find the maximum product of any two digits in it. Approach: • Traverse the number digit by digit • Keep track of the two largest digits (large1 and large2) • Multiply the two largest digits to get the answer • No extra data structures required, simple comparison logic Time Complexity: • O(log n) — proportional to the number of digits Space Complexity: • O(1) — only a few variables used Key Learnings: • Simple comparison logic can replace sorting or extra arrays • Breaking down the number digit by digit is often sufficient • Edge cases like single-digit numbers should be considered Takeaway: Finding the largest values while iterating can simplify problems and reduce complexity. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #MathTricks
To view or add a comment, sign in
-
-
Day 79 - LeetCode Journey 🚀 Solved LeetCode 203: Remove Linked List Elements (Easy) — a deceptively simple problem that strengthens core linked list fundamentals. At first, it feels like just removing nodes with a given value. But the real challenge lies in handling edge cases cleanly, especially when deletions happen at the head or consecutively. 💡 Core Idea (Dummy Node + Pointer Control): Introduce a dummy node pointing to head Use a pointer (prev) to traverse the list If prev.next.val == target, skip the node Otherwise, move the pointer forward This ensures safe deletion without losing track of the list. 🤯 Why it works? Because the dummy node acts as a stable anchor, allowing uniform handling of all cases — including when the head itself needs to be removed. ⚡ Key Learning Points: • Importance of dummy node in linked list problems • Handling edge cases like head deletion • Managing consecutive deletions efficiently • Clean pointer manipulation without breaking links • Achieving O(n) time and O(1) space This problem builds the foundation for many advanced linked list operations. Also, this pattern connects with: <>Remove Nth Node from End <>Delete Node in Linked List <>Remove Duplicates (I & II) <>Partition List ✅ Stronger understanding of pointer-based logic ✅ Better handling of tricky edge cases ✅ Writing clean and robust linked list code Mastering these basics is what makes complex problems easier later 🚀 #LeetCode #DSA #Java #LinkedList #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
To view or add a comment, sign in
-
-
There is a quiet shift happening in engineering. Not in tools. Not in frameworks. But in how we think. We are moving from: 👉 Code as instructions to 👉 Systems as flow Pipeline architecture forces you to think differently: Not “what does this method do?” But “how does this move?” And that one shift… changes everything. Wrote about this in my latest newsletter: 👉 Stop Writing Code. Start Designing Pipelines. https://lnkd.in/eyzwtqtg #SoftwareEngineering #SystemDesign #Java #Microservices #Thinking
To view or add a comment, sign in
-
-
Hitting /actuator/refresh updates the config server values — but your beans won't see the new values unless they're annotated with @RefreshScope. Without it, Spring initializes the bean once at startup, injects the property value at that point, and never touches it again. The refresh endpoint updates the Environment, but that bean is already holding a stale copy from startup. @RefreshScope solves this by making the bean a proxy. When a refresh is triggered, Spring destroys the scoped bean and recreates it on the next method call — picking up the latest values from the Environment. Two things worth knowing: 1. @ConfigurationProperties classes also need @RefreshScope if you want them to reload. The annotation alone isn't enough. 2. @RefreshScope on a @Configuration class doesn't automatically propagate to the beans it declares. Each bean that needs to reload must be scoped individually. #Java #SpringBoot #SpringCloud #BackendEngineering
To view or add a comment, sign in
-
-
Building scalable systems isn’t just about code — it’s about architecture. Recently worked on implementing tracing in a multi-tenant architecture, where visibility across tenants is critical for performance, debugging, and reliability. Key takeaways: • Tenant-level observability is a game changer • Distributed tracing helps identify bottlenecks faster • Proper context propagation is everything Designing systems that scale cleanly across tenants is where real engineering begins. #SoftwareEngineering #MultiTenant #SystemDesign #BackendDevelopment #Observability #Java #SpringBoot
To view or add a comment, sign in
-
-
Day 29/30 – LeetCode streak Problem: Fancy Sequence You need to support 'append', 'addAll', 'multAll', and 'getIndex' under modulo '(10^9 + 7)' in 'O(1)' per operation. Core idea Keep the logical sequence implicitly via a global affine transform: * Store an internal array 'vals[]'. * Maintain global coefficients 'mul = a' and 'add = b' so that for every index 'i': 'real_i ≡ a · vals[i] + b (mod M)' * Initially, 'a = 1' and 'b = 0', so the stored value equals the real value. Operations * 'append(val)' We want to store a value 'x' such that: 'a · x + b ≡ val (mod M)' Rearranging gives: 'x ≡ (val − b) · a⁻¹ (mod M)' Since 'M' is prime and 'a ≠ 0', the modular inverse 'a⁻¹' exists and can be computed using Fermat’s little theorem. * 'addAll(inc)' Adding a constant to every element changes the transform: 'a · x + b → a · x + (b + inc)' So we simply update: 'add = (add + inc) % MOD'. * 'multAll(m)' Multiplying every element scales both coefficients: 'a · x + b → (a · m) · x + (b · m)' So update: 'mul = (mul * m) % MOD' 'add = (add * m) % MOD'. * 'getIndex(idx)' If the index is out of range return '-1'. Otherwise compute the real value using the stored transform: 'real = (mul * vals[idx] + add) % MOD'. Day 29 takeaway: Instead of updating every element on each operation, using a lazy affine transformation 'a · x + b' lets you represent the entire sequence with just two parameters, turning what would normally be 'O(n)' updates into constant-time operations. #leetcode #dsa #java #math #design #consistency
To view or add a comment, sign in
-
-
How Spring Uses Topological Sort (Simple Explanation) When working with the Spring Framework, everything feels smooth — you define your components, and Spring handles the rest. But behind the scenes, Spring is solving an important problem: 👉 In what order should objects (beans) be created when they depend on each other? 🧩 The Problem In any real application, different parts depend on each other. For example: A service depends on a repository A repository depends on a database So, you cannot create everything randomly. 👉 You must follow the correct order. ⚡ What Spring Does Spring looks at all these dependencies and builds a relationship like this: Database → Repository → Service Then it ensures: 👉 First create Database, then Repository, then Service 🧠 Where Topological Sort Comes In This is exactly what topological sort does: 👉 It finds a valid order of tasks where dependencies are respected. Spring internally uses this idea to: Understand which bean depends on which Arrange them in the correct sequence Create them without errors 🔄 Inside Spring The Spring IoC Container works like a smart manager: It scans all components Understands their dependencies Decides the correct creation order Initializes everything step by step 🚨 Circular Dependency Problem Sometimes, a bad design creates a loop: A depends on B B depends on A In this case, no correct order exists. Spring detects this and throws an error because: 👉 Topological sorting only works when there is no cycle 💡 Why This Matters Because of this logic, Spring gives you: Proper initialization of objects No missing dependencies Clean and scalable architecture Without it, managing large applications would become very complex. 🚀 Final Thought Topological sort is not something you see directly in Spring, but it is quietly working in the background. 👉 Whenever Spring decides “what to create first and what next” 👉 It is using the logic of topological sorting. #TopologicalSort #DataStructures #Algorithms #GraphTheory #ComputerScience #SpringFramework #JavaDeveloper #BackendDevelopment #SpringBoot #SoftwareEngineering #TechLearning #CodingJourney #Developers #ProgrammingLife #LearnInPublic #TechExplained #SystemDesign #CodingConcepts
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