---
# System prepended metadata

title: Weekly Contest 359
tags: [Weekly Contest]

---

###### tags: `Weekly Contest`
# Weekly Contest 359

## [2828. Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) (<font color=#00B8A3>Easy</font>)

限制 :

<ul>
<li><code>1 <= words.length <= 100</code></li>
<li><code>1 <= words[i].length <= 10</code></li>
<li><code>1 <= s.length <= 100</code></li>
<li><code>words[i] and s consist of lowercase English letters</code></li>
</ul>
### Solution

#### 時間複雜度: $O(n)$

#### 空間複雜度: $O(1)$

程式碼:

```c++=
class Solution {
public:
    bool isAcronym(vector<string>& words, string s) {
        string k ="";
        for(auto word:words)
        {
            k += word[0];
        }
        return k == s ;
    }
};
```

## [2829. Determine the Minimum Sum of a k-avoiding Array](https://leetcode.com/problems/determine-the-minimum-sum-of-a-k-avoiding-array) (<font color=#FFC011>Medium</font>)

限制 :

<ul>
<li><code>1 <= n, k <= 50</code></li>
</ul>
### Solution

寫了一個爛 code ，之後再問大家。

#### 時間複雜度: $O(n^2)$

#### 空間複雜度: $O(n)$

程式碼:

```c++=
class Solution {
public:
    bool is_k_pair(int k, vector<int> array, int input)
    {
        for(int i=0;i<array.size();i++)
        {
            if(array[i]+input == k)
            {
                return true;
            }
        }
        return false;
    }

    int minimumSum(int n, int k) {
        vector<int>record = {};
        int index = 1;
        for(int i=0;i<n;i++)
        {
            if(is_k_pair(k, record, index) == false)
            {
                record.push_back(index);
                cout << index << ' ' ;
            }
            else
            {
                i--;
            }
            index++;
        }
        int result = 0;
        for(int& i:record)
        {
            result+=i;
        }
        return result;
    }
};
```

## [2830. Maximize the Profit as the Salesman](https://leetcode.com/problems/maximize-the-profit-as-the-salesman)(<font color=#FFC011>Medium</font>)

限制 :

<ul>
<li><code>1 <= n <= 10<sup>5</sup></code></li>
<li><code>1 <= offers.length 10<sup>5</sup></code></li>
<li><code>offers[i].length == 3</code></li>
<li><code>0 <= start<sub>i</sub> <= end<sub>i</sub> <= n - 1</code></li>
<li><code>1 <= gold<sub>i</sub> <=10<sup>3</sup></code></li>
</ul>
### Solution

#### 時間複雜度: $O()$

#### 空間複雜度: $O()$

程式碼:

```c++=
```

## [2831. Find the Longest Equal Subarray](https://leetcode.com/problems/find-the-longest-equal-subarray) (<font color=#FFC011>Medium</font>)

限制 :

<ul>
<li><code>10<sup>4</sup></code></li>
</ul>
### Solution

#### 時間複雜度: $O()$

#### 空間複雜度: $O()$

程式碼:

```c++=
```
