{"id":"33d33ac7-96eb-4ba3-a031-09e8ceef50f3","name":"Minimum Delta In Partitions","description":"1. You are given an array(arr) of integers.\r\n2. You have to divide all the elements of the given array into two sets S1 and S2.\r\n3. You have to find the minimum value of |(sum of all elements of S1) - (sum of all elements of S2)|.","inputFormat":"A number N\r\narr1\r\narr2... N integers","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= N &lt;= 10^3\r\n1 &lt;= arr[i] &lt;= 10^3","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static int solution(int[] arr, int sum) {\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint[] arr = new int[n];\r\n\t\tint sum = 0;\r\n\t\tfor(int i = 0 ; i < n; i++){\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t\tsum += arr[i];\r\n\t\t}\r\n\t\tSystem.out.println(solution(arr,sum));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\n1 1 7 8 9 1","sampleOutput":"3\r\n","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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"7204e434-8963-4a03-a8bb-c27698853fd9","name":"Minimum Delta In Partitions","slug":"minimum-delta-in-partitions","type":1}],"next":{"id":"f9db54d1-cfac-4538-8ab8-e94dfe78419b","name":"Minimum Number Of Steps To Reduce N","type":1,"slug":"minimum-number-of-steps-to-reduce-n"},"prev":{"id":"0166191b-0aab-40ec-8f24-6db8fafe9b37","name":"Super Ugly Number MCQ","type":0,"slug":"super-ugly-number-mcq"}}}

Minimum Delta In Partitions

1. You are given an array(arr) of integers. 2. You have to divide all the elements of the given array into two sets S1 and S2. 3. You have to find the minimum value of |(sum of all elements of S1) - (sum of all elements of S2)|.

{"id":"33d33ac7-96eb-4ba3-a031-09e8ceef50f3","name":"Minimum Delta In Partitions","description":"1. You are given an array(arr) of integers.\r\n2. You have to divide all the elements of the given array into two sets S1 and S2.\r\n3. You have to find the minimum value of |(sum of all elements of S1) - (sum of all elements of S2)|.","inputFormat":"A number N\r\narr1\r\narr2... N integers","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= N &lt;= 10^3\r\n1 &lt;= arr[i] &lt;= 10^3","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static int solution(int[] arr, int sum) {\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint[] arr = new int[n];\r\n\t\tint sum = 0;\r\n\t\tfor(int i = 0 ; i < n; i++){\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t\tsum += arr[i];\r\n\t\t}\r\n\t\tSystem.out.println(solution(arr,sum));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\n1 1 7 8 9 1","sampleOutput":"3\r\n","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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"7204e434-8963-4a03-a8bb-c27698853fd9","name":"Minimum Delta In Partitions","slug":"minimum-delta-in-partitions","type":1}],"next":{"id":"f9db54d1-cfac-4538-8ab8-e94dfe78419b","name":"Minimum Number Of Steps To Reduce N","type":1,"slug":"minimum-number-of-steps-to-reduce-n"},"prev":{"id":"0166191b-0aab-40ec-8f24-6db8fafe9b37","name":"Super Ugly Number MCQ","type":0,"slug":"super-ugly-number-mcq"}}}
plane

Editor


Loading...

Minimum Delta In Partitions

medium

1. You are given an array(arr) of integers. 2. You have to divide all the elements of the given array into two sets S1 and S2. 3. You have to find the minimum value of |(sum of all elements of S1) - (sum of all elements of S2)|.

Constraints

1 <= N <= 10^3 1 <= arr[i] <= 10^3

Format

Input

A number N arr1 arr2... N integers

Output

Check the sample output and question video.

Example

Sample Input

6 1 1 7 8 9 1

Sample Output

3

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode