Recursive solution:

private static boolean findWinner(int[] a, int i, int j, int p1, int p2, boolean flag) { if (i == j) { if (flag) return p1 + a[i] >= p2; return p1 >= p2 + a[i]; } if (flag) return findWinner(a, i + 1, j, p1 + a[i], p2, false) || findWinner(a, i, j - 1, p1 + a[j], p2, false); return findWinner(a, i + 1, j, p1, p2 + a[i], true) && findWinner(a, i, j - 1, p1, p2 + a[j], true); }Subcategories

LeetCode Weekly Contest 16B