Vertical Sticks

solution to the vertical sticks problem on hacker rank