Java | 4-liner | Beats %100
Intuition\nEvent though tagged as Greedy, you can just re-think it as: given an integer sum, being the sum of all elements in the nums arrays, and the integer r
# Intuition\nEvent though tagged as Greedy, you can just re-think it as: given an integer `sum`, being the sum of all elements in the `nums` arrays, and the integer `remainder`, being the absolute value representing the distance between `sum` and `goal`; how many `limit`s would fit in `remainder`?. That\'s it! a harmless fraction.\n\n# Approach\n- Iterate over the `nums` array to find `sum`.\n- Get `abs(goal - sum)` as `remainder`.\n- Find out how many time would it be required to add `limit` to get to `remainder` (+1 if `remainder % limit != 0`).\n\n**NOTE:** Keep `sums` and `remainder` as long ints to account for large sums.\n\n# Complexity\n- Time complexity: $$O(n)$$ As per the array iteration to get `sums`.\n\n- Space complexity: $$O(1)$$\n\n# Code\n```java []\nclass Solution {\n    public int minElements(int[] nums, int limit, int goal) {\n        \n        long sum = 0;\n        for (long n : nums) { sum += n; }\n\n        long remainder = Math.abs(goal - sum);\n\n        return (int) (remainder / limit) + ((remainder % limit == 0) ? 0 : 1);\n    }\n}\n```
['Java']