`{"id":"9edef438-b176-420b-b2de-b2557f30f7d1","name":"Find Pivot Index","description":"1. Given an array of integers nums, calculate the pivot index of this array.\r\n2. The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.\r\n3. If the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applies to the right edge of the array.\r\n4. Return the leftmost pivot index. If no such index exists, return -1.\r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"1 &lt;= nums.length &lt;= 104\r\n-1000 &lt;= nums[i] &lt;= 1000","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n\nusing namespace std;\n\nint pivotIdx(vector<int>& arr){\n // write your code here\n \n return 0;\n}\n\nint main(){\n int n;\n cin >> n;\n \n vector<int> arr(n,0);\n \n for(int i = 0; i < n; i++){\n cin >> arr[i];\n }\n int pi = pivotIdx(arr);\n cout << pi;\n \n return 0;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int pivot_index(int[]arr) {\r\n //write your code here\r\n return -1;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n\r\n for(int i=0; i < arr.length;i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int pi = pivot_index(arr);\r\n System.out.println(pi);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n1 7 3 6 5 6","sampleOutput":"3","questionVideo":"https://www.youtube.com/embed/AH-YhFNJoas","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"63477d88-b0e3-477c-927a-4e76274e55ed","name":"Find Pivot Index","slug":"find-pivot-index","type":1}],"next":{"id":"5bafd2ec-c865-4304-a837-12b45ca18010","name":"Find Pivot Index","type":3,"slug":"find-pivot-index"},"prev":{"id":"ac08e17f-2a94-4ac0-b9e5-3b4add06faf2","name":"Search A 2d Matrix - 2 MCQ","type":0,"slug":"search-a-2d-matrix-2-mcq"}}}`

# Find Pivot Index

1. Given an array of integers nums, calculate the pivot index of this array. 2. The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right. 3. If the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applies to the right edge of the array. 4. Return the leftmost pivot index. If no such index exists, return -1.

`{"id":"9edef438-b176-420b-b2de-b2557f30f7d1","name":"Find Pivot Index","description":"1. Given an array of integers nums, calculate the pivot index of this array.\r\n2. The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.\r\n3. If the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applies to the right edge of the array.\r\n4. Return the leftmost pivot index. If no such index exists, return -1.\r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"1 &lt;= nums.length &lt;= 104\r\n-1000 &lt;= nums[i] &lt;= 1000","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n\nusing namespace std;\n\nint pivotIdx(vector<int>& arr){\n // write your code here\n \n return 0;\n}\n\nint main(){\n int n;\n cin >> n;\n \n vector<int> arr(n,0);\n \n for(int i = 0; i < n; i++){\n cin >> arr[i];\n }\n int pi = pivotIdx(arr);\n cout << pi;\n \n return 0;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int pivot_index(int[]arr) {\r\n //write your code here\r\n return -1;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n\r\n for(int i=0; i < arr.length;i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int pi = pivot_index(arr);\r\n System.out.println(pi);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n1 7 3 6 5 6","sampleOutput":"3","questionVideo":"https://www.youtube.com/embed/AH-YhFNJoas","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"63477d88-b0e3-477c-927a-4e76274e55ed","name":"Find Pivot Index","slug":"find-pivot-index","type":1}],"next":{"id":"5bafd2ec-c865-4304-a837-12b45ca18010","name":"Find Pivot Index","type":3,"slug":"find-pivot-index"},"prev":{"id":"ac08e17f-2a94-4ac0-b9e5-3b4add06faf2","name":"Search A 2d Matrix - 2 MCQ","type":0,"slug":"search-a-2d-matrix-2-mcq"}}}` Editor

# Find Pivot Index

easy

1. Given an array of integers nums, calculate the pivot index of this array. 2. The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right. 3. If the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applies to the right edge of the array. 4. Return the leftmost pivot index. If no such index exists, return -1.

## Constraints

1 <= nums.length <= 104 -1000 <= nums[i] <= 1000

## Format

### Input

Input is managed for you

### Output

Output is managed for you

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}6 1 7 3 6 5 6```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}3`

Question Video

Discussions

Show Discussion

Related Resources 