Challenge Taken with permission from my University Code Challenge Contest
After finishing her studies a couple of months ago, Marie opened a bank account to start receiving the payment of her first job in town. Since then she has been performing a few transactions with it. Her first payment was $1000 dollars. With that money she paid for a dinner in which she invited her parents (The dinner cost $150 dollars), then, she did a purchase in a well-known supermarket ($80 dollars) and a hotel reservation for her vacations ($200). At the end of the month she received her payment again (1040 dollars, a little more than the previous month) and the day after she spent another $70 dollars at the supermarket.
Today, she realized that if after paying the first $80 dollars in the supermarket a second account had been created and the first one frozen, both accounts would have exactly the same balance:
$$ \underbrace{1000\quad -150\quad -80}_{Total=770}\quad \underbrace{-200\quad 1040\quad -70}_{Total=770} $$
The event was so rare to her that she wants to continue ascertaining if the movements of her account and those of her friends have also this feature or not.
Challenge
Given a list of transactions, output the number of instants of time in which the owner of the bank account could have created a second account so that both had the same final balance.
Example: [1000, -150, -80, -200, 1040, -70]
$$ \color{red}{1)\quad\underbrace{}_{Total=0}\quad \underbrace{1000\quad -150\quad -80\quad -200\quad 1040\quad -70}_{Total=1540}} $$
$$ \color{red}{2)\quad\underbrace{1000}_{Total=1000}\quad \underbrace{-150\quad -80\quad -200\quad 1040\quad -70}_{Total=540}} $$
$$ \color{red}{3)\quad\underbrace{1000\quad -150}_{Total=850}\quad \underbrace{-80\quad -200\quad 1040\quad -70}_{Total=690}} $$
$$ \color{green}{4)\quad\underbrace{1000\quad -150\quad -80}_{Total=770}\quad \underbrace{-200\quad 1040\quad -70}_{Total=770}} $$
$$ \color{red}{5)\quad\underbrace{1000\quad -150\quad -80\quad-200}_{Total=570}\quad \underbrace{ 1040\quad -70}_{Total=970}} $$
$$ \color{red}{6)\quad\underbrace{1000\quad -150\quad -80\quad -200\quad 1040}_{Total=1610}\quad \underbrace{-70}_{Total=-70}} $$
$$ \color{red}{7)\quad\underbrace{1000\quad -150\quad -80\quad-200\quad 1040\quad -70}_{Total=1540}\quad \underbrace{}_{Total=0}} $$
Test Case
- Input:
1000 -150 -80 -200 1040 -70
Output:1
- Input:
100 -100
Output:2
- Input:
1 2 3
Output:1
- Input:
10 -20 15
Output:0
- Input:
15 -15 15 -15
Output:3
- Input:
1
Output:0
Notes
- You can assume there wont be any transaction of $0 dollars
- You can take input in any reasonable way