Find the Pivot Integer Problem

Find the Pivot Integer Problem — ExecCode Easy DSA Practice

Solve the Find the Pivot Integer problem on ExecCode. Free online easy DSA practice in Math. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a positive integer n, find the pivot integer x such that:. Your task is to compute the required answer and return the pivot integer x. The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively. If no such integer exists, return -1. It is guaranteed that there will be at most one pivot index for the given input.

Examples

Input {"n": 8}; Output 6. Input {"n": 1}; Output 1

Constraints

1 <= n <= 1000

Practice Find the Pivot Integer free on ExecCode. Browse DSA problems, topic map, and placement guides.