𝐀𝐫𝐫𝐚𝐲𝐋𝐢𝐬𝐭 𝐯𝐬 𝐋𝐢𝐧𝐤𝐞𝐝𝐋𝐢𝐬𝐭: 𝐜𝐡𝐨𝐨𝐬𝐢𝐧𝐠 𝐰𝐢𝐭𝐡 𝐢𝐧𝐭𝐞𝐧𝐭 Most programs: Build a list once Iterate over it many times Rarely modify it after creation In these cases, ArrayList is the natural fit due to efficient access, iteration, and memory layout. LinkedList becomes the better option only when: You already hold a stable iterator or position You perform frequent insertions or removals at that exact spot Operations are sequential (queues, deques, pipelines) Random access by index is not required The takeaway is simple: Data structures should be chosen based on access patterns, not assumptions. #Java #SoftwareEngineering #BackendDevelopment #CleanCode #SystemDesign #DataStructures #Performance #Programming #DeveloperMindset
Choosing ArrayList vs LinkedList in Java
More Relevant Posts
-
Continued with Arrays today and worked on finding the second largest element. This one made me slow down. It’s not hard, but it’s easy to get wrong if the logic isn’t clean. int[] arr = {4, 7, 1, 9, 3}; int largest = Integer.MIN_VALUE; int secondLargest = Integer.MIN_VALUE; for (int i = 0; i < arr.length; i++) { if (arr[i] > largest) { secondLargest = largest; largest = arr[i]; } else if (arr[i] > secondLargest && arr[i] != largest) { secondLargest = arr[i]; } } System.out.println(secondLargest); // Output : 7 What this problem made clear: - tracking multiple values needs careful updates - order of conditions matters - edge cases (like duplicate values) can break logic - arrays are less about looping and more about state management This felt like a step up from just finding the maximum. Continuing with Arrays & ArrayLists today. #Java #DSA #Arrays #LearningInPublic #ProblemSolving #CodingJourney #Programming #JavaDeveloper #DeveloperJourney
To view or add a comment, sign in
-
𝗗𝗮𝘆 𝟰𝟵/𝟭𝟬𝟬 | 𝗥𝗲𝗺𝗼𝘃𝗲 𝗗𝘂𝗽𝗹𝗶𝗰𝗮𝘁𝗲𝘀 𝗳𝗿𝗼𝗺 𝗦𝗼𝗿𝘁𝗲𝗱 𝗟𝗶𝘀𝘁 𝗜𝗜 Day 49 ✅ — One day from halfway. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟴𝟮: Remove Duplicates from Sorted List II (Medium) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Remove ALL nodes that have duplicates, not just the extras. If a value appears twice, remove both occurrences. Day 35: Kept one copy of duplicates. Day 49: Remove all duplicates entirely. The difference? An inner while loop to skip ALL duplicate values, then reconnect prev to the node after the duplicate chain. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Dummy node for clean head handling 👉 Detect duplicates: curr.val == curr.next.val 👉 Inner loop: skip ALL duplicate nodes 👉 Reconnect: prev.next = curr.next 👉 Move forward only when no duplicates found Time: O(n), Space: O(1) 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Twenty linked list problems (Day 30-49). The progression from Day 35's "keep one" to Day 49's "remove all" shows how small changes in requirements test true understanding. Tomorrow: Day 50. Halfway milestone. The journey continues. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/g-tqpNVB 𝗗𝗮𝘆 𝟰𝟵/𝟭𝟬𝟬 ✅ | 𝟱𝟭 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #Programming #AlmostHalfway #Day50Tomorrow
To view or add a comment, sign in
-
𝗗𝗮𝘆 𝟯𝟲/𝟭𝟬𝟬 | 𝗠𝗲𝗿𝗴𝗲 𝗧𝘄𝗼 𝗦𝗼𝗿𝘁𝗲𝗱 𝗟𝗶𝘀𝘁𝘀 Day 36 ✅ — Recursion over iteration. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟮𝟭: Merge Two Sorted Lists (Easy) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Merge two sorted linked lists. Instead of the iterative dummy node approach, I used 𝗿𝗲𝗰𝘂𝗿𝘀𝗶𝗼𝗻. Compare the heads. Attach the smaller one, then recursively merge the rest. Base case: if one list is empty, return the other. Elegant. Three lines of logic. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Base cases: if l1 is null, return l2 (and vice versa) 👉 Compare l1.val and l2.val 👉 Attach smaller node and recurse with remaining lists Time: O(n + m), Space: O(n + m) for recursion stack 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Seven linked list problems, and recursion just made this one cleaner than iteration. Sometimes the simplest code is the most powerful. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/g4f4_B69 𝗗𝗮𝘆 𝟯𝟲/𝟭𝟬𝟬 ✅ | 𝟲𝟰 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #Recursion #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #Programming
To view or add a comment, sign in
-
🚀 100 Day Target – Day 18 Problem: Running Sum of 1D Array Concept: Prefix Sum | Cumulative Computation Today’s focus was on building a running (prefix) sum efficiently in a single pass. Approach: ✔ Traverse once ✔ Keep a cumulative sum ✔ Update in-place Time Complexity: O(n) Space Complexity: O(1) Result? 💯 100% Runtime Performance Sometimes simple problems are about writing clean, efficient logic — not overcomplicating the solution. Sharpening basics. Optimizing thinking. Building speed + clarity. 💪 #100DaysOfCode #Day18 #LeetCode #DSA #Java #PrefixSum #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 57 - LeetCode Journey Solved LeetCode 2104: Sum of Subarray Ranges (Medium) today using a brute force + optimization approach. This journey isn’t about solving the hardest problems daily, but about showing up consistently and improving step by step. Problems like this help in building a deeper understanding of arrays and how subarrays behave. Today’s problem reinforced key concepts like: • Understanding how to generate all subarrays efficiently • Tracking minimum and maximum values dynamically • Avoiding recomputation using smart updates • Writing clean and logical nested loop solutions The idea is simple — for each starting index, expand the subarray and keep updating min and max to calculate the range 💡 Every problem adds a new layer to problem-solving skills, and that’s where real growth happens 💯 ✅ Better understanding of subarrays and ranges ✅ Improved thinking for optimization ✅ More confidence in array-based problems Still a long way to go, but progress is progress 🚀 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #Algorithms #Programming #DeveloperJourney #KeepCoding
To view or add a comment, sign in
-
-
Started the Loops module today and began with a problem that actually needs thinking, not just repetition. Checking whether a number is prime or composite made it clear why loops exist in the first place. int n = sc.nextInt(); boolean isPrime = true; for (int i = 2; i <= n - 1; i++) { if (n % i == 0) { isPrime = false; break; } } if (isPrime) { System.out.println("Prime"); } else { System.out.println("Composite"); } What this taught me about loops: - loops are used to test conditions repeatedly, not just print values - breaking early matters once the answer is already known - logic decides when a loop should stop, not just the counter - a small condition inside a loop can change the entire outcome This felt like a good starting point for loops because it connects repetition with decision-making. Continuing with the rest of the loops module today. #Java #Loops #LearningInPublic #Beginner #DSA
To view or add a comment, sign in
-
𝐍𝐞𝐬𝐭𝐞𝐝 𝐥𝐨𝐨𝐩𝐬 𝐥𝐨𝐨𝐤 𝐬𝐢𝐦𝐩𝐥𝐞, 𝐛𝐮𝐭 𝐭𝐡𝐞𝐲 𝐜𝐚𝐫𝐫𝐲 𝐡𝐢𝐝𝐝𝐞𝐧 𝐜𝐨𝐬𝐭. A nested loop is a loop inside another loop. Each extra level increases the number of executions — often more than we expect. for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { // process each pair } } What seems like a small structure can quickly scale to O(n²) operations. That’s why nested loops deserve a second thought: • Are we looping more than necessary? • Can a data structure or early exit simplify this? In real systems, performance issues often start with innocent-looking loops. #Java #Programming #SoftwareEngineering #LearningInPublic #dailyChallenge
To view or add a comment, sign in
-
Most developers learn polymorphism as a definition. But in real systems, it’s what enables flexible architectures, plug-and-play components, and scalable design. In today’s post, I break down Polymorphism in a simple, practical way: • What it really means in software design • Why runtime polymorphism matters most • Real-world examples like payment systems • How it connects to system design patterns If you’re preparing for interviews or trying to move from coding to designing systems, this concept is a must-know. Save this post for revision, and follow the series as we move from OOP fundamentals to system design thinking. #OOP #SoftwareEngineering #SystemDesign #Programming #CleanCode #CodingInterview #DeveloperJourney #TechLearning #BackendDevelopment #DotNet #Java #FullStackDeveloper
To view or add a comment, sign in
-
Day 53 - LeetCode Journey Solved LeetCode 80: Remove Duplicates from Sorted Array II (Medium) using an in-place two-pointer approach. This journey isn’t about solving the hardest problems daily, but about showing up consistently and improving step by step. Problems like this strengthen core fundamentals of arrays and in-place manipulation. Today’s problem reinforced key concepts like: • Using two pointers to track valid positions • Maintaining constraints (at most twice occurrence) • Performing operations in-place with O(1) space • Writing clean and efficient logic The idea is simple — allow each element at most twice by comparing with the element at index i-2, ensuring the array stays valid 💡 Every problem adds a new layer to problem-solving skills, and that’s where real growth happens 💯 ✅ Better understanding of array manipulation ✅ Improved in-place optimization skills ✅ More confidence in DSA concepts Still a long way to go, but progress is progress 🚀 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #Algorithms #Programming #DeveloperJourney #KeepCoding
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
This is a great reminder, Pavan. "Choosing with intent" perfectly captures the critical mindset here, as it's so easy to make assumptions about usage patterns. Have you observed common scenarios or specific application types where developers frequently misjudge the optimal choice between these two?