Consecutive Numbers Sum

Given an integer n, return the number of ways you can write n as the sum of consecutive positive integers.

Example 1
Inputn = 5
Output2
The number 5 can be written as 5 and as 2 + 3, so there are 2 ways.
Example 2
Inputn = 9
Output3
The number 9 can be written as 9, 4 + 5, and 2 + 3 + 4, so there are 3 ways.

Constraints

  • 1 <= n <= 10^9

Asked at 8 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate