[C++ Solution (Beats 100.00%)] Min Elements | Explained
IntuitionApproachComplexity

Time complexity:
O(n)


Space complexity:
O(1)

Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(1)

# Code
```cpp []
class Solution {
public:
    int minElements(vector<int>& nums, int limit, int goal) {
        
        /* First, get sum of the array */
        long long arr_sum = 0, diff = 0;
        for (auto val : nums) arr_sum += val;

        /* Now compute the absolute difference between the sum of 
         * the array and the goal value. Compute how many times we can 
         * "fit" the limit value into this difference by dividing the
         * difference by limit. If there is a non-zero remainder, add 1 more */
        diff = std::abs(arr_sum - goal);
        int num_limits = (diff / limit);
        int remainder  = (diff % limit) ? 1 : 0;

        return num_limits + remainder;
    }
};
```
['C++']