𝐍𝐞𝐬𝐭𝐞𝐝 𝐥𝐨𝐨𝐩𝐬 𝐥𝐨𝐨𝐤 𝐬𝐢𝐦𝐩𝐥𝐞, 𝐛𝐮𝐭 𝐭𝐡𝐞𝐲 𝐜𝐚𝐫𝐫𝐲 𝐡𝐢𝐝𝐝𝐞𝐧 𝐜𝐨𝐬𝐭. 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
Nested Loops in Java: Performance Considerations
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 68 of #100DaysOfCode 📌 Problem: Combination Sum II Today's challenge was a twist on the classic combination sum problem! Each number in candidates can only be used once, and the solution set must not contain duplicate combinations. 🧠 Approach: Sorted the array first to handle duplicates efficiently Used recursion with backtracking Skipped duplicate elements to avoid repeated combinations Explored all possible combinations by picking/unpicking elements 📊 Stats: ✅ 176/176 test cases passed ⚡ Runtime: 6 ms | Beats 73.38% 💾 Memory: 45.61 MB | Beats 19.56% 📝 Takeaway: The key challenge was avoiding duplicate combinations while ensuring each element is used at most once. Sorting + skipping duplicates during recursion made this elegant. Memory optimization is the next frontier! 🔗 Problem: Combination Sum II 🏷️ #LeetCode #CodingChallenge #Java #Backtracking #Recursion #Algorithms #DuplicateHandling #TechJourney #Programming
To view or add a comment, sign in
-
-
Strong software doesn’t happen by accident — it’s designed with principles. The foundation of Object-Oriented Programming (OOP) stands on four key pillars: • Encapsulation – Protecting data and controlling access within a class. • Abstraction – Exposing only what’s necessary while hiding complexity. • Inheritance – Reusing and extending existing functionality efficiently. • Polymorphism – Allowing flexibility through multiple implementations of the same interface. Mastering these concepts transforms code from functional to structured, scalable, and maintainable. #OOP #Java #SoftwareDesign #Programming #ComputerScience
To view or add a comment, sign in
-
-
Continued with Arrays today and worked on reversing an array in place. This problem made it clear that arrays aren’t just about reading values — they’re about modifying data carefully. int[] arr = {4, 7, 1, 9, 3}; int left = 0; int right = arr.length - 1; while (left < right) { int temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; left++; right--; } for (int x : arr) { System.out.print(x + " "); // Output : 3 9 1 7 4 } What this problem highlighted for me: - two-pointer logic is very common with arrays - in-place operations need careful index handling - swapping looks simple but is easy to mess up - many problems build on this same pattern This felt like an important foundation before moving into rotations. Continuing with Arrays & ArrayLists today. #Java #DSA #Arrays #LearningInPublic #ProblemSolving #Coding #Programming #DeveloperJourney #JavaDeveloper
To view or add a comment, sign in
-
🚀 Day 10 of My Programming Journey – Introduction to Array Traversal Today, I focused on understanding the fundamentals of Array Traversal in Java a core concept that plays a major role in problem-solving and data handling. 🔹 1️⃣ Array Traversal Array traversal means accessing each element of an array one by one. It helps in reading, processing, and analyzing data stored inside arrays. Understanding traversal is important because almost every array-based problem starts here. 🔹 2️⃣ Count Elements in an Array I learned how to logically determine the number of elements present in an array. This concept strengthens understanding of: Array size Loop execution Basic counting logic 🔹 3️⃣ Finding the Maximum Element Index Another important program was identifying the index of the maximum value in an array. This improves: Comparison logic Decision-making using conditions Tracking positions while iterating ✅ Stronger understanding of loops ✅ Better clarity on array structure ✅ Improved logical thinking ✅ Foundation for searching and sorting algorithms #Day10 #Java #ArrayTraversal #ProgrammingJourney #KeepLearning
To view or add a comment, sign in
-
-
Continued with Arrays today and worked on finding the maximum element in an array. This problem looks basic, but it quietly teaches how careful you need to be with initialization and comparisons. int[] arr = {4, 7, 1, 9, 3}; int max = arr[0]; for (int i = 1; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; } } System.out.println(max); // Output : 9 What this problem highlighted for me: - arrays need a sensible starting reference - comparisons depend on correct initialization - one wrong starting value can break the logic - this pattern shows up in many other problems Simple logic, but it sets the base for more complex array questions. Continuing with Arrays & ArrayLists today. #Java #DSA #Arrays #LearningInPublic #ProblemSolving #Coding #Programming #DeveloperJourney #JavaDeveloper
To view or add a comment, sign in
-
🔁 Recursion Made Simple When a function calls itself — that’s Direct Recursion. When it calls another function that calls it back — that’s Indirect Recursion. 💡 Example: Factorial of 6 6 × 5 × 4 × 3 × 2 × 1 = 720 Base Case ➝ Stops the recursion Recursive Call ➝ Breaks problem into smaller parts Think smaller. Solve smaller. Build bigger. 🚀 #Java #Recursion #Programming #CodingLife #DataStructures #LearnToCode
To view or add a comment, sign in
-
-
Day 74/100: LeetCode Challenge - Letter Combinations of a Phone Number 📱 Today I solved the classic backtracking problem - generating all possible letter combinations from a phone number! Problem: Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent (just like the old phone keypads). Example: Input: "23" → Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] My approach: Used backtracking to explore all possible combinations Mapped each digit to its corresponding letters (2→abc, 3→def, etc.) Built combinations recursively by trying each letter for the current digit Results: ✅ Runtime: 3 ms (beats 32.71%) ✅ Memory: 48.65 MB (beats 26.99%) Key takeaway: Backtracking is a powerful technique for generating all combinations/permutations. The key is to build the solution incrementally and backtrack when we've explored a complete path. This problem is a perfect example of when recursion shines! #100DaysOfCode #LeetCode #Java #Backtracking #CodingChallenge #ProblemSolving #Day73 #Programming
To view or add a comment, sign in
-
-
The Sliding Window Counter algorithm is the robust way to handle traffic spikes without letting bursts overwhelm your API at window boundaries. I created a complete guide on YouTube covering everything you need to know about it. Video highlights: 👉 Clear definition & workflow. 👉 Practical visual examples. 👉 Thread-safe code implementation. Level up your system design knowledge today. Watch here: https://lnkd.in/gTvjpesc #SoftwareArchitecture #Programming #TechSkills #Backend #Algorithms #SystemDesign #RateLimiting #BackendEngineering #LowLevelDesign #Concurrency #Java #InterviewPreparation #ScalableSystems #DistributedSystems #Java #Concurrency #Multithreading #SoftwareEngineering #TechLearning
To view or add a comment, sign in
-
Detecting Hidden Patterns #day19 of #100DaysOfCode ✅ Problems Solved 🔹 Find Duplicate Subtrees (LeetCode 652) Approach • Perform postorder traversal to capture subtree structure • Serialize each subtree into a string (node + left + right) • Use a hashmap to track the frequency of each serialization • Collect roots of subtrees that appear more than once Key takeaway : It’s not about brute force comparison — it’s about encoding. Once subtrees are serialized, duplicates reveal themselves naturally. The key realization : This problem highlights the power of representation: - Traversal defines how structure is captured - Serialization transforms trees into comparable signatures - Hashmaps expose repetition without extra overhead Day 19 is done. The chain continues. #LeetCode #Java #Consistency #coding #DSA #GeeksForGeeks #Programming #Daily #Learning Ikshit .. Anchal Sharma
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