Find how much we need and divide that by our limit - O(n)time, O(1)space - 100% speed rank
Intuition\n Describe your first thoughts on how to solve this problem. \nHow much does the limit evenly divide into the difference of the goal minus the current
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nHow much does the limit evenly divide into the difference of the goal minus the current sum of nums (and then add one if limit doesn\'t divide into the difference evenly).\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- *Instead of adding actual numbers to nums, we can just keep track of the amount we\'re supposed to add.*\n1) Find the "target" by adding all integers in "nums" list and subtracting that sum from the "goal".\n2) Initialize another variable to zero, "additional", to represent the last possible digit needed to add to the list (that is less than limit) if the limit doesn\'t divide into our target evenly.\n3) If limit doesn\'t divide into target evenly, set additional to 1.\n4) return the sum of the amount that limit divides into the absolute value of target evenly and the additional variable (a 1 or a 0).\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\nWe have to iterate through the nums list once to find the current sum before a few simple math problems.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\nWe keep track of two integers during this process\n\n# Code\n```python3 []\nclass Solution:\n    def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n        target = goal - sum(nums)\n        additional = 0\n\n        if abs(target) % limit > 0:\n            additional += 1\n        \n        ans = abs(target) // limit + additional\n\n        return ans\n\n```\n\n# Upon Refinement\n```python3 []\nclass Solution:\n    def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n        target = abs(goal - sum(nums))\n\n        if target % limit:\n            additional = 1\n        else:\n            additional = 0\n        \n        return target // limit + additional\n```
['Python3']