Solved Pivot Index challenge with Java and learned about balance in code and life

🌟 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

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories