🌟 Day 38 of #100DaysOfCode 🌟 🔍 Exploring Pivot Index & Equilibrium — Balancing Logic with Precision 🔹 What I Solved Today’s challenge focused on finding the pivot index in an array — the position where the sum of all elements to the left equals the sum of all elements to the right. A perfect blend of logic, arithmetic reasoning, and optimization — a reminder that balance matters in both code and life 🧮 Problem: Find the Pivot Index 💡 Example: Input: [1,7,3,6,5,6] → Output: 3 Explanation: Left Sum = 11, Right Sum = 11 → Pivot = 3 🧠 Concepts Used Prefix Sum Logic Iteration & Accumulation Conditional Checking Time Complexity → O(n) ⚙️ Approach 1️⃣ Compute total sum of array 2️⃣ Initialize leftSum = 0 3️⃣ Traverse each index: • If leftSum == totalSum - leftSum - nums[i], return i • Else, add nums[i] to leftSum 4️⃣ Return -1 if no pivot found 🚀 What I Learned ✨ Prefix sums simplify comparisons beautifully ✨ Even small problems teach deep optimization ✨ Balance between simplicity and efficiency is key 💬 Reflection Today’s task was about equilibrium — in arrays and in mindset. Sometimes the calmest logic wins. #100DaysOfCode #Day38 #Java #Array #ProblemSolving #Algorithm
Solved Pivot Index challenge with Java and learned about balance in code and life
More Relevant Posts
-
🔥 Day 117 of My DSA Challenge – Partition Array According to Given Pivot 🔷 Problem : 2161. Partition Array According to Given Pivot 🔷 Level : Medium 🔷 Goal : Rearrange an array so that — 1️⃣ Elements less than the pivot come first 2️⃣ Elements equal to the pivot come next 3️⃣ Elements greater than the pivot come last …and maintain relative order for smaller and larger elements. 🔷 Key Idea : The problem is a great test of array manipulation and partitioning logic — similar to what we see in the partition step of quicksort, but here the order must be stable (unchanged for equal categories). We can solve it cleanly using extra space and multiple passes: First collect elements < pivot Then elements == pivot Finally elements > pivot 🔷 Approach : 1️⃣ Initialize a result array res of same size. 2️⃣ Keep two pointers — left starts from the beginning for smaller elements. right starts from the end for larger elements. 3️⃣ Fill smaller elements from the start. 4️⃣ Fill larger elements from the end (in reverse order). 5️⃣ Fill the middle portion with the pivot. Time Complexity: O(n) Space Complexity: O(n) This problem strengthens your understanding of partitioning logic, stable ordering, and array construction — all fundamental to sorting algorithms and data arrangement. Small rearrangements. Big insights. Every element has its right place — in arrays and in life. ⚡ #Day117 #DSA #100DaysOfCode #LeetCode #Java #Arrays #ProblemSolving #CodingChallenge #Algorithms #DataStructures #LearningJourney #CodeEveryday #DeveloperMindset #EngineerInProgress
To view or add a comment, sign in
-
-
🔥 Day 36/100 of #100DaysOfCode - Matrix Zero Transformation! Today's Problem: Set Matrix Zeroes Task: Given an m x n matrix, if an element is 0, set its entire row and column to 0s. Must be done in-place. Solution: Used the optimal O(1) space approach! Leveraged the first row and first column as markers to track which rows/columns need to be zeroed, with a separate variable for column 0. Key Steps: Mark zeros in first row/column while preserving original state Process inner matrix using the markers Zero rows/columns based on markers Smart Optimizations: Uses matrix itself for storage instead of extra O(m+n) space Handles edge case for first column separately Single pass for marking + two passes for execution Advanced matrix manipulation that demonstrates deep understanding of in-place algorithms! Perfect example of trading complexity for optimal space usage. 🧩 #100DaysOfCode #LeetCode #Java #Algorithms #Matrix #InPlace #CodingInterview
To view or add a comment, sign in
-
-
🔥 Day 120 of My DSA Challenge – Remove Linked List Elements 🔷 Problem : 203. Remove Linked List Elements 🔷 Goal : Remove all nodes from a linked list whose value equals a given val, and return the updated head. 🔷 Key Insight : This problem focuses on Linked List traversal and pointer manipulation, one of the most fundamental concepts in data structures. Directly removing nodes from a linked list can get tricky, especially when dealing with the head node itself. To simplify this, we use a dummy node technique — a smart approach to handle head removals gracefully. 🔷 Approach : 1️⃣ Create a dummy node (dummy) that points to the start of the list. 2️⃣ Use a pointer (tail) to build a new filtered list. 3️⃣ Traverse the original list using head: If head.val != val, link it to the new list. Otherwise, skip the node. 4️⃣ After traversal, ensure tail.next = null to avoid cycles. 5️⃣ Return dummy.next (new head). Time Complexity: O(n) Space Complexity: O(1) This problem reinforces : ✅ Pointer management ✅ Dummy node usage ✅ Clean and safe linked list manipulation When handling linked lists, think in pointers — not positions. Efficient traversal and clean linking make all the difference. ⚡ 120 days strong. One more concept mastered, one step closer to mastery. 🚀 #Day120 #DSA #100DaysOfCode #LeetCode #Java #LinkedList #Pointers #ProblemSolving #Algorithms #DataStructures #CodingChallenge #DeveloperJourney #EngineerMindset #LogicBuilding
To view or add a comment, sign in
-
-
💡 𝗗𝗮𝘆 𝟲 𝗼𝗳 #𝟭𝟬𝟬𝗗𝗮𝘆𝘀𝗢𝗳𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 🧠 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝗦𝘁𝗮𝘁𝗲𝗺𝗲𝗻𝘁: Given an integer array nums, return an array answer such that answer[i] equals the product of all elements of nums except nums[i], without using division and in O(n) time. 💬 𝗘𝘅𝗮𝗺𝗽𝗹𝗲: Input: [1, 2, 3, 4] Output: [24, 12, 8, 6] ⚙️ 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 1.Build a prefix product array → product of all elements to the left of each index. 2.Then traverse from the right, maintaining a running suffix product. 3.Multiply prefix and suffix for each index to get the result — no extra space, no division needed! 𝘀𝘂𝗱𝗼 𝗰𝗼𝗱𝗲 : 𝘪𝘯𝘵 𝘯 = 𝘯𝘶𝘮𝘴.𝘭𝘦𝘯𝘨𝘵𝘩; 𝘪𝘯𝘵[] 𝘳𝘦𝘴𝘶𝘭𝘵 = 𝘯𝘦𝘸 𝘪𝘯𝘵[𝘯]; 𝘳𝘦𝘴𝘶𝘭𝘵[0] = 1; 𝘧𝘰𝘳 (𝘪𝘯𝘵 𝘪 = 1; 𝘪 < 𝘯; 𝘪++) { 𝘳𝘦𝘴𝘶𝘭𝘵[𝘪] = 𝘳𝘦𝘴𝘶𝘭𝘵[𝘪 - 1] * 𝘯𝘶𝘮𝘴[𝘪 - 1]; } 𝘪𝘯𝘵 𝘴𝘶𝘧𝘧𝘪𝘹 = 1; 𝘧𝘰𝘳 (𝘪𝘯𝘵 𝘪 = 𝘯 - 1; 𝘪 >= 0; 𝘪--) { 𝘳𝘦𝘴𝘶𝘭𝘵[𝘪] *= 𝘴𝘶𝘧𝘧𝘪𝘹; 𝘴𝘶𝘧𝘧𝘪𝘹 *= 𝘯𝘶𝘮𝘴[𝘪]; } 𝘳𝘦𝘵𝘶𝘳𝘯 𝘳𝘦𝘴𝘶𝘭𝘵; } ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) #LeetCode#100DaysOfLeetCode#Java#CodingChallenge#DSA #Arrays#PrefixSum#CodingJourney#SoftwareEngineering #ProblemSolving#TechJourney
To view or add a comment, sign in
-
🌳 Day 88 — Finding Connections & Balance in Trees Today was all about exploring two powerful Binary Tree problems — Lowest Common Ancestor (LCA) and Maximum Width of a Binary Tree — both teaching how structure, hierarchy, and relationships matter not just in code. 🔹 Lowest Common Ancestor (LCA) Imagine a family tree 👨👩👧👦 — two people might share a common ancestor generations above. In a Binary Tree, the LCA is that deepest shared node from which both given nodes descend. 🧭 Approach (Step-by-step): 1. If the current node is null, return null. 2. If the current node matches either of the given nodes → return that node. 3. Recursively search in the left and right subtrees. 4. If both sides return non-null → current node is the LCA. 5. Else → return the non-null node. ⏱️ Time Complexity: O(N) — visit every node once 📦 Space Complexity: O(H) — recursive stack (height of tree) 💡 Real-World Analogy: Just like tracing two employees up an organization chart to find their nearest common manager. 🔹 Maximum Width of a Binary Tree Think of a tree as a building with multiple floors. The maximum width is like the floor with the most rooms (nodes). 🧭 Approach (Step-by-step): 1. Perform a Level Order Traversal using a queue. 2. Keep track of each node’s position index. 3. For each level, find width = (last index - first index + 1). 4. Track the maximum width across all levels. ⏱️ Time Complexity: O(N) 📦 Space Complexity: O(N) — for queue storage 💡 Real-World Analogy: Imagine counting how many cars fit side-by-side on each lane of a multi-lane bridge — the lane with the most cars defines the maximum width. #Day88 #100DaysOfCode #DSA #BinaryTree #StriversA2ZDSASheet #ProblemSolving #Java #LearningJourney #CodingCommunity #Consistency
To view or add a comment, sign in
-
🔥 Day 118 of My DSA Challenge – Sort Array By Parity II 🔷 Problem : 922. Sort Array By Parity II 🔷 Goal : Rearrange the array so that — ✅ At even indices, we place even numbers ✅ At odd indices, we place odd numbers Given condition : Half of the numbers are even, half are odd — so a valid arrangement is always possible. 🔷 Key Insight : This problem is a perfect example of pointer-based placement. We don’t need to sort — we just need to place: Even numbers → even positions Odd numbers → odd positions We can do this in one pass by using two pointers: evenP → starts at index 0 oddP → starts at index 1 Whenever we find an even number → place it at evenP, move evenP += 2 Whenever we find an odd number → place it at oddP, move oddP += 2 🔷Approach : 1️⃣ Create a result array res of the same size 2️⃣ Track even and odd positions using two pointers 3️⃣ Traverse the array once 4️⃣ Place each number at the correct index (even or odd) 5️⃣ Return the result array Time Complexity: O(n) Space Complexity: O(n) This problem helps build intuition for index-based placement and parity logic. Place elements where they belong — efficient, simple, and clean ✅ This pattern is useful in : ✅ Rearrangement problems ✅ Partitioning by conditions ✅ Two-pointer placement algorithms Every new problem improves how I think about arrays and patterns. Step-by-step progress, every single day 🔥 #Day118 #DSA #100DaysOfCode #LeetCode #Java #Arrays #TwoPointers #ProblemSolving #CodingJourney #Algorithms #DataStructures #EngineerMindset #GrowEveryday
To view or add a comment, sign in
-
-
💡 Day 92 of #100DaysOfCode Today I explored one of the fundamental problems in Binary Trees — checking whether two trees are identical 🌳 🔍 Problem: Given two binary trees, determine if they are the same in both structure and node values. 💻 Approach Used: I used recursion to solve the problem elegantly. The logic is simple yet powerful — 1️⃣ If both nodes are NULL, they are identical at that branch. 2️⃣ If one is NULL and the other isn’t, they differ. 3️⃣ Otherwise, check whether the current node values match and then recursively compare the left and right subtrees. 🧠 Key Insight: Recursion is a natural fit for tree problems — it mirrors the tree’s structure perfectly, allowing us to break down complex comparisons into smaller, easy-to-handle parts. ✅ Skills Strengthened: Recursive thinking Binary tree traversal concepts Structural comparison logic in C++
To view or add a comment, sign in
-
-
#Day_24 💡 Problem Solved: Intersection of Two Arrays II Today’s challenge tested my ability to handle array manipulation and two-pointer logic efficiently. 🧩 Problem Overview: Given two integer arrays, the task is to find their intersection — meaning the common elements between both arrays, including duplicates. For example: nums1 = [4,9,5] and nums2 = [9,4,9,8,4] 👉 Output should be [4,9] (since both 4 and 9 appear in both arrays). ⚙️ My Approach: Sorting both arrays: By sorting nums1 and nums2, I was able to efficiently compare elements in a linear scan. Two-pointer technique: I used two indices i and j, starting from 0 in each array. If both elements matched → it’s part of the intersection. If one was smaller → move that pointer ahead to catch up. Storing results dynamically: Added all matching elements into an ArrayList. Finally converted it into an integer array for the result. This approach ensures O(n log n) time complexity due to sorting, but O(n) in space — a solid balance between clarity and performance. 🧠 Key Takeaways: Sorting simplifies complex comparison problems. The two-pointer pattern is extremely useful for dealing with sorted arrays. Always remember: clean logic > brute force. 🔥 Every new problem brings a fresh perspective on optimizing logic and learning better ways to handle data structures. #Java #CodingChallenge #LeetCode #100DaysOfCode #ProblemSolving #DSA #ProgrammingJourney #TechWithMudassir
To view or add a comment, sign in
-
-
🔥 Day 115 of My DSA Challenge – Intersection of Two Arrays II 🔷 Problem : 350. Intersection of Two Arrays II 🔷 Goal : Return the intersection of two arrays, where each element in the result must appear as many times as it shows in both arrays. Order doesn’t matter. 🔷 Key Insight : This is an extension of the previous problem (Intersection of Two Arrays). The twist? Here we need to consider duplicate occurrences too. For example : nums1 = [1,2,2,1], nums2 = [2,2] → result should be [2,2] (because 2 appears twice in both). 🔷 Approach : 1️⃣ Use a HashMap to count occurrences of each element in nums1. 2️⃣ Traverse nums2 and check if an element exists in the map. 3️⃣ If yes → add it to the result and decrease its count in the map. 4️⃣ When the count becomes 0, remove it from the map to keep things clean. Time Complexity: O(n + m) Space Complexity: O(n) This problem strengthens hash-based frequency counting and element tracking. Use a map to record frequency — then match, decrease, and clean up. This logic is key for : ✅ Counting duplicates ✅ Array frequency comparison ✅ Inventory & matching systems Every small concept compounds into bigger problem-solving clarity. Step by step, I’m becoming stronger at thinking like a coder 💪💻 #Day115 #DSA #100DaysOfCode #HashMap #LeetCode #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #DeveloperJourney #LogicBuilding #EngineerMindset #GrowEveryday
To view or add a comment, sign in
-
-
#Day_23 💡 Problem Solved: Intersection of Two Arrays Today’s challenge tested my ability to handle array manipulation and two-pointer logic efficiently. 🧩 Problem Overview: Given two integer arrays, the task is to find their intersection — meaning the common elements between both arrays, including duplicates. For example: nums1 = [4,9,5] and nums2 = [9,4,9,8,4] 👉 Output should be [4,9] (since both 4 and 9 appear in both arrays). ⚙️ My Approach: Sorting both arrays: By sorting nums1 and nums2, I was able to efficiently compare elements in a linear scan. Two-pointer technique: I used two indices i and j, starting from 0 in each array. If both elements matched → it’s part of the intersection. If one was smaller → move that pointer ahead to catch up. Storing results dynamically: Added all matching elements into an ArrayList. Finally converted it into an integer array for the result. This approach ensures O(n log n) time complexity due to sorting, but O(n) in space — a solid balance between clarity and performance. 🧠 Key Takeaways: Sorting simplifies complex comparison problems. The two-pointer pattern is extremely useful for dealing with sorted arrays. Always remember: clean logic > brute force. 🔥 Every new problem brings a fresh perspective on optimizing logic and learning better ways to handle data structures. #Java #CodingChallenge #LeetCode #100DaysOfCode #ProblemSolving #DSA #ProgrammingJourney #TechWithMudassir
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