Solved LeetCode 724 with Prefix Sum Logic

Day 19/75 🚀 Solved LeetCode 724 — Find Pivot Index today! ✅ All 747/747 test cases passed ⚡ Runtime: 1 ms (Beats 25.74%) 💾 Memory: 35.78 MB (Beats 53.67%) 🔍 Approach — Prefix Sum Logic The goal is to find an index where the sum of elements to the left equals the sum of elements to the right. Here’s how I solved it: First compute the total sum of the array. Maintain a running left sum (currs). For each index: Left Sum = currs Right ends = sum - currs-nums[i]; If both are equal → we found the pivot index. Update currs by adding the current element. This solution runs in O(n) time and uses O(1) extra space. 💡 Key Learning: Prefix sums make array problems much easier. Whenever you need to compare left vs right portions, prefix sum is the perfect approach. Keep building consistency — one problem a day, every day 💪🔥 #LeetCode #LeetCode75 #CPP #DSA #SlidingWindow #ProblemSolving #CodingJourney #75DaysOfCode

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories