Consecutive Numbers Sum

Reported in interviews at Citadel Robinhood

Problem statement

Given a positive integer $N$, return the number of ways to write $N$ as a sum of two or more consecutive positive integers. This variant excludes the trivial single-term decomposition $N = N$ itself, so the answer is the total number of consecutive-positive-integer representations minus $1$.

Implement:

def consecutiveSumWays(N):
    ...

Return an integer denoting the number of ways.

Example 1: $N = 15$ can be written as $1+2+3+4+5$, $4+5+6$, and $7+8$, so the answer is $3$.

Example 2: $N = 9$ can be written as $2+3+4$ and $4+5$, so the answer is $2$.

Example 3: $N = 5$ can be written as $2+3$, so the answer is $1$.

Show hint

If you knew how many terms the run had, how many possible starting values could there be?

Relevant roles: ML Engineer, Forward Deployed Engineer and AI Engineer.

Related free problems