`{"id":"19811cc3-5110-4309-bf70-e91fdd7c88f2","name":"Split Array Largest Sum","description":"1. Given an array nums which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays.\r\n2. Write an algorithm to minimize the largest sum among these m subarrays.\r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you","constraints":"1 &lt;= nums.length &lt;= 1000\r\n0 &lt;= nums[i] &lt;= 10^6\r\n1 &lt;= m &lt;= nums.length","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint splitArray(vector<int>& arr, int m){\n //Write your code here\n}\n\nint main(){\n int n;\n cin>>n;\n vector<int> arr(n,0);\n for(int i=0; i<n; i++){\n cin>>arr[i];\n }\n int m;\n cin>>m;\n\n int ans = splitArray(arr, m );\n cout<<ans<<endl;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int splitArray(int[]arr, int m) {\r\n //write your code here\r\n return 0;\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 < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int m = scn.nextInt();\r\n\r\n int ans = splitArray(arr, m);\r\n System.out.println(ans);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"5\r\n7 2 5 10 8\r\n2","sampleOutput":"18","questionVideo":"","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":"8f7ed76d-631d-4ae9-a02a-204532802b46","name":"Split Array Largest Sum","slug":"split-array-largest-sum","type":1}],"next":{"id":"74b4cc7a-92be-4157-a0ad-d997cf9b6c84","name":"Split array largest sum","type":3,"slug":"split-array-largest-sum"},"prev":{"id":"896c4096-c045-4f15-8d85-a26ca05b830e","name":"Capacity To Ship Packages Within D Days MCQ","type":0,"slug":"capacity-to-ship-packages-within-d-days-mcq"}}}`

# Split Array Largest Sum

1. Given an array nums which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. 2. Write an algorithm to minimize the largest sum among these m subarrays.

`{"id":"19811cc3-5110-4309-bf70-e91fdd7c88f2","name":"Split Array Largest Sum","description":"1. Given an array nums which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays.\r\n2. Write an algorithm to minimize the largest sum among these m subarrays.\r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you","constraints":"1 &lt;= nums.length &lt;= 1000\r\n0 &lt;= nums[i] &lt;= 10^6\r\n1 &lt;= m &lt;= nums.length","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint splitArray(vector<int>& arr, int m){\n //Write your code here\n}\n\nint main(){\n int n;\n cin>>n;\n vector<int> arr(n,0);\n for(int i=0; i<n; i++){\n cin>>arr[i];\n }\n int m;\n cin>>m;\n\n int ans = splitArray(arr, m );\n cout<<ans<<endl;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int splitArray(int[]arr, int m) {\r\n //write your code here\r\n return 0;\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 < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int m = scn.nextInt();\r\n\r\n int ans = splitArray(arr, m);\r\n System.out.println(ans);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"5\r\n7 2 5 10 8\r\n2","sampleOutput":"18","questionVideo":"","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":"8f7ed76d-631d-4ae9-a02a-204532802b46","name":"Split Array Largest Sum","slug":"split-array-largest-sum","type":1}],"next":{"id":"74b4cc7a-92be-4157-a0ad-d997cf9b6c84","name":"Split array largest sum","type":3,"slug":"split-array-largest-sum"},"prev":{"id":"896c4096-c045-4f15-8d85-a26ca05b830e","name":"Capacity To Ship Packages Within D Days MCQ","type":0,"slug":"capacity-to-ship-packages-within-d-days-mcq"}}}`

Editor

# Split Array Largest Sum

hard

1. Given an array nums which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. 2. Write an algorithm to minimize the largest sum among these m subarrays.

## Constraints

1 <= nums.length <= 1000 0 <= nums[i] <= 10^6 1 <= m <= nums.length

## 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;}5 7 2 5 10 8 2```

### 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;}18`

Discussions

Show Discussion

Related Resources