Trains the technique from
LeetCode 829Consecutive Numbers SumThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A hall has exactly n seats and they all have to be used. The seats are laid out in one or more rows, read from the front of the hall to the back, under two rules: every row holds at least one seat, and each row after the first holds exactly one seat more than the row directly in front of it.
Two layouts are different when they use a different number of rows, or when some row holds a different number of seats. A single row holding all n seats is a valid layout.
Return how many different layouts the hall allows.
Example 1
Two layouts work: one row of 12, and the three rows 3, 4, 5 which also total 12.
Example 2
The four layouts are the single row 27, the two rows 13 and 14, the three rows 8, 9 and 10, and the six rows 2 through 7.
Example 3
Only the single row of 4 works. A two-row layout would need a front row and a back row one larger that add to 4, and no whole number does that, while the smallest three-row layout already totals 1 + 2 + 3 = 6.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def consecutive_numbers_sum(n: int) -> int:public int consecutiveNumbersSum(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.