question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
minimum-elements-to-add-to-form-a-given-sum | [Java/Python 3] 2/1 liners. | javapython-3-21-liners-by-rock-1k6b | java\n public int minElements(int[] nums, int limit, int goal) {\n long diff = goal - IntStream.of(nums).mapToLong(i -> i).sum();\n return (int | rock | NORMAL | 2021-03-07T04:02:52.537603+00:00 | 2021-03-07T04:02:52.537655+00:00 | 613 | false | ```java\n public int minElements(int[] nums, int limit, int goal) {\n long diff = goal - IntStream.of(nums).mapToLong(i -> i).sum();\n return (int)((Math.abs(diff) + limit - 1) / limit); \n }\n```\n```python\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n return ... | 9 | 4 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Python 3 | 1-liner | Explanation | python-3-1-liner-explanation-by-idontkno-8ql7 | Explanation\n- Find the absolute difference\n- Add new numbers using limit, count how many numbers need to be added using ceil\n### Implementation\n\nclass Solu | idontknoooo | NORMAL | 2021-03-21T20:19:07.019598+00:00 | 2021-03-21T20:19:07.019631+00:00 | 895 | false | ### Explanation\n- Find the absolute difference\n- Add new numbers using `limit`, count how many numbers need to be added using `ceil`\n### Implementation\n```\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n return math.ceil(abs(goal - sum(nums)) / limit)\n``` | 6 | 0 | ['Greedy', 'Python', 'Python3'] | 1 |
minimum-elements-to-add-to-form-a-given-sum | Python 1-line solution using ceil | python-1-line-solution-using-ceil-by-oto-qd5t | \n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n return math.ceil( abs(goal - sum(nums)) / limit) \n | otoc | NORMAL | 2021-03-07T04:09:45.225510+00:00 | 2021-03-07T04:09:45.225550+00:00 | 470 | false | ```\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n return math.ceil( abs(goal - sum(nums)) / limit) \n``` | 6 | 0 | [] | 1 |
minimum-elements-to-add-to-form-a-given-sum | Java Greedy Solution | java-greedy-solution-by-admin007-kocl | \npublic int minElements(int[] nums, int limit, int goal) {\n\tlong sum = 0;\n\tfor (int i = 0; i < nums.length; i++) {\n\t\tsum += nums[i];\n\t}\n\tlong delta | admin007 | NORMAL | 2021-03-12T19:21:30.967885+00:00 | 2021-03-12T19:23:41.453658+00:00 | 646 | false | ```\npublic int minElements(int[] nums, int limit, int goal) {\n\tlong sum = 0;\n\tfor (int i = 0; i < nums.length; i++) {\n\t\tsum += nums[i];\n\t}\n\tlong delta = (long)goal - sum;\n\treturn (int)((Math.abs(delta) + limit - 1) / limit); // You will need the ceil in such a integer division here.\n}\n``` | 5 | 0 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Python math ceil | python-math-ceil-by-it_bilim-wo24 | \n\ndef minElements(self, nums, limit, goal):\n import math\n t = float(sum(nums)) # count sum of all elements\n s = abs(goal | it_bilim | NORMAL | 2021-03-07T04:01:26.948814+00:00 | 2021-03-07T04:17:42.234185+00:00 | 627 | false | ```\n\ndef minElements(self, nums, limit, goal):\n import math\n t = float(sum(nums)) # count sum of all elements\n s = abs(goal -t) # find diffence between goal and sum\n return int(math.ceil(s/limit)) # find how many numbers can be added (nums[i]<=limit... | 5 | 3 | ['Python'] | 1 |
minimum-elements-to-add-to-form-a-given-sum | Easy C++ solution || commented | easy-c-solution-commented-by-saiteja_bal-23a1 | \nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n \n //just calculate how many limit values to be added to | saiteja_balla0413 | NORMAL | 2021-06-18T06:26:53.841950+00:00 | 2021-06-18T06:26:53.841993+00:00 | 576 | false | ```\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n \n //just calculate how many limit values to be added to the array to make our currSum close to the goal\n long int currSum=0;\n for(auto ele:nums)\n currSum+=ele;\n long int remain... | 4 | 0 | ['Greedy', 'C'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Simple Java Solution | simple-java-solution-by-kodiswaran-02dd | \nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n long sum = 0;\n for(int num: nums)\n sum += num;\n | kodiswaran | NORMAL | 2021-03-07T04:00:50.722330+00:00 | 2021-03-07T04:00:50.722374+00:00 | 608 | false | ```\nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n long sum = 0;\n for(int num: nums)\n sum += num;\n long diff = Math.abs(sum-goal);\n return (int) (diff/limit) + (diff%limit>0?1:0);\n }\n}\n``` | 4 | 1 | ['Java'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | C++ | Easy to Understand Solution O(n) | c-easy-to-understand-solution-on-by-user-y36s | class Solution {\npublic:\n int minElements(vector& nums, int limit, int goal) {\n long long sum = 0;\n for(int i=0;i<nums.size();i++){\n | user2921bc | NORMAL | 2022-05-10T11:40:30.545932+00:00 | 2022-05-10T11:40:30.545961+00:00 | 445 | false | class Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long sum = 0;\n for(int i=0;i<nums.size();i++){\n sum += nums[i];\n }\n if(sum == goal){\n return 0;\n }\n long long diff = abs(goal-sum);\n long long an... | 3 | 0 | ['C'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Fastest and Simplest greedy solution - Beats 100% time and 100% memory - With detailed explanation | fastest-and-simplest-greedy-solution-bea-m5o7 | We start by calculating the total sum of the elements of the array.\n * We then simplify our problem by making the new goal as abs(goal-sum) and starting sum | yajassardana | NORMAL | 2021-03-07T04:36:17.533578+00:00 | 2021-03-07T05:31:27.194478+00:00 | 164 | false | * We start by calculating the **total sum** of the elements of the array.\n * We then simplify our problem by making the new goal as **abs(goal-sum)** **and starting sum as 0**.\n * Then comes the** most important part** --> We\'ve to calculate count by counting the number of times a limit value will come while a... | 3 | 1 | ['Greedy', 'C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | 1-liner Solutions (C++, Python, JS) | beats 100% | short & easy w/ explanation | 1-liner-solutions-c-python-js-beats-100-hhbip | Solution -\nThe solution can be arrived at using a greedy approach. We just need to find the current sum, get the absolute differene of the current sum and goal | archit91 | NORMAL | 2021-03-07T04:08:25.970789+00:00 | 2021-03-07T04:33:43.653006+00:00 | 100 | false | **Solution -**\nThe solution can be arrived at using a greedy approach. We just need to find the current sum, get the absolute differene of the current sum and `goal`, and keep adding `limit` (since that\'s the biggest element we can add so as to get smallest number of additions). The number of times we need to add `li... | 3 | 2 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Clean Python 3, straightforward | clean-python-3-straightforward-by-lenche-a20t | Time: O(N + diff / limit)\nSpace: O(1)\n\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n total = sum(nums)\ | lenchen1112 | NORMAL | 2021-03-07T04:03:20.766943+00:00 | 2021-03-07T04:03:20.766986+00:00 | 192 | false | Time: `O(N + diff / limit)`\nSpace: `O(1)`\n```\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n total = sum(nums)\n diff = abs(total - goal)\n return diff // limit + (diff % limit > 0)\n``` | 3 | 0 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | [Python3] 1-line | python3-1-line-by-ye15-ce2g | \n\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n return ceil(abs(goal - sum(nums))/limit)\n | ye15 | NORMAL | 2021-03-07T04:01:19.795339+00:00 | 2021-03-07T04:01:19.795383+00:00 | 319 | false | \n```\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n return ceil(abs(goal - sum(nums))/limit)\n``` | 3 | 1 | ['Python3'] | 1 |
minimum-elements-to-add-to-form-a-given-sum | Python Elegant & Short | 1-Line | python-elegant-short-1-line-by-kyrylo-kt-hoay | Complexity\n- Time complexity: O(n)\n- Space complexity: O(1)\n\n# Code\n\nfrom math import ceil\n\nclass Solution:\n def minElements(self, nums: List[int], | Kyrylo-Ktl | NORMAL | 2023-03-19T22:01:58.013017+00:00 | 2023-03-19T22:01:58.013055+00:00 | 470 | false | # Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(1)$$\n\n# Code\n```\nfrom math import ceil\n\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n return ceil(abs(sum(nums) - goal) / limit)\n\n``` | 2 | 0 | ['Python3'] | 1 |
minimum-elements-to-add-to-form-a-given-sum | C++ Easy to understand O(n) greedy solution | c-easy-to-understand-on-greedy-solution-cxef5 | 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 | Mdkaif2938 | NORMAL | 2023-02-19T15:39:39.223219+00:00 | 2023-02-19T15:39:39.223263+00:00 | 359 | false | # 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# Complexi... | 2 | 0 | ['Greedy', 'C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Easy to understand Greedy solution| Javascript | tc: O(n) | sc: O(1) | easy-to-understand-greedy-solution-javas-hrho | Complexity\n- Time complexity: O(N)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co | aaryansinha16 | NORMAL | 2023-01-26T19:26:22.975051+00:00 | 2023-01-26T19:26:22.975089+00:00 | 134 | false | # Complexity\n- Time complexity: $$O(N)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * @param {number[]} nums\n * @param {number} limit\n * @param {number} goal\n * @return {number}\n */\nvar minEle... | 2 | 0 | ['Greedy', 'JavaScript'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Java || Greedy || 1ms || beats 100% in time and memory || T.C - O(N) S.C - O(1) | java-greedy-1ms-beats-100-in-time-and-me-klsw | \n public int minElements(int[] nums, int limit, int goal) {\n \n int count = 0,len = nums.length;\n long sum = 0;\n for(int i=0; | LegendaryCoder | NORMAL | 2021-03-07T09:01:45.537700+00:00 | 2021-03-07T09:01:45.537746+00:00 | 71 | false | \n public int minElements(int[] nums, int limit, int goal) {\n \n int count = 0,len = nums.length;\n long sum = 0;\n for(int i=0;i<len;i++)\n sum+=nums[i];\n \n if(sum == goal)\n return 0;\n \n long diff = Math.abs(goal - sum);\n ... | 2 | 1 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Java || One Pass | java-one-pass-by-vishnu_jupiter-daro | \tclass Solution {\n \n\t\tpublic int minElements(int[] nums, int limit, int goal) {\n \n\t\t\tlong sum = 0, temp;\n\n\t\t\tfor(int i : nums)\n\t\t\t\ | Vishnu_Jupiter | NORMAL | 2021-03-07T05:38:55.354296+00:00 | 2021-03-07T05:38:55.354343+00:00 | 187 | false | \tclass Solution {\n \n\t\tpublic int minElements(int[] nums, int limit, int goal) {\n \n\t\t\tlong sum = 0, temp;\n\n\t\t\tfor(int i : nums)\n\t\t\t\tsum += i;\n\t\t\tif(sum == goal) // if sum and goal is equal then no element is required \n\t\t\t\treturn 0;\n\t\t\ttemp = Math.abs(sum - goal);\n\t\t\treturn... | 2 | 1 | ['Math', 'Java'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | C++ Short Greedy Solution | c-short-greedy-solution-by-niloiv-mre5 | \nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long sum = 0;\n for (int num : nums) {\n s | niloiv | NORMAL | 2021-03-07T04:27:14.349488+00:00 | 2021-03-07T04:27:14.349517+00:00 | 340 | false | ```\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long sum = 0;\n for (int num : nums) {\n sum += num;\n }\n long target = goal - sum;\n return target % limit == 0 ? abs(target / limit) : abs(target/limit) + 1;\n }\n};\n``` | 2 | 0 | [] | 1 |
minimum-elements-to-add-to-form-a-given-sum | c++ easy to understand clean code | c-easy-to-understand-clean-code-by-codin-71ln | \nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long sum = 0;\n for (auto& num : nums) sum += num;\n | codingmission | NORMAL | 2021-03-07T04:03:03.568513+00:00 | 2021-03-07T04:04:58.390066+00:00 | 169 | false | ```\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long sum = 0;\n for (auto& num : nums) sum += num;\n long diff = abs(goal - sum);\n return diff % limit ? (diff / limit) + 1 : diff / limit;\n }\n};\n``` | 2 | 1 | ['C'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Simple C++ solution | simple-c-solution-by-gcsingh1629-ccz6 | Code\n\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long sum=0;\n for(auto n:nums){\n | gcsingh1629 | NORMAL | 2023-10-15T05:26:37.714340+00:00 | 2023-10-15T05:26:37.714365+00:00 | 90 | false | # Code\n```\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long sum=0;\n for(auto n:nums){\n sum+=n;\n }\n long long diff=abs(goal-sum);\n return diff%limit==0?diff/limit:(int)(diff/limit+1);\n }\n};\n``` | 1 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Only 2 Lines Code || Easy C++ ✅✅ | only-2-lines-code-easy-c-by-deepak_5910-rzxk | Approach\n Describe your approach to solving the problem. \nResult = abs(Current_Sum - Goal) / Limit + (abs(Current_sum-Goal)%Limit!=0)\n# Complexity\n- Time co | Deepak_5910 | NORMAL | 2023-08-11T18:55:40.439895+00:00 | 2023-08-11T18:55:40.439949+00:00 | 233 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\n`Result = abs(Current_Sum - Goal) / Limit + (abs(Current_sum-Goal)%Limit!=0)`\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$... | 1 | 0 | ['Greedy', 'C++'] | 1 |
minimum-elements-to-add-to-form-a-given-sum | [JavaScript] 1785. Minimum Elements to Add to Form a Given Sum | javascript-1785-minimum-elements-to-add-q9mhm | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | pgmreddy | NORMAL | 2023-08-06T14:30:43.471883+00:00 | 2023-08-06T14:30:43.471914+00:00 | 150 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['JavaScript'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Short & Concise | C++ | short-concise-c-by-tusharbhart-v02x | \nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long sum = 0;\n for(int i : nums) sum += i;\n | TusharBhart | NORMAL | 2023-06-15T18:38:28.926211+00:00 | 2023-06-15T18:38:28.926233+00:00 | 227 | false | ```\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long sum = 0;\n for(int i : nums) sum += i;\n \n long long diff = goal - sum;\n return ceil((double)abs(diff) / limit);\n }\n};\n``` | 1 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Python 3 solution - O(1) solution | python-3-solution-o1-solution-by-ankisha-jb56 | Intuition and Approach\n\nTo solve this problem, We need to find the minimum number of elements that we can add to the array to reach the goal sum while maintai | ankits0052 | NORMAL | 2023-04-19T20:22:15.360547+00:00 | 2023-04-19T20:22:15.360589+00:00 | 92 | false | # Intuition and Approach\n\nTo solve this problem, We need to find the minimum number of elements that we can add to the array to reach the goal sum while maintaining the property that abs(nums[i]) <= limit for all i.\n\nFirst, we calculate the current sum of the array. Then, we calculate the difference between the goa... | 1 | 0 | ['Python3'] | 1 |
minimum-elements-to-add-to-form-a-given-sum | JAVA one line solution | java-one-line-solution-by-21arka2002-w5vj | \n\n# Code\n\nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n return (int)(Math.ceil((Math.abs((long)goal-(Arrays.strea | 21Arka2002 | NORMAL | 2023-04-03T10:31:12.561960+00:00 | 2023-04-03T10:34:20.591232+00:00 | 586 | false | \n\n# Code\n```\nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n return (int)(Math.ceil((Math.abs((long)goal-(Arrays.stream(Arrays.stream(nums).mapToLong(i->i).toArray()).sum())))*1.0/limit));\n }\n}\n```\n\n```\n//Convert integer array to long array\nlong[] longArray = Array... | 1 | 0 | ['Array', 'Math', 'Greedy', 'Java'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | C++ | greedy | fast | c-greedy-fast-by-venomhighs7-avaq | \n\n# Code\n\nclass Solution {\npublic:\n int minElements(vector<int>& A, int limit, int goal) {\n long sum = accumulate(A.begin(), A.end(), 0L), | venomhighs7 | NORMAL | 2022-11-15T03:59:38.975987+00:00 | 2022-11-15T03:59:38.976012+00:00 | 811 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int minElements(vector<int>& A, int limit, int goal) {\n long sum = accumulate(A.begin(), A.end(), 0L), diff = abs(goal - sum);\n return (diff + limit - 1) / limit;\n }\n};\n``` | 1 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | c++ using greedy | c-using-greedy-by-yashodhan11-opog | \nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long total=0;\n for(int i=0;i<nums.size();i++){\ | Yashodhan11 | NORMAL | 2022-10-03T13:31:55.712497+00:00 | 2022-10-03T13:31:55.712535+00:00 | 345 | false | ```\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long total=0;\n for(int i=0;i<nums.size();i++){\n total+=nums[i];\n }\n long long count=0;\n long long target=abs(goal-total);\n while(target && limit){\n ... | 1 | 0 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Python. One liner. Faster than 69%... | python-one-liner-faster-than-69-by-nag00-8zin | \nclass Solution:\n def minElements(self, x: List[int], limit: int, goal: int) -> int:\n return ceil(abs(goal-sum(x))/limit)\n | nag007 | NORMAL | 2022-06-24T17:16:58.512352+00:00 | 2022-06-24T17:17:14.893801+00:00 | 183 | false | ```\nclass Solution:\n def minElements(self, x: List[int], limit: int, goal: int) -> int:\n return ceil(abs(goal-sum(x))/limit)\n``` | 1 | 0 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | [Py/Py3] Solution w/ comments | pypy3-solution-w-comments-by-ssshukla26-itya | \nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n """\n 1) Take the sum of nums\n 2) Chech how | ssshukla26 | NORMAL | 2021-09-12T18:27:48.618018+00:00 | 2021-09-12T18:27:48.618066+00:00 | 201 | false | ```\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n """\n 1) Take the sum of nums\n 2) Chech how many steps it is aways from goal\n 3) Divide the steps w.r.t limit\n 4) The ceiling of the division will give you\n no. of hopes req... | 1 | 0 | ['Greedy', 'Python', 'Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | One liners, 98% speed | one-liners-98-speed-by-evgenysh-tqrs | Runtime: 708 ms, faster than 98.60%\nMemory Usage: 26.8 MB, less than 96.28%\n\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: in | evgenysh | NORMAL | 2021-07-16T16:04:34.119839+00:00 | 2021-07-16T16:04:34.119969+00:00 | 233 | false | Runtime: 708 ms, faster than 98.60%\nMemory Usage: 26.8 MB, less than 96.28%\n```\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n return ceil(abs(goal - sum(nums)) / limit)\n``` | 1 | 0 | ['Python', 'Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | C++ Easy Short Math Solution | c-easy-short-math-solution-by-vibhu17200-3ai9 | \nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long sum=0;\n for(int i=0;i<nums.size();i++)\n | vibhu172000 | NORMAL | 2021-07-04T02:25:22.713697+00:00 | 2021-07-04T02:25:22.713727+00:00 | 112 | false | ```\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long sum=0;\n for(int i=0;i<nums.size();i++)\n {\n sum+=nums[i];\n }\n int ans=0;\n long long x = goal-sum;\n x=abs(x);\n if(x%limit==0)\n {\n ... | 1 | 0 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | It should have been classified as Easy | it-should-have-been-classified-as-easy-b-421y | \n/**\n * @param {string} s\n * @return {boolean}\n */\nvar splitString = function(s) {\n const len = s.length\n \n function toKey(fromIndex, fromVal) | lilongxue | NORMAL | 2021-05-02T15:47:03.265653+00:00 | 2021-05-02T15:47:03.265690+00:00 | 69 | false | ```\n/**\n * @param {string} s\n * @return {boolean}\n */\nvar splitString = function(s) {\n const len = s.length\n \n function toKey(fromIndex, fromVal) {\n return [fromIndex, fromVal].join(\'|\')\n }\n // key => result of key\n const map = new Map()\n function isOK(fromIndex, fromVal) {\n ... | 1 | 1 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | [JavaScript] Easy to understand - 1-line greedy | javascript-easy-to-understand-1-line-gre-was6 | For this problem, the key point is that we could add multiple identical numbers, which means it\'s straightforward to solve it via greedy strategy.\n\njs\nconst | poppinlp | NORMAL | 2021-03-22T09:47:58.181382+00:00 | 2021-03-22T09:51:55.521890+00:00 | 174 | false | For this problem, the key point is that we could add multiple identical numbers, which means it\'s straightforward to solve it via greedy strategy.\n\n```js\nconst minElements = (nums, limit, goal) => {\n let diff = goal;\n for (let i = 0; i < nums.length; ++i) {\n diff -= nums[i];\n }\n return Math.ceil(Math.ab... | 1 | 0 | ['JavaScript'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | C++ solution | c-solution-by-oleksam-iutn | \nint minElements(vector<int>& nums, int limit, int goal) {\n\tlong sum = accumulate(nums.begin(), nums.end(), 0L);\n\treturn ceil((double)abs(goal - sum) / lim | oleksam | NORMAL | 2021-03-21T19:13:31.901579+00:00 | 2021-03-21T19:32:13.514022+00:00 | 224 | false | ```\nint minElements(vector<int>& nums, int limit, int goal) {\n\tlong sum = accumulate(nums.begin(), nums.end(), 0L);\n\treturn ceil((double)abs(goal - sum) / limit);\n}\n```\n | 1 | 0 | ['C', 'C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Python Concise solution 100% Faster and 100% less memory usage (3-liner) | python-concise-solution-100-faster-and-1-4gim | First of all, we need to find the absolute difference in the sum of the array and the goal to find the total sum of the values that are to be added in it. Then | tier10coder | NORMAL | 2021-03-19T10:42:28.417013+00:00 | 2021-03-20T03:14:06.072603+00:00 | 160 | false | First of all, we need to find the absolute difference in the sum of the array and the goal to find the total sum of the values that are to be added in it. Then we simply find the ceiling value of the absolute difference divided by the limit. Using the if else condtion instead of math.floor makes the code faster .\n\n``... | 1 | 0 | ['Greedy', 'Python'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Java 3 lines: meaningless question. Better to modify as... | java-3-lines-meaningless-question-better-wjek | The question is too simple as medium.\nBetter to modify to: try to find minimum modifications required to make sum equals goal.\n\nclass Solution {\n public | DaviLu | NORMAL | 2021-03-13T22:11:46.997521+00:00 | 2021-03-13T22:11:46.997551+00:00 | 115 | false | The question is too simple as medium.\nBetter to modify to: try to find minimum modifications required to make `sum` equals `goal`.\n```\nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n var sum=0L;\n for(int num:nums) sum+=num;\n return (int) ((Math.abs(sum-goal)+l... | 1 | 0 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Simple C++ O(N) solution | simple-c-on-solution-by-indrajohn-gm6p | \nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n double sum = 0;\n for (int i = 0; i < nums.size(); i+ | indrajohn | NORMAL | 2021-03-13T09:55:47.181755+00:00 | 2021-03-13T09:56:38.016247+00:00 | 115 | false | ```\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n double sum = 0;\n for (int i = 0; i < nums.size(); i++) sum += nums[i];\n double diff = goal - sum;\n if (diff < 0) diff = (-1) * diff;\n int count = diff / limit;\n diff -= ((doub... | 1 | 0 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Python Greedy Solution Without using Loop | python-greedy-solution-without-using-loo-ecbs | \nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n s = sum(nums) \n if s == goal :\n retur | abhishek12800 | NORMAL | 2021-03-13T07:05:10.796016+00:00 | 2021-08-19T09:41:35.671696+00:00 | 99 | false | ```\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n s = sum(nums) \n if s == goal :\n return 0 \n val = abs(goal - s)\n if val <= limit :\n return 1 \n q = val // limit \n r = val % limit \n if r == 0 :... | 1 | 0 | ['Greedy', 'Python', 'Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | [JAVA] Simple to understand solution. | java-simple-to-understand-solution-by-an-29uv | \n public int minElements(int[] nums, int limit, int goal) {\n long sumOfArrayElements = 0;\n for (int i = 0; i < nums.length; i++) {\n | ankit341 | NORMAL | 2021-03-09T15:13:51.968875+00:00 | 2021-03-09T15:13:51.968922+00:00 | 72 | false | ```\n public int minElements(int[] nums, int limit, int goal) {\n long sumOfArrayElements = 0;\n for (int i = 0; i < nums.length; i++) {\n sumOfArrayElements += nums[i];\n }\n if (sumOfArrayElements == goal)\n return 0;\n\n long differenceOfGoalAndSum = Math.ab... | 1 | 0 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Python easy code with explanation And one line code | python-easy-code-with-explanation-and-on-knad | 1. Get target number by substracting from total sum of array to the goal\n2. Since target can be postive or negative \n3. Let take an example 10//3=3 and -10 | primeAK | NORMAL | 2021-03-07T07:53:31.603945+00:00 | 2021-03-07T10:58:35.723102+00:00 | 125 | false | **1. Get target number by substracting from total sum of array to the goal\n2. Since target can be postive or negative \n3. Let take an example 10//3=3 and -10//3=-4 in Python\n4. So take absolute of Target number\n5. Add the quotient to the answer\n6. If there is remainder then add 1 to the answer as remainder i... | 1 | 0 | ['Python'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | [Python3] 3 Lines O(N) | python3-3-lines-on-by-blackspinner-hxt2 | \nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n total = sum(nums)\n diff = abs(total - goal)\n | blackspinner | NORMAL | 2021-03-07T07:16:49.526678+00:00 | 2021-03-07T07:16:49.526718+00:00 | 40 | false | ```\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n total = sum(nums)\n diff = abs(total - goal)\n return 0 if diff == 0 else 1 if diff <= limit else diff // limit + 1 if diff % limit else diff // limit\n``` | 1 | 0 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | java 100% I hate math!! | java-100-i-hate-math-by-trustno1-dqre | ```\nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n long total = 0, diff = 0;\n for(int n : nums) total += n;\n | trustno1 | NORMAL | 2021-03-07T05:19:01.111654+00:00 | 2021-03-07T05:19:01.111702+00:00 | 108 | false | ```\nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n long total = 0, diff = 0;\n for(int n : nums) total += n;\n diff = Math.abs(goal - total);\n long x = diff % limit, y = diff / limit;\n return x == 0 ? (int) y : (int) (y + 1);\n }\n} | 1 | 1 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | python3 | python3-by-aniketrastogi-587h | ```\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n s=sum(nums)\n dr=goal-s\n return math.cei | aniketrastogi | NORMAL | 2021-03-07T04:58:02.100909+00:00 | 2021-03-07T04:58:02.100946+00:00 | 46 | false | ```\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n s=sum(nums)\n dr=goal-s\n return math.ceil(abs(dr/limit))\n\t\t | 1 | 0 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | easy JAVA solution 100%faster | easy-java-solution-100faster-by-smartcod-jjgi | ```\nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n long totalsum=0L;\n for(int i=0;i0 && remain>0){\n | smartcoder_06 | NORMAL | 2021-03-07T04:33:42.023279+00:00 | 2021-03-07T04:52:47.551469+00:00 | 125 | false | ```\nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n long totalsum=0L;\n for(int i=0;i<nums.length;i++){\n totalsum+=nums[i];\n }\n if(totalsum==goal){\n return 0;\n }\n long count=0L;\n long remain=Math.abs(totalsu... | 1 | 1 | ['Java'] | 1 |
minimum-elements-to-add-to-form-a-given-sum | Python 1-liner | python-1-liner-by-lokeshsk1-bi5z | python []\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n\n rem = goal - sum(nums)\n\n return ceil(a | lokeshsk1 | NORMAL | 2021-03-07T04:15:59.609493+00:00 | 2024-08-04T11:41:26.334292+00:00 | 119 | false | ```python []\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n\n rem = goal - sum(nums)\n\n return ceil(abs(rem)/limit)\n \n \n``` | 1 | 0 | ['Python', 'Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | esy c++ implementation | esy-c-implementation-by-frameboy_27-qo7h | \nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long int s=0;\n for(int i=0;i<nums.size();i++)\n | frameboy_27 | NORMAL | 2021-03-07T04:12:33.036971+00:00 | 2021-03-07T04:12:33.037020+00:00 | 197 | false | ```\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long int s=0;\n for(int i=0;i<nums.size();i++)\n s+=nums[i];\n long long int d=abs(s-goal);\n if(d%limit==0)\n return (int)(di/limit);\n return (int)((di/limit)+1)... | 1 | 0 | ['C', 'C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Confusing on a test case | confusing-on-a-test-case-by-timsonshi-id44 | An official test case is\n\n[2,5,5,-7,4]\n7\n464680098\n\n\nFirstly I\'m confusing why the goal could be much greater than len(nums) * limit, as from the descri | timsonshi | NORMAL | 2021-03-07T04:10:50.978247+00:00 | 2021-03-07T04:10:50.978275+00:00 | 90 | false | An official test case is\n```\n[2,5,5,-7,4]\n7\n464680098\n```\n\nFirstly I\'m confusing why the goal could be much greater than `len(nums) * limit`, as from the description `nums` shouldn\'t be extended. Put this question aside, as `goal` is obviously greater than `len(nums) * limit`, we should modify all the elements... | 1 | 0 | [] | 1 |
minimum-elements-to-add-to-form-a-given-sum | Simple math, C++ | simple-math-c-by-hc167-2hmd | \nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long sum = 0;\n for(int u : nums)\n s | hc167 | NORMAL | 2021-03-07T04:04:07.647180+00:00 | 2021-03-07T04:04:07.647218+00:00 | 65 | false | ```\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long long sum = 0;\n for(int u : nums)\n sum += u;\n\n sum = abs(goal-sum);\n \n if(sum%limit == 0)\n return sum/limit;\n else\n return (sum+limit)/l... | 1 | 0 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | c++ easy | c-easy-by-rakeshkr05091999-out9 | class Solution {\npublic:\n int minElements(vector& nums, int limit, int goal) {\n long int sum=0;\n for(int i=0;i<nums.size();i++)\n su | rakeshkr05091999 | NORMAL | 2021-03-07T04:01:59.693913+00:00 | 2021-03-07T04:01:59.693946+00:00 | 100 | false | class Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n long int sum=0;\n for(int i=0;i<nums.size();i++)\n sum+=nums[i];\n \n long int count=0;\n if(sum==goal)\n return 0;\n sum=abs(goal-sum);\n count=sum/limit... | 1 | 0 | [] | 0 |
minimum-elements-to-add-to-form-a-given-sum | solved! 2line😂 | solved-2line-by-azizbekeshpolatov-ukw5 | Code | AzizbekEshpolatov | NORMAL | 2025-03-27T09:53:45.399291+00:00 | 2025-03-27T09:53:45.399291+00:00 | 3 | false | # Code
```dart []
class Solution {
int minElements(List<int> nums, int limit, int goal) {
int sum = nums.reduce((a,b) => a+b);
return ((sum-goal).abs() / limit).ceil();
}
}
``` | 0 | 0 | ['Dart'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | 0 ms Beats 100.00% | 0-ms-beats-10000-by-funkeymunkey-5mii | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | funkeymunkey | NORMAL | 2025-03-25T11:15:17.960826+00:00 | 2025-03-25T11:15:17.960826+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | huỳnh Văn Đương code | huynh-van-duong-code-by-3qn5nki5o5-yuv0 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | 3QN5Nki5O5 | NORMAL | 2025-03-01T03:09:32.426472+00:00 | 2025-03-01T03:09:32.426472+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Easy solution | easy-solution-by-liew-li-2nhr | IntuitionApproachComplexity
Time complexity:O(N)
Space complexity:O(1)
Code | liew-li | NORMAL | 2025-02-09T04:29:53.992619+00:00 | 2025-02-09T04:29:53.992619+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
... | 0 | 0 | ['JavaScript'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | 785. Minimum Elements to Add to Form a Given Sum | 785-minimum-elements-to-add-to-form-a-gi-h71w | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-15T03:23:41.377147+00:00 | 2025-01-15T03:23:41.377147+00:00 | 7 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | [C++ Solution (Beats 100.00%)] Min Elements | Explained | c-solution-beats-10000-min-elements-expl-ufp2 | IntuitionApproachComplexity
Time complexity:
O(n)
Space complexity:
O(1)
Code | daniel_9650 | NORMAL | 2025-01-06T23:40:50.970083+00:00 | 2025-01-06T23:40:50.970083+00:00 | 7 | false | # 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) {
... | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Simple Java 0ms solution | simple-java-0ms-solution-by-bharani1729-gsdc | Complexity
Time complexity:O(N)
Space complexity:O(1)
Code | bharani1729 | NORMAL | 2025-01-06T03:05:24.967786+00:00 | 2025-01-06T03:05:24.967786+00:00 | 10 | false | # Complexity
- Time complexity:O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```java []
class Solution {
public int minElements(int[] nums, int limit, int goal) {
long sum = 0 ;
int n = nums.length;
... | 0 | 0 | ['Java'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Minimum Elements to Add to Form a Given Sum | minimum-elements-to-add-to-form-a-given-kr4gd | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Naeem_ABD | NORMAL | 2025-01-04T07:32:33.504042+00:00 | 2025-01-04T07:32:33.504042+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Go'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Simple iterative solution || c++ || beats 100% | simple-iterative-solution-c-beats-100-by-pjp3 | IntuitionApproachComplexity
Time complexity:O(n)
Space complexity:O(1)
Code | vikash_kumar_dsa2 | NORMAL | 2024-12-28T18:02:02.482778+00:00 | 2024-12-28T18:02:02.482778+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
... | 0 | 0 | ['Array', 'Greedy', 'C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | C++ easy solution | c-easy-solution-by-axard-8gg0 | Code | axard | NORMAL | 2024-12-27T10:13:30.954537+00:00 | 2024-12-27T10:13:30.954537+00:00 | 8 | false |
# Code
```cpp []
class Solution {
public:
int minElements(vector<int>& nums, int limit, int goal) {
long sum = 0;
for (auto n : nums) sum += n;
long d = abs(goal - sum);
int count = (d / limit) + (d % limit > 0);
return count;
}
};
``` | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Nice n EZ Python Solution :D | nice-n-ez-python-solution-d-by-heterohab-gyde | Complexity\n- Time complexity:\n O(n)\n\n- Space complexity:\nO(1)\n# Code\npython3 []\nclass Solution:\n def minElements(self, nums: list[int], limit: int, | Heterohabilis_114514 | NORMAL | 2024-11-30T01:34:31.052809+00:00 | 2024-11-30T01:34:31.052842+00:00 | 1 | false | # Complexity\n- Time complexity:\n $$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n# Code\n```python3 []\nclass Solution:\n def minElements(self, nums: list[int], limit: int, goal: int) -> int:\n return ceil(abs(goal-sum(nums))/limit)\n``` | 0 | 0 | ['Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Straightforward Greedy Algo | straightforward-greedy-algo-by-iitjsagar-phqe | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nCalculate the diff betw | iitjsagar | NORMAL | 2024-11-24T03:57:03.921412+00:00 | 2024-11-24T03:57:03.921434+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCalculate the diff between goal and current sum. Number of additional elements = diff/limit\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity... | 0 | 0 | ['Greedy', 'Python'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Find how much we need and divide that by our limit - O(n)time, O(1)space - 100% speed rank | find-how-much-we-need-and-divide-that-by-dugi | 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 | OSharpe001 | NORMAL | 2024-11-22T16:47:43.175169+00:00 | 2024-11-22T20:59:23.841847+00:00 | 2 | false | # 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.... | 0 | 0 | ['Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | beats 100% | beats-100-by-yagizerdem-eo9q | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | yagizerdem | NORMAL | 2024-11-12T17:22:59.141820+00:00 | 2024-11-12T17:22:59.141854+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['JavaScript'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Straightforward, 4 lines | straightforward-4-lines-by-belka-u6su | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | belka | NORMAL | 2024-11-04T18:54:41.028755+00:00 | 2024-11-04T18:54:41.028783+00:00 | 3 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Simple java solution 100% beats | simple-java-solution-100-beats-by-phoeni-5h1v | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | gladiator- | NORMAL | 2024-10-21T14:24:10.667805+00:00 | 2024-10-21T14:24:10.667836+00:00 | 15 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```java []\nclass Solution {\n public int minElements(int[] nums, int limit, int go... | 0 | 0 | ['Java'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Java | 4-liner | Beats %100 | java-4-liner-beats-100-by-jeshuakrc-smr2 | 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 | Jeshuakrc | NORMAL | 2024-10-15T04:37:05.028841+00:00 | 2024-10-15T04:37:05.028878+00:00 | 4 | false | # 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 harmle... | 0 | 0 | ['Java'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | 🟢🔴🟢 Beats 100.00%👏 3 Lines Solutions 🟢🔴🟢 | beats-10000-3-lines-solutions-by-develop-272s | \nclass Solution {\n int minElements(List<int> nums, int limit, int goal) {\n\n int total = nums.fold(0,(a,b)=> a+b);\n int add = goal - total;\n retu | developerSajib88 | NORMAL | 2024-10-11T11:56:08.118603+00:00 | 2024-10-11T11:56:08.118626+00:00 | 9 | false | ```\nclass Solution {\n int minElements(List<int> nums, int limit, int goal) {\n\n int total = nums.fold(0,(a,b)=> a+b);\n int add = goal - total;\n return (add.abs() / limit).ceil();\n \n }\n}\n``` | 0 | 0 | ['C', 'Python', 'C++', 'Java', 'JavaScript', 'C#', 'Dart'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | 4 Line Code | 4-line-code-by-vatan999-880i | Intuition\nThe goal is to determine the minimum number of elements we need to add or subtract to transform the sum of the array nums into the goal. We can adjus | vatan999 | NORMAL | 2024-10-08T13:55:56.433531+00:00 | 2024-10-08T13:55:56.433564+00:00 | 1 | false | # Intuition\nThe goal is to determine the minimum number of elements we need to add or subtract to transform the sum of the array `nums` into the `goal`. We can adjust the sum using values limited by a specific maximum (`limit`). The problem can be approached by first calculating the current sum and then figuring out h... | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | 2 lines - 76ms | 2-lines-76ms-by-8ataaxwvnn-33z9 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | 8AtaAXWVNN | NORMAL | 2024-10-01T02:17:25.320182+00:00 | 2024-10-01T02:17:25.320215+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['JavaScript'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Easy Java Solution | easy-java-solution-by-aloksharma_06-b406 | Code\njava []\nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n long sum = 0;\n for(int i=0;i<nums.length;i++){\n | aloksharma_06 | NORMAL | 2024-09-28T19:01:12.397611+00:00 | 2024-09-28T19:01:12.397646+00:00 | 2 | false | # Code\n```java []\nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n long sum = 0;\n for(int i=0;i<nums.length;i++){\n sum += nums[i];\n }\n long difference = Math.abs(sum-goal);\n if(difference == 0){\n return 0;\n }\n ... | 0 | 0 | ['Java'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Easy than expected - Java O(N)|O(1) | easy-than-expected-java-ono1-by-wangcai2-bpq8 | Intuition\n Describe your first thoughts on how to solve this problem. \nSimply follow the description, the only trick is Integer overflow, use Long for sum.\n\ | wangcai20 | NORMAL | 2024-09-25T20:38:43.218102+00:00 | 2024-09-25T20:38:43.218154+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimply follow the description, the only trick is `Integer` overflow, use `Long` for sum.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. ... | 0 | 0 | ['Java'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Easy than expected - Java | easy-than-expected-java-by-wangcai20-m7i9 | Intuition\n Describe your first thoughts on how to solve this problem. \nSimply follow the description. The only trick is Integer overflow, use Long for sum.\n\ | wangcai20 | NORMAL | 2024-09-25T20:35:43.622584+00:00 | 2024-09-25T20:35:43.622612+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimply follow the description. The only trick is `Integer` overflow, use `Long` for sum.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. ... | 0 | 0 | ['Java'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Simple ,Effective and Intuitive Approach to Calculate Minimum Steps in Array Problem | simple-effective-and-intuitive-approach-ptp8y | Intuition\n Describe your first thoughts on how to solve this problem. \n figure out how many elements of size limit you need to reach a goal\n\n# Approach\n De | priyanshumishragn1 | NORMAL | 2024-09-15T06:25:24.894754+00:00 | 2024-09-15T06:29:57.655994+00:00 | 2 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n figure out how many elements of size limit you need to reach a goal\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1)Find the Total Difference:\nFirst, calculate the difference between your goal and the sum of yo... | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | 2 liner || Simple maths || C++ | 2-liner-simple-maths-c-by-lotus18-y3fa | Code\n\nclass Solution \n{\npublic:\n int minElements(vector<int>& nums, int limit, int goal) \n {\n long long sum=accumulate(nums.begin(),nums.end | lotus18 | NORMAL | 2024-08-16T17:57:46.997028+00:00 | 2024-08-16T17:57:46.997049+00:00 | 1 | false | # Code\n```\nclass Solution \n{\npublic:\n int minElements(vector<int>& nums, int limit, int goal) \n {\n long long sum=accumulate(nums.begin(),nums.end(),(long long)0);\n return ceil((double)abs(goal-sum)/limit);\n }\n};\n``` | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Python3 Math O(1) | python3-math-o1-by-dhruvp16011-oa49 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | dhruvp16011 | NORMAL | 2024-07-24T01:13:29.987398+00:00 | 2024-07-24T01:13:29.987424+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Easy to understand | easy-to-understand-by-nksgbc12-5j2k | Code\n\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n \n long sum=0;\n for(int i=0; i<nums.siz | nksgbc12 | NORMAL | 2024-07-17T09:51:09.683276+00:00 | 2024-07-17T09:51:09.683312+00:00 | 3 | false | # Code\n```\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n \n long sum=0;\n for(int i=0; i<nums.size(); i++) {\n sum += nums[i];\n }\n\n long req = abs(goal - sum);\n int ans = req / limit;\n if(req % limit != 0) an... | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Beats 100%||O(1) TC and SC | beats-100o1-tc-and-sc-by-xbhinxv54-xfff | Intuition\n If sum of the nums is already equal to goal,no need to add anything so return 0\nElse if sum is less than goal we need to add some elements,the sum | xbhinxv54 | NORMAL | 2024-06-21T09:22:42.168194+00:00 | 2024-06-21T09:22:42.168229+00:00 | 15 | false | # Intuition\n<!-- If sum of the nums is already equal to goal,no need to add anything so return 0\nElse if sum is less than goal we need to add some elements,the sum of the elements to be added will be the difference between the goal and the sum of all elements in the current list. If this sum is less than the limit ju... | 0 | 0 | ['Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Python Medium | python-medium-by-lucasschnee-y570 | \nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n s = sum(nums)\n\n left = s - goal\n\n if lef | lucasschnee | NORMAL | 2024-06-16T14:35:05.466789+00:00 | 2024-06-16T14:35:05.466813+00:00 | 3 | false | ```\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n s = sum(nums)\n\n left = s - goal\n\n if left == 0:\n return 0\n\n\n left = abs(left)\n\n\n amount = left // limit\n\n left %= limit\n if left:\n amoun... | 0 | 0 | ['Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Easy C++ Soln || Simple subtraction || TC ->O(N) || SC->O(1) | easy-c-soln-simple-subtraction-tc-on-sc-8k6gs | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Xpider_7080 | NORMAL | 2024-06-14T04:59:25.387899+00:00 | 2024-06-14T04:59:25.387924+00:00 | 3 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Easy Greedy intuitive | easy-greedy-intuitive-by-afrid85-x12s | \n# Code\n\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n //int sum=0; \n long long sum=0; \n | afrid85 | NORMAL | 2024-06-05T05:28:26.917563+00:00 | 2024-06-05T05:28:26.917602+00:00 | 2 | false | \n# Code\n```\nclass Solution {\npublic:\n int minElements(vector<int>& nums, int limit, int goal) {\n //int sum=0; \n long long sum=0; \n for(int i=0;i<nums.size();i++){\n sum +=nums[i];\n }\n if(sum == goal)return 0; \n long long needed = goal-sum; \n ... | 0 | 0 | ['Greedy', 'C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | 😊Runtime 76 ms Beats 100.00% of users with Go | runtime-76-ms-beats-10000-of-users-with-b5sfv | Code\n\nfunc minElements(nums []int, limit int, goal int) int {\n\tvar sum int64 = 0\n\tfor _, num := range nums {\n\t\tsum += int64(num)\n\t}\n\n\tdiff := math | pvt2024 | NORMAL | 2024-05-25T02:23:58.971907+00:00 | 2024-05-25T02:23:58.971975+00:00 | 1 | false | # Code\n```\nfunc minElements(nums []int, limit int, goal int) int {\n\tvar sum int64 = 0\n\tfor _, num := range nums {\n\t\tsum += int64(num)\n\t}\n\n\tdiff := math.Abs(float64(goal) - float64(sum))\n\treturn int(math.Ceil(diff / float64(limit)))\n}\n``` | 0 | 0 | ['Go'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | C++ SOLUTION | c-solution-by-shantanuubasu-x01z | Approach\n Describe your approach to solving the problem. \n1. Find the sum of array.\n2. Calculate its absolute difference from the goal.\n3. Then return the c | shantanuubasu | NORMAL | 2024-05-13T12:58:55.866085+00:00 | 2024-05-13T12:58:55.866111+00:00 | 0 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\n1. Find the sum of array.\n2. Calculate its absolute difference from the goal.\n3. Then return the ceil of diff/limit.\n\nGitHub: [1785. Minimum Elements to Add to Form a Given Sum](https://github.com/Shantanuubasu/Leetcode/blob/main/Array/1785.%20Min... | 0 | 0 | ['Array', 'Greedy', 'C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | 2 liner || GREEDY | 2-liner-greedy-by-rastogimudit02-831q | Intuition\nFind diff between sum of array and goal.\nNow, in order to make both of them same, we need to +/-\nnumbers in array such that sum = goal.\nTo get min | coder_rastogi_21 | NORMAL | 2024-05-09T01:08:26.395161+00:00 | 2024-05-09T01:08:26.395183+00:00 | 2 | false | # Intuition\n`Find diff between sum of array and goal.`\n`Now, in order to make both of them same, we need to +/-`\n`numbers in array such that sum = goal.`\n`To get minimum steps,`\n`we keep on doing +/- limit to make sum = goal` \n`as early as possible.`\n\n# Complexity\n- Time complexity: $$O(n)$$ \n\n- Space comple... | 0 | 0 | ['Greedy', 'C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | ❇ minimum-elements-to-add👌 🏆O(N)❤️ Javascript🎯 Memory👀95.45%🕕 ++Explanation✍️ 🔴🔥 ✅ 👉 💪🙏 | minimum-elements-to-add-on-javascript-me-7g3u | Time Complexity: O(N)\nSpace Complexity: O(1)\n\n\nvar minElements = function (nums, limit, goal) {\n const sum = (function () {\n let sum = 0;\n | anurag-sindhu | NORMAL | 2024-04-25T02:29:53.123950+00:00 | 2024-04-25T02:29:53.123972+00:00 | 1 | false | Time Complexity: O(N)\nSpace Complexity: O(1)\n\n```\nvar minElements = function (nums, limit, goal) {\n const sum = (function () {\n let sum = 0;\n for (const iterator of nums) {\n sum += iterator;\n }\n return sum;\n })();\n let diff = 0;\n if ((sum < 0 && goal < 0) ... | 0 | 0 | ['JavaScript'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Swift | swift-by-ksmirnovnn-giqh | First calculating the sum of the array. Then calculate the absolute difference between the goal and the sum. This difference is the amount that needs to be adde | ksmirnovnn | NORMAL | 2024-04-21T11:17:11.728898+00:00 | 2024-04-21T11:17:11.728929+00:00 | 3 | false | First calculating the sum of the array. Then calculate the absolute difference between the goal and the sum. This difference is the amount that needs to be added to the array to reach the goal. Since each added element can have an absolute value of up to limit, the minimum number of elements needed is the difference di... | 0 | 0 | ['Swift'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Beats 100% Time Complexity | Java | Arithmetic Solution | | beats-100-time-complexity-java-arithmeti-8s5h | Intuition\n Describe your first thoughts on how to solve this problem. \nThe Intuition here is that we need to find how many times we need to use limit to get t | code_bandit | NORMAL | 2024-04-19T14:59:53.371922+00:00 | 2024-04-19T14:59:53.371949+00:00 | 42 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe Intuition here is that we need to find how many times we need to use limit to get to the difference of current array sum and the goal.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Calculate the array sum.\... | 0 | 0 | ['Java'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | scala oneliner | scala-oneliner-by-vititov-ggyb | \nobject Solution {\n def minElements(nums: Array[Int], limit: Int, goal: Int): Int =\n (((goal - nums.foldLeft(0L)(_ + _)).abs + limit - 1) / limit).toInt\ | vititov | NORMAL | 2024-04-11T17:52:34.409692+00:00 | 2024-04-11T17:52:34.409726+00:00 | 1 | false | ```\nobject Solution {\n def minElements(nums: Array[Int], limit: Int, goal: Int): Int =\n (((goal - nums.foldLeft(0L)(_ + _)).abs + limit - 1) / limit).toInt\n}\n``` | 0 | 0 | ['Scala'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | JS || Solution by Bharadwaj | js-solution-by-bharadwaj-by-manu-bharadw-0e0f | Code\n\nvar minElements = (nums, limit, goal) => Math.ceil(Math.abs(nums.reduce((prev, cur) => prev - cur, goal) / limit));\n | Manu-Bharadwaj-BN | NORMAL | 2024-03-01T05:59:37.555663+00:00 | 2024-03-01T05:59:37.555687+00:00 | 6 | false | # Code\n```\nvar minElements = (nums, limit, goal) => Math.ceil(Math.abs(nums.reduce((prev, cur) => prev - cur, goal) / limit));\n``` | 0 | 0 | ['JavaScript'] | 1 |
minimum-elements-to-add-to-form-a-given-sum | Ruby O(k) | ruby-ok-by-tmpasipanodya-rbo5 | Intuition\nNot sure why this is labelled as a medium.\n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity: O(k)\n | tmpasipanodya | NORMAL | 2024-02-29T20:43:01.226976+00:00 | 2024-02-29T20:43:01.227007+00:00 | 3 | false | # Intuition\nNot sure why this is labelled as a medium.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(k)\n\n- Space complexity: O(k)\n\n# Code\n```\n# @param {Integer[]} nums\n# @param {Integer} limit\n# @param {Integer} goal\n# @return {Integer}\ndef min_e... | 0 | 0 | ['Ruby'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Simple 3 Lines C++ | simple-3-lines-c-by-elcabalero-v2qc | Intuition + Approach\n Describe your first thoughts on how to solve this problem. \nThe intuition is to compare the initial sum of the array\'s elements s with | elcabalero | NORMAL | 2024-02-14T18:24:11.841698+00:00 | 2024-02-14T18:24:11.841728+00:00 | 4 | false | # Intuition + Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition is to compare the initial sum of the array\'s elements `s` with the target sum `goal`. Then, since we know how big (or small) can each integer be, we can compute the missing amount of integers to insert with a sim... | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | EASY to understand @beats 90-100% | easy-to-understand-beats-90-100-by-dash1-ktmd | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n first find total sum | dash123--- | NORMAL | 2024-02-10T18:58:10.957283+00:00 | 2024-02-10T18:58:10.957298+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n first find total sum and check that if diffrence between goal and sum is divisible by limit if it divisible means we required the number of additional number equal t... | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | 100% | 100-by-devziv-59vv | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | DevZiv | NORMAL | 2024-02-04T15:58:13.813865+00:00 | 2024-02-04T15:58:13.813895+00:00 | 9 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:o(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$... | 0 | 0 | ['Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Easy C++ Solution | easy-c-solution-by-nimbalkarbhagyesh6979-8hgt | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | nimbalkarbhagyesh6979 | NORMAL | 2024-01-31T07:35:57.308232+00:00 | 2024-01-31T07:35:57.308268+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Dart Solution | dart-solution-by-friendlygecko-p2zk | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Friendlygecko | NORMAL | 2024-01-17T21:21:28.165079+00:00 | 2024-01-17T21:21:28.165104+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Dart'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | RUNTIME 75% .... MEMOERY 100%,,,EASIEST C++ SOLUTION.. | runtime-75-memoery-100easiest-c-solution-n66n | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | DevRuhela | NORMAL | 2024-01-05T17:19:38.835921+00:00 | 2024-01-05T17:19:38.835968+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | python3 1 liner (beats 100%) | python3-1-liner-beats-100-by-0icy-e9rj | \n\n# Code\n\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n return ceil(abs(sum(nums)-goal)/limit)\n | 0icy | NORMAL | 2023-12-25T09:03:01.959395+00:00 | 2023-12-25T09:03:01.959427+00:00 | 8 | false | \n\n# Code\n```\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n return ceil(abs(sum(nums)-goal)/limit)\n``` | 0 | 0 | ['Python3'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | Java 4 lines | java-4-lines-by-fredo30400-7cca | \n\n# Code\n\nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n long sum = 0;\n for (int x:nums){sum+=x;}\n | fredo30400 | NORMAL | 2023-11-27T13:56:52.798005+00:00 | 2023-11-27T13:56:52.798033+00:00 | 66 | false | \n\n# Code\n```\nclass Solution {\n public int minElements(int[] nums, int limit, int goal) {\n long sum = 0;\n for (int x:nums){sum+=x;}\n long toFind = Math.abs(goal-sum);\n return (int)(toFind/limit) + (toFind % limit !=0 ? 1 : 0);\n }\n}\n``` | 0 | 0 | ['Java'] | 0 |
minimum-elements-to-add-to-form-a-given-sum | One line Python answer | one-line-python-answer-by-dhaxina-xva8 | Code\n\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n return abs(sum(nums)-goal)//limit if abs(sum(nums)-g | Dhaxina | NORMAL | 2023-11-21T11:46:24.418606+00:00 | 2023-11-21T11:46:24.418636+00:00 | 6 | false | # Code\n```\nclass Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:\n return abs(sum(nums)-goal)//limit if abs(sum(nums)-goal)%limit==0 else abs(sum(nums)-goal)//limit+1\n``` | 0 | 0 | ['Python', 'Python3'] | 0 |
smallest-subsequence-of-distinct-characters | [Java/C++/Python] Stack Solution O(N) | javacpython-stack-solution-on-by-lee215-gv7u | Explanation:\nFind the index of last occurrence for each character.\nUse a stack to keep the characters for result.\nLoop on each character in the input string | lee215 | NORMAL | 2019-06-09T04:03:55.772188+00:00 | 2019-11-29T15:30:57.397973+00:00 | 29,896 | false | ## **Explanation**:\nFind the index of last occurrence for each character.\nUse a `stack` to keep the characters for result.\nLoop on each character in the input string `S`,\nif the current character is smaller than the last character in the stack,\nand the last character exists in the following stream,\nwe can pop the... | 425 | 5 | [] | 42 |
smallest-subsequence-of-distinct-characters | C++ O(n), identical to #316 | c-on-identical-to-316-by-votrubac-kpte | The solution is exactly the same as for 316. Remove Duplicate Letters.\n\nFrom the input string, we are trying to greedily build a monotonically increasing resu | votrubac | NORMAL | 2019-06-09T04:01:40.320484+00:00 | 2019-06-12T16:57:41.342318+00:00 | 12,879 | false | The solution is exactly the same as for [316. Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters).\n\nFrom the input string, we are trying to greedily build a monotonically increasing result string. If the next character is smaller than the back of the result string, we remove larger chara... | 135 | 1 | [] | 15 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.