#2829
Determine the Minimum Sum of a k-avoiding Array
specialist · 705 · lc medium +30 · verified · 60.6% accepted · 345 likes · top 59%
Description
Two integers n and k are given.
An array of distinct positive integers is a k-avoiding array if no two distinct elements sum to k.
Return the smallest possible total sum of a k-avoiding array of length n.
Example 1:
Input: n = 5, k = 4
Output: 18
Explanation: Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18.
It can be proven that there is no k-avoiding array with a sum less than 18.
Example 2:
Input: n = 2, k = 6
Output: 3
Explanation: We can construct the array [1,2], which has a sum of 3.
It can be proven that there is no k-avoiding array with a sum less than 3.
Code
1
2
3