Split Into Two

Company: IBM_2oct_oncampus

Difficulty: medium

Problem Statement

Split Into Two Problem Description You are given an array arr of N integers. A split cuts the array into two parts at one position: the left part is arr[0..k-1] and the right part is arr[k..N-1] , for some k with 1 <= k <= N-1 , so that both parts are non-empty . There are therefore exactly N-1 possible splits. Count the splits for which the sum of the left part is strictly greater than the sum of the right part. Complete the function splitIntoTwo in the editor below. It has the following parameter: arr : an array of integers. The function must return an integer: the number of splits whose left sum is strictly greater than its right sum. Input The first line contains the integer N , the number of elements. The second line contains N space-separated integers, the elements of arr . Output Print a single integer: the number of valid splits. Examples Example 1 Input 3 10 -5 6 Output 1 Explanation Two splits exist. After one element: left sum 10, right sum 1, and 10 > 1, so this sp