Understanding Find Pivot Index
Return the leftmost index where the sum strictly to its left equals the sum strictly to its right, or -1 if none exists.
How it works
The right sum is the total minus the left sum and the current value.
Compute the total sum. Compare the running left sum with the derived right sum. Only then include the current value in the left sum.
Try an example
Input: nums = [1, 7, 3, 6, 5, 6]
Output: 3
The right sum is the total minus the left sum and the current value.
Constraints
- 0–64 integers between -1,000,000 and 1,000,000.
- The pivot value is excluded from both sums; an empty side sums to 0.
Use the simulator
Change the input, then choose Visualize input. Use Next and Previous to inspect each decision, or Play to advance automatically. Compare approaches and their complexity. Choose Try yourself to write JavaScript, select My code and Visualize code to inspect its execution, or Run Tests to check results.
Execution happens in your browser. Drafts are saved locally; avoid entering secrets or sensitive information.