Mid/SeniorGreedyMath

Find the Minimum Possible Sum of a Beautiful Array

You are given positive integers n and target.

An array nums is beautiful if it meets the following conditions:

  • nums.length == n.
  • nums consists of pairwise distinct positive integers.
  • There does not exist two distinct indices, i and j, in the range [0, n - 1], such that nums[i] + nums[j] == target.

Return the minimum possible sum that a beautiful array could have modulo 10^9 + 7.

Example 1
Inputn = 2, target = 3
Output4
The array nums = [1, 3] is beautiful, and it can be proven that 4 is the minimum possible sum.
Example 2
Inputn = 3, target = 3
Output8
The array nums = [1, 3, 4] is beautiful, and it can be proven that 8 is the minimum possible sum.

Constraints

  • 1 <= n <= 10^9
  • 1 <= target <= 10^9

Asked at 1 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