Skip to content

Instantly share code, notes, and snippets.

@skrauchenia
Last active January 2, 2016 20:09
Show Gist options
  • Save skrauchenia/8355410 to your computer and use it in GitHub Desktop.
Save skrauchenia/8355410 to your computer and use it in GitHub Desktop.
def func(arr: Array[Int],
leftSum: Int = 0, rightSum: Int = 0,
leftInx: Int = -1, rightIdx: Int = -1): Int = {
if (leftInx > rightIdx) {
if (leftSum == rightSum) leftInx else -1
} else {
func(arr.slice(leftInx, rightIdx), arr.head + leftSum, arr.last + rightSum, leftInx + 1, rightIdx - 1)
}
}
func(Array(1, 3, 8, 7, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment