> For the complete documentation index, see [llms.txt](https://coding-9.gitbook.io/untitled/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coding-9.gitbook.io/untitled/hash-and-map/2829.-determine-the-minimum-sum-of-a-k-avoiding-array.md).

# 2829. Determine the Minimum Sum of a k-avoiding Array

## Problem Statement

<br>

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`.

&#x20;

**Example 1:**

<pre><code><strong>Input: n = 5, k = 4
</strong><strong>Output: 18
</strong><strong>Explanation: Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18.
</strong>It can be proven that there is no k-avoiding array with a sum less than 18.
</code></pre>

**Example 2:**

<pre><code><strong>Input: n = 2, k = 6
</strong><strong>Output: 3
</strong><strong>Explanation: We can construct the array [1,2], which has a sum of 3.
</strong>It can be proven that there is no k-avoiding array with a sum less than 3.
</code></pre>

&#x20;

**Constraints:**

* `1 <= n, k <= 50`

## Intuition

```
Basically,
We want minimum sum
So start from 1 and go along

Store the alternate sum in hash set 
Eg- k = 6
Take 1, Store 5 in map so you can skip that number ahead
```

### Links

[2829. Determine the Minimum Sum of a k-avoiding Array](https://leetcode.com/problems/determine-the-minimum-sum-of-a-k-avoiding-array/)

### Video Links

### Approach 1:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
class Solution {
public:
    int minimumSum(int n, int k) {
        int ans = 0;
        unordered_map<int,int> mp;
        int i=1;

        while(n){
            if(mp.find(i) == mp.end()){
                ans += i;
                mp[k-i] = 1;
                n--;
            }
            i++;
        }

        return ans;
    }
};
```

{% endcode %}

### Approach 2:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Approach 3:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Approach 4:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Similar Problems

[2834. Find the Minimum Possible Sum of a Beautiful Array](https://leetcode.com/problems/find-the-minimum-possible-sum-of-a-beautiful-array/)<br>
