Ctrl K

Equal-Sum Split Point

Easy
The numbers from 1 to n are written in a row. Find a number x from that row such that the sum of all numbers from 1 to x equals the sum of all numbers from x to n (x itself counts in both sums). Return x, or -1 if there is no such number. When x exists, it is unique.
Example 1
n=49 → 35

1 + 2 + … + 35 = 630 and 35 + 36 + … + 49 = 630.

Example 2
n=5 → -1

No x from 1 to 5 works: for example, x = 4 gives 10 on the left and 9 on the right.

Example 3
n=1 → 1
Constraints
  • 1 ≤ n ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTotals of Odd-Length Slices EasyEven-Gap Cut Points EasyA Stretch Divisible by k MediumThe Growing Grab Limit MediumStretches With k Odd Numbers Medium
loading Python…
Input
n=49
Expected
35

Run checks the first 3 tests in your browser. Submit checks all 55 tests on the server, hidden ones included.