Mid/SeniorGreedyMath

Determine the Minimum Sum of a k-avoiding Array

You are given two integers, n and k.

An array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k.

Return the minimum possible sum of a k-avoiding array of length n.

Example 1
Inputn = 5, k = 4
Output18
Consider the k-avoiding array [1, 2, 4, 5, 6], which has a sum of 18, and it can be proven that no k-avoiding array has a smaller sum.
Example 2
Inputn = 2, k = 6
Output3
We can construct the array [1, 2], which has a sum of 3, and it can be proven that no k-avoiding array has a smaller sum.

Constraints

  • 1 <= n, k <= 50

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