package org.shkim.codility.demo;


/**
 * 
 * https://codility.com/demo/results/demoUMKAHB-74G/ 64%
 * @author parad
 *
 */
public class Demo
{
	public static int solution(int A[])
	{

		int N = A.length;

		long in_left = 0;
		long in_right = 0;

		for (int i = 0; i < N; i++)
		{
			in_left = 0;
			in_right = 0;

			if (i != 0)
			{
				for (int j = 0; j < i; j++)
				{
					in_left += A[j];
				}
			}

			if (i != N - 1)
			{

				for (int j = i + 1; j < N; j++)
				{
					in_right += A[j];
				}
			}

			if (in_left == in_right)
			{
				return i;
			}
		}

		return -1;
	}
}

package org.shkim.codility.demo;

/**
 * 
 * https://codility.com/demo/results/demoUMKAHB-74G/ 64%
 * 
 * @author parad
 *
 */
public class Demo
{

	public static void main(String[] args)
	{
		int A[] = { -1, 3, -4, 5, 1, -6, 2, 1 };
		System.out.println(solution(A));
	}

	private static int solution(int A[])
	{

		int N = A.length;

		if (N == 1)
		{
			return 1;
		} else if (N == 0)
		{
			return 0;
		}

		long in_left = 0;
		long in_right = 0;

		long all_sum = 0L;
		for (int i = 0; i < N; i++)
		{
			all_sum += A[i];
		}

		long temp = 0L;
		for (int i = 0; i < N; i++)
		{

			temp += A[i];

			if (i == 0)
			{
				in_left = 0;
				in_right = all_sum - A[i];
			} else if (i == N - 1)
			{
				in_left = all_sum - A[i];
				in_right = 0;
			} else
			{
				in_left = temp - A[i];
				in_right = all_sum - in_left - A[i];
			}

			if (in_left == in_right)
			{
				return i;
			}
		}

		return -1;
	}
}

change demo