🔢 Sum of Good Numbers - Easy 💡 | C++ | Brute Force 🚀
Intuition
The problem requires identifying "good" numbers in the array based on their relative values to specific neighboring indices.
A number is considered "g
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
- The problem requires identifying "good" numbers in the array based on their relative values to specific neighboring indices.
-  A number is considered "good" if it is strictly greater than the numbers at indices i - k and i + k, provided those indices exist. If neither of these indices exists, the number is automatically considered "good."
- The goal is to compute the sum of all such "good" numbers.

# Approach
<!-- Describe your approach to solving the problem. -->
1. Initialize a variable sum to store the sum of all "good" numbers.
2. Iterate through the array and check each element nums[i]:
    - If i - k exists (i.e., i - k >= 0), compare nums[i] with nums[i - k].
    - If i + k exists (i.e., i + k < n), compare nums[i] with nums[i + k].
    - If nums[i] is not strictly greater than at least one of these valid indices, it is not a "good" number.
3. If the number is determined to be "good," add it to the sum.
4. Finally, return the computed sum.

This approach ensures that each element is checked in constant time, making the solution efficient.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
    - The algorithm iterates over the array exactly once and performs constant-time checks for each element.
    - O(n), where n is the size of the input array.

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
    - The solution only uses a few integer variables (n, sum, i), so it does not require extra space beyond the input array.
    - O(1) (constant extra space).
# Code
```cpp []
class Solution {
public:
    int sumOfGoodNumbers(vector<int>& nums, int k) {
        int n = nums.size();
        int sum = 0;

        for (int i = 0; i < n; i++) { 
            bool isGood = true;

            if ((i - k >= 0 && nums[i] <= nums[i - k]) ||
                (i + k < n && nums[i] <= nums[i + k])) {
                isGood = false;
            }
            if (isGood) {
                sum += nums[i];
            }
        }
        return sum;
    }
};
```
['C++']