Skip to content

Practice Find the Pivot Integer

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2485
LeetCode Problem

Find the Pivot Integer

Problem Statement

Find an integer x from 1 through n such that the sum from 1 through x equals the sum from x through n, including x in both sums. Return x or -1 if none exists; there is at most one solution.

Source: Find the Pivot Integer on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 8
Output
6

# Example 2

Input
n = 1
Output
1

# Example 3

Input
n = 4
Output
-1

Constraints

1 <= n <= 1000

Related LeetCode Problems

Practice more problems similar to Find the Pivot Integer.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.