Tap here to switch tabs
Problem
Submissions

Problem: Find Pivot Index

Find Pivot Index asks you to return the leftmost position where the sums of elements on both sides are equal, counting an empty side as zero. Return -1 if none exists. Negative values are allowed.

Statement

Given an integer array nums, find the pivot index of the array.

The pivot index is defined as the index where the sum of all elements strictly to its left equals the sum of all elements strictly to its right. If the index lies on the left edge of the array, the left sum is considered 00 since no elements exist to its left. The same applies when the index lies on the right edge.

Return the leftmost pivot index. If no such index exists, return −1-1.

Constraints:

  • 1≤1 \leq nums.length ≤104\leq 10^4

  • −1000≤-1000 \leq nums[i] ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Pivot Index

Find Pivot Index asks you to return the leftmost position where the sums of elements on both sides are equal, counting an empty side as zero. Return -1 if none exists. Negative values are allowed.

Statement

Given an integer array nums, find the pivot index of the array.

The pivot index is defined as the index where the sum of all elements strictly to its left equals the sum of all elements strictly to its right. If the index lies on the left edge of the array, the left sum is considered 00 since no elements exist to its left. The same applies when the index lies on the right edge.

Return the leftmost pivot index. If no such index exists, return −1-1.

Constraints:

  • 1≤1 \leq nums.length ≤104\leq 10^4

  • −1000≤-1000 \leq nums[i] ≤1000\leq 1000