Balanced Split

	public boolean balancedSplitExists(int[] arr) {
		Arrays.sort(arr);
		int i = 0;
		int j = arr.length - 1;
		int leftSum = arr[0];
		int rightSum = arr[arr.length-1];
		while(i <= j) {
			if(leftSum < rightSum) {
				i++;
				leftSum+=arr[i];
			}else if (leftSum > rightSum) {
				j--;
				rightSum+=arr[j];
			} else break;
		}
		if(j-i == 1) return true;
		else return false;
	}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s