C++ Easy to understand O(n) greedy solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nFirstly we will calcula
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirstly we will calculate the total sum of array\nThen find how far are we from the goal\nthen calculate the number of elements needed to reach the GOAL.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\npublic:\n    int minElements(vector<int>& nums, int limit, int goal) {\n        \n        long long int sum = 0, diff;\n\n        //finding total sum of array\n        for(int x = 0; x < nums.size(); x++)sum+=nums[x];\n\n        //calculating absolute difference of goal and sum\n        diff = (goal>=sum) ? goal-sum : sum-goal;\n\n        //calculate number of elements(<=limit) to fulfill the difference \n        return (diff%limit) ? diff/limit+1 : diff/limit;\n    }\n};\n```
['Greedy', 'C++']