Find Pivot Index Problem

Find Pivot Index Problem — ExecCode School DSA Practice

Solve the Find Pivot Index problem on ExecCode. Free online school DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given an integer array nums, return the leftmost pivot index where the sum of every element to the left of the index equals the sum of every element to the right; return -1 if no such index exists.

Examples

Input nums = [1, 7, 3, 6, 5, 6]; Output 3. Input nums = [1, 2, 3]; Output -1. Input nums = [2, 1, -1]; Output 0

Constraints

1 ≤ nums.length ≤ 10⁴ -1000 ≤ nums[i] ≤ 1000

Practice Find Pivot Index free on ExecCode. Browse DSA problems, topic map, and placement guides.