🚀 100 Days of DSA with Java | Day 5 Q7 🚀 📌 Problem of the Day: Equilibrium Index in an Array You are given an array Arr of N integers. Your task is to find the equilibrium index. 🔹 An index is called an equilibrium index if: 👉 Sum of elements on the left side = Sum of elements on the right side 👉 The element at the index itself is not included in either sum 📝 Important Rules: Array follows 0-based indexing If multiple equilibrium indices exist, return the left-most one If no equilibrium index is found, return -1 📊 Example: Arr = [1, 7, 3, 6, 5, 6] ✅ Output: 3 (Left sum = 1 + 7 + 3 = 11, Right sum = 5 + 6 = 11) 🎯 What I practiced today: Prefix sum optimization Reducing time complexity from O(N²) to O(N) Stronger understanding of array traversal logic 💡 Problems like this build a solid foundation for advanced DSA topics. 📅 Onward to the next challenge tomorrow! #100DaysOfDSA #DSAWithJava #ArrayProblems #ProblemSolving #CodingJourney #LearningInPublic #Consistency #JavaProgramming
Equilibrium Index in Array | Java DSA Challenge
More Relevant Posts
-
🚀 Day 7 / 180 – DSA with Java 🚀 📘 Topic Covered: Modified Binary Search 🧩 Problem Solved: Search in Rotated Sorted Array Problem: Given a sorted array that has been rotated at some pivot, find the index of a target element in O(log n) time. Approach: Used a modified Binary Search by identifying which half of the array is sorted at each step. Based on the sorted portion, narrowed the search space intelligently until the target was found. Key Learning: ✔️ Applying binary search beyond simple sorted arrays ✔️ Identifying sorted halves in rotated arrays ✔️ Maintaining O(log n) efficiency with smart conditions If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #BinarySearch #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 21.... 💡 Today I learned about Prime Factorization in Java! Prime Factorization means breaking a number into its prime factors — the building blocks of the number. 🧩 Basic Approach: int i = 2; while (n > 1) { while (n % i == 0) { System.out.println(i); n = n / i; } i++; } ⏱️ Time Complexity: O(n) ⚙️ Optimized Approach: int i = 2; while (i * i <= n) { while (n % i == 0) { System.out.println(i); n = n / i; } i++; } if (n > 1) System.out.println(n); ⏱️ Time Complexity: O(√n) ✅ Key Takeaway: Checking factors only up to √n makes the algorithm much faster — no need to go till n. Small change, big improvement in performance! #Java #DSA #LearningJourney #Coding #Algorithms #Optimization
To view or add a comment, sign in
-
🚀 Day 6 / 180 – DSA with Java 🚀 📘 Topic Covered: Binary Search 🧩 Problem Solved: Search in Sorted Array Problem: Given a sorted array and a target value, return its index if found. Otherwise, return -1. Approach: Applied the Binary Search technique by repeatedly dividing the search space in half, comparing the middle element with the target, and adjusting the search boundaries accordingly. Key Learning: ✔️ Understanding divide-and-conquer strategy ✔️ Reducing time complexity to O(log n) ✔️ Importance of sorted arrays in efficient searching If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #BinarySearch #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Bubble Sort in Java may look simple, but most mistakes happen because: • we don’t clearly understand what becomes sorted after each pass • we run the inner loop beyond the required range • we miss the fact that no swaps mean the array is already sorted The core idea is straightforward: compare adjacent elements and swap them if they are in the wrong order. After each complete pass, the largest element moves to its correct position at the end of the array. So: – 1st pass → last element is fixed – 2nd pass → last two elements are fixed – each pass reduces the unsorted portion Once you understand that every pass shrinks the problem size, optimizations like early termination using a swapped flag and handling ascending/descending order become intuitive. Bubble Sort isn’t about speed — it’s about clarity of logic. That’s what makes it a great learning tool for beginners in DSA. #Java #BubbleSort #DSA #Algorithms #ProblemSolving #BackendEngineering
To view or add a comment, sign in
-
------Continuing my DSA practice using Java. Today I worked on the “Shortest Completing Word” problem. The task was to find the shortest word that contains all the letters present in a given license plate. I first extracted and counted only the alphabetical characters from the license plate, ignoring digits and case. For each word, I compared its character frequency with the required frequency. If a word satisfied all the conditions, I checked whether it was shorter than the current answer and updated accordingly. Time Complexity: O(n × m) Space Complexity: O(1) Key takeaway: Breaking string problems into frequency comparison steps helps keep the logic clear and manageable. #DSA #Java #Strings #Hashing #ProblemSolving #LearningJourney
To view or add a comment, sign in
-
-
🚀 Day 4 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Index Manipulation 🧩 Problem Solved: Rearrange Array Elements by Sign Problem: Rearrange the array so that positive and negative numbers appear alternately, while maintaining their original relative order. Approach: Used separate indices for positive and negative positions and placed elements at alternating indices in a new array to achieve the required arrangement efficiently. Key Learning: ✔️ Handling index-based placement in arrays ✔️ Maintaining order while rearranging elements ✔️ Breaking problems into position-mapping logic If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 DSA in Java | Shortest Path Using NSEW Directions 🚀 While practicing Data Structures & Algorithms in Java, I solved a classic logic problem: 👉 Finding the shortest path after a sequence of directions (N, S, E, W). 📌 Problem Insight: Given a string consisting of directions: N (North) S (South) E (East) W (West) We track movement on a 2D plane starting from (0, 0) and calculate the shortest distance from the origin after completing the full path. 🧠 Approach Used: Maintain two variables x and y for horizontal and vertical movement Traverse the string once Update coordinates based on direction Final shortest path = |x| + |y| (Manhattan Distance) ⚙️ Complexity: Time Complexity: O(n) Space Complexity: O(1) 💡 What I learned from this problem: ✅ Translating real-world movement into code ✅ Coordinate system fundamentals ✅ Importance of absolute values in distance calculation ✅ Writing optimized and readable Java logic I’m consistently practicing DSA in Java to improve problem-solving skills and build a strong foundation for backend and system-level development. 📈 Learning Focus: Core Java DSA fundamentals Logic building Writing optimized solutions One problem at a time, getting better every day 💻🔥 #DSA #Java #ProblemSolving #LearningInPublic #CodingJourney #JavaDeveloper #DataStructures #Algorithms #100DaysOfCode #BackendDevelopment
To view or add a comment, sign in
-
-
🚀 Day 2 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Two-Pointer Technique 🧩 Problem Solved: Move Zeroes Problem: Move all 0s to the end of the array while maintaining the relative order of non-zero elements, without using extra space. Approach: Identified the first zero and used a two-pointer method to swap non-zero elements forward, ensuring an in-place and efficient solution. Key Learning: ✔️ Better understanding of in-place array manipulation ✔️ Practical use of two-pointer logic ✔️ Writing optimized solutions with O(n) time If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
📝 Day 18/30 – LeetCode #153 (Find Minimum in Rotated Sorted Array) | Java I’ve been a bit inconsistent with daily posting lately due to focusing on deeper revision and understanding core patterns rather than just completing problems for the sake of streaks. Coming back with a classic binary search problem. The key insight here was realizing that even after rotation, at least one half of the array remains sorted. By comparing the middle element with the right boundary, we can decide which half contains the minimum and eliminate the other in each step. This approach reduces the search space logarithmically, resulting in an O(log n) solution. Progress isn’t always linear, but learning is still happening. #LeetCode #Java #DSA #BinarySearch #ProblemSolving #LearningInPublic #ConsistencyOverStreaks
To view or add a comment, sign in
-
-
🔁 Reversing a Linked List in Java — Understanding the Logic Behind It While practicing DSA, I worked on a classic but powerful problem: Reversing a Singly Linked List 🧠 Problem Insight In a singly linked list, each node points only to the next node. To reverse it, we need every node to instead point to its previous node — without losing the rest of the list during the process. ⚙️ Approach (Iterative, In-Place) I solved this using three pointers: 1️⃣ Previous Pointer (prev) Keeps track of the node that should come *before* the current node in the reversed list. 2️⃣ Current Pointer (curr) The node we are currently processing. 3️⃣ Next Pointer (next) Temporarily stores the next node so we don’t lose the remaining list when we change links. 🔄 Step-by-Step Logic * Start with `prev = null` and `curr = head` * For each node: * Save the next node * Reverse the link (point current node to previous) * Move previous forward * Move current forward * When the loop ends, *)prev becomes the new head of the reversed list 🚀 Key Takeaways ✔ Strengthened my understanding of pointer manipulation ✔ Learned how to update links without using extra memory ✔ Reinforced the importance of step-by-step state tracking in DSA problems Sometimes the biggest growth comes from deeply understanding a “simple” problem. Always open to discussions on better or alternative approaches! 🙌 #Java #DataStructures #LinkedList #DSA #ProblemSolving #CodingJourney #SoftwareEngineering #LearningInPublic
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