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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
n-repeated-element-in-size-2n-array | simple c++ solution using maps faster than 93.8% | simple-c-solution-using-maps-faster-than-xg1w | \n\nclass Solution {\npublic:\n int repeatedNTimes(vector& A) {\n unordered_map m;\n int ans;\n int n=A.size();\n for(int i=0; i1 | zephyr7047 | NORMAL | 2020-04-27T15:04:12.700300+00:00 | 2020-04-27T15:06:37.040413+00:00 | 356 | false | ```\n\n```class Solution {\npublic:\n int repeatedNTimes(vector<int>& A) {\n unordered_map<int ,int> m;\n int ans;\n int n=A.size();\n for(int i=0; i<n ; i++)\n {\n m[A[i]]++;\n if(m[A[i]]>1){\n //see that there are n+1 unique no so only one no ... | 3 | 0 | ['C', 'C++'] | 2 |
n-repeated-element-in-size-2n-array | Use count() | Python3 | Super Easy! | use-count-python3-super-easy-by-gsethi24-z1ma | \n for x in A: \n if A.count(x)>1: \n return x\n | gsethi2409 | NORMAL | 2020-03-25T18:41:00.708505+00:00 | 2020-03-25T18:41:00.708550+00:00 | 497 | false | ```\n for x in A: \n if A.count(x)>1: \n return x\n``` | 3 | 0 | ['Python', 'Python3'] | 1 |
n-repeated-element-in-size-2n-array | [Python] Very simple, 212ms (faster than 92.45%) | python-very-simple-212ms-faster-than-924-zavq | Intuition:\n\nIterate through all numbers and keep track of which ones have been seen.\nAs soon as we encounter a number that has been seen before, return that | j95io | NORMAL | 2020-03-09T18:29:49.981095+00:00 | 2020-03-17T12:28:09.956115+00:00 | 279 | false | **Intuition:**\n\nIterate through all numbers and keep track of which ones have been seen.\nAs soon as we encounter a number that has been seen before, return that number.\n\n**Code:**\n\n```\ndef repeatedNTimes(self, A: List[int]) -> int:\n\n\tseen = set()\n\tfor num in A:\n\t\tif num in seen:\n\t\t\treturn num\n\t\ts... | 3 | 0 | ['Python', 'Python3'] | 1 |
n-repeated-element-in-size-2n-array | Go 94% O(N) time O(1) space solution | go-94-on-time-o1-space-solution-by-tjuco-vvb2 | go\nfunc repeatedNTimes(A []int) int {\n for i := 0; i < len(A); i += 2 {\n if A[i] == A[i+1] {\n return A[i]\n }\n }\n if A[0 | tjucoder | NORMAL | 2020-01-29T08:26:05.154269+00:00 | 2020-01-29T08:27:30.813066+00:00 | 245 | false | ```go\nfunc repeatedNTimes(A []int) int {\n for i := 0; i < len(A); i += 2 {\n if A[i] == A[i+1] {\n return A[i]\n }\n }\n if A[0] == A[2] || A[0] == A[3] {\n return A[0]\n }\n return A[1]\n}\n``` | 3 | 0 | ['Go'] | 1 |
n-repeated-element-in-size-2n-array | From O(n) to O(1) Solutions in Rust | from-on-to-o1-solutions-in-rust-by-wfxr-7vcl | Solution 1: O(n) space, O(n) time\nrust\npub fn repeated_n_times(A: Vec<i32>) -> i32 {\n\tlet mut T = [false; 10000];\n\tfor a in A {\n\t\tT[a as usize] ^= true | wfxr | NORMAL | 2019-12-27T06:57:35.954299+00:00 | 2019-12-27T06:58:07.159554+00:00 | 136 | false | **Solution 1: O(n) space, O(n) time**\n```rust\npub fn repeated_n_times(A: Vec<i32>) -> i32 {\n\tlet mut T = [false; 10000];\n\tfor a in A {\n\t\tT[a as usize] ^= true;\n\t\tif !T[a as usize] {\n\t\t\treturn a;\n\t\t}\n\t}\n\tunreachable!()\n}\n```\n\n**Solution 2: O(1) space, O(n) time**\n```rust\npub fn repeated_n_ti... | 3 | 0 | [] | 2 |
n-repeated-element-in-size-2n-array | No hash/set/count/search. Simple 0ms Java solutions with no allocations (+ a 1-liner). | no-hashsetcountsearch-simple-0ms-java-so-ejws | Since there are so many of the repeated element, it is hard to go too far without a duplicate. There may be sections of the array that have large areas with no | flarbear | NORMAL | 2019-04-10T18:49:22.348806+00:00 | 2019-04-10T18:49:22.348848+00:00 | 666 | false | Since there are so many of the repeated element, it is hard to go too far without a duplicate. There may be sections of the array that have large areas with no duplicates, but that just means that the duplicated elements are even more concentrated in some other section of the array.\n\nAdjacent elements are highly lik... | 3 | 0 | [] | 2 |
n-repeated-element-in-size-2n-array | Java O(N) time, 0 space, 100%, pigeonhole principle | java-on-time-0-space-100-pigeonhole-prin-3f5g | \n\nclass Solution {\n public int repeatedNTimes(int[] A) {\n if(A[0] == A[A.length-1])\n return A[0];\n \n for(int i = 0; i | miklov | NORMAL | 2019-04-04T05:11:35.890514+00:00 | 2019-04-04T05:11:35.890558+00:00 | 670 | false | \n```\nclass Solution {\n public int repeatedNTimes(int[] A) {\n if(A[0] == A[A.length-1])\n return A[0];\n \n for(int i = 0; i < A.length-1; i++){\n if(i < A.length-2 && A[i] == A[i+2]){\n return A[i];\n }\n if(A[i] == A[i+1])\n ... | 3 | 0 | [] | 1 |
n-repeated-element-in-size-2n-array | java 4ms faster than 99.96% of Java solutions | java-4ms-faster-than-9996-of-java-soluti-bm4t | The key is that all the numbers are unique except the result. Simply, loop through the original numbers and keep adding numbers to a set, as soon as you see a r | codepower | NORMAL | 2019-01-23T09:35:40.480929+00:00 | 2019-01-23T09:35:40.481015+00:00 | 448 | false | The key is that all the numbers are unique except the result. Simply, loop through the original numbers and keep adding numbers to a set, as soon as you see a repeated number that\'s the result. It\'s an O(n) memory though\n```\npublic int repeatedNTimes(int[] A) {\n Set<Integer> uniqueNums = new HashSet<>();\n ... | 3 | 0 | [] | 0 |
n-repeated-element-in-size-2n-array | Intuitive Python O(1) Space O(N) Time | intuitive-python-o1-space-on-time-by-jle-nkdv | \nclass Solution:\n def repeatedNTimes(self, A):\n """\n :type A: List[int]\n :rtype: int\n """\n # check the first 4 for | jlepere2 | NORMAL | 2019-01-10T02:02:47.667880+00:00 | 2019-01-10T02:02:47.667922+00:00 | 819 | false | ```\nclass Solution:\n def repeatedNTimes(self, A):\n """\n :type A: List[int]\n :rtype: int\n """\n # check the first 4 for a duplicate\n for i in range(4):\n for j in range(i+1, 4):\n if A[i] == A[j]:\n return A[i]\n # no... | 3 | 0 | [] | 1 |
n-repeated-element-in-size-2n-array | [JavaScript] O(n) w/Explanation! | javascript-on-wexplanation-by-bundit-gt5u | Given the fact that there are N + 1 unique elements and only one of these elements is repeated N times, we know that there is only one repeated element and the | bundit | NORMAL | 2019-01-07T00:53:19.181907+00:00 | 2019-01-07T00:53:19.181955+00:00 | 552 | false | Given the fact that there are ```N + 1``` unique elements and only one of these elements is repeated ```N``` times, we know that there is only one repeated element and the rest are unique. \n1. We can use a set to store elements that we\'ve seen. This gives us O(1) lookup and O(1) insert.\n2. Once we find an element th... | 3 | 0 | [] | 1 |
n-repeated-element-in-size-2n-array | Python 1-liner | python-1-liner-by-cenkay-4mi9 | \nclass Solution:\n def repeatedNTimes(self, A):\n return collections.Counter(A).most_common(1)[0][0]\n | cenkay | NORMAL | 2018-12-23T04:04:20.124246+00:00 | 2018-12-23T04:04:20.124308+00:00 | 576 | false | ```\nclass Solution:\n def repeatedNTimes(self, A):\n return collections.Counter(A).most_common(1)[0][0]\n``` | 3 | 1 | [] | 0 |
n-repeated-element-in-size-2n-array | Easy solution for beginners. Beats 90%. | easy-solution-for-beginners-beats-90-by-6jej3 | 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 | Akshat_04 | NORMAL | 2024-08-02T08:27:25.308298+00:00 | 2024-08-02T08:27:25.308324+00:00 | 226 | 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)$$ --... | 2 | 0 | ['C++'] | 1 |
n-repeated-element-in-size-2n-array | JAVA Easy Solution | java-easy-solution-by-vaish_na_vi-gtya | Describe your first thoughts on how to solve this problem. \n\n\n\n\n# Complexity\n- Time complexity: 0ms\n\n\n- Space complexity: 44.72\n\n\n# Code\n\nclass | Vaish_na_vi | NORMAL | 2024-06-10T09:06:06.364949+00:00 | 2024-06-10T09:06:06.365001+00:00 | 255 | false | <!-- Describe your first thoughts on how to solve this problem. -->\n\n\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: 0ms\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: 44.72\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n... | 2 | 0 | ['Java'] | 0 |
n-repeated-element-in-size-2n-array | Beginners Friendly Solution 🚀🚀| Easy To Understand C++ Users | beginners-friendly-solution-easy-to-unde-1w4h | 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 | dhiraj_15 | NORMAL | 2024-02-13T18:51:23.675791+00:00 | 2024-02-13T18:51:23.675818+00:00 | 202 | 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 Log n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.... | 2 | 0 | ['Array', 'Sorting', 'C++'] | 0 |
n-repeated-element-in-size-2n-array | 1-liner counter ez | 1-liner-counter-ez-by-randomnpc-qyvj | Code\n\nfrom collections import Counter\nclass Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:\n return Counter(nums).most_common(1)[0][ | RandomNPC | NORMAL | 2023-10-25T04:10:54.385962+00:00 | 2023-10-25T04:10:54.385991+00:00 | 228 | false | # Code\n```\nfrom collections import Counter\nclass Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:\n return Counter(nums).most_common(1)[0][0]\n``` | 2 | 0 | ['Python', 'Python3'] | 1 |
n-repeated-element-in-size-2n-array | Very Easy Approach || Java || GeForceGroot | very-easy-approach-java-geforcegroot-by-ama7d | Intuition\nSort array and if current and next element found same then return that element.\n\n# Approach\nSort the array and find is nums[i]==nums[i+1] and then | GeForceGroot | NORMAL | 2023-09-12T06:19:34.230578+00:00 | 2023-09-12T06:19:34.230598+00:00 | 265 | false | # Intuition\nSort array and if current and next element found same then return that element.\n\n# Approach\nSort the array and find is nums[i]==nums[i+1] and then store nums[i] in and variable and break the loop. return the variable.\n# Complexity\n- Time complexity:\nnlog(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```... | 2 | 0 | ['Java'] | 0 |
n-repeated-element-in-size-2n-array | ✅C++ || Best Solution || Without Extra Space || -100% use of brain✅ | c-best-solution-without-extra-space-100-x1x6k | \n# Approach\nAppoach is very simple. As there is only one element that occured n times in (n*2) size array. That\'s why after sorting element will be around mi | shyamal122 | NORMAL | 2023-09-05T20:55:07.897321+00:00 | 2023-09-05T20:55:07.897354+00:00 | 140 | false | \n# Approach\nAppoach is very simple. As there is only one element that occured n times in (n*2) size array. That\'s why after sorting element will be around mid position or, left side of mid or, right side of mid. We compare curent value with surrounding value and return the value.\n\n# Complexity\n- Time complexity:\... | 2 | 0 | ['C++'] | 0 |
n-repeated-element-in-size-2n-array | Solution beats 99% in runtime and 93% in memory. Optimized way | solution-beats-99-in-runtime-and-93-in-m-bke7 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe unique number is half + 1 of the length of array. \nAnd one number is half of the l | muhammedsheheem | NORMAL | 2023-08-25T05:15:58.550744+00:00 | 2023-08-25T05:18:17.209462+00:00 | 301 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe unique number is half + 1 of the length of array. \nAnd one number is half of the length of array.\nWhich means the half of the array is unique and the rest is same number. So we just have to find the duplicate from the array.\n\nEg :... | 2 | 0 | ['JavaScript'] | 1 |
n-repeated-element-in-size-2n-array | Moore's Voting Algorithm | moores-voting-algorithm-by-chandravaibha-ta5m | Intuition\nMany so called O(1) solutions have been published but the thing is they are hard to think of during an interview. If the inteviewer allows extra spac | chandravaibhav65 | NORMAL | 2023-08-02T15:53:09.749041+00:00 | 2023-08-02T15:53:09.749064+00:00 | 30 | false | # Intuition\nMany so called O(1) solutions have been published but the thing is they are hard to think of during an interview. If the inteviewer allows extra space or N^2 time then the question is trivial. But to do this in O(N) time and O(1) space requires some extra thinking.\n\n# Approach\nMoore\'s voting algorithm ... | 2 | 0 | ['C++'] | 1 |
n-repeated-element-in-size-2n-array | Easiest solution with just one condition | easiest-solution-with-just-one-condition-nsju | 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 | anshul2702 | NORMAL | 2023-07-18T20:29:31.171324+00:00 | 2023-07-18T20:29:31.171345+00:00 | 20 | 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)$$ --... | 2 | 0 | ['C++'] | 0 |
n-repeated-element-in-size-2n-array | JAVA solution with HashSet 0ms very easy | java-solution-with-hashset-0ms-very-easy-zjot | 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 | nyutonov_sh | NORMAL | 2023-07-02T11:22:13.892861+00:00 | 2023-07-02T11:22:13.892879+00:00 | 166 | 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)$$ --... | 2 | 0 | ['Java'] | 2 |
n-repeated-element-in-size-2n-array | Simple JAVA Solution for beginners. 0ms. Beats 100%. | simple-java-solution-for-beginners-0ms-b-tw5w | 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 | sohaebAhmed | NORMAL | 2023-05-19T10:24:00.314183+00:00 | 2023-05-19T10:24:00.314226+00:00 | 412 | 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)$$ --... | 2 | 0 | ['Array', 'Hash Table', 'Java'] | 0 |
n-repeated-element-in-size-2n-array | Solution | solution-by-deleted_user-x3ty | C++ []\nclass Solution {\npublic:\n int repeatedNTimes(vector<int>& nums)\n {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n\n | deleted_user | NORMAL | 2023-05-16T12:40:12.887165+00:00 | 2023-05-16T13:35:49.322731+00:00 | 351 | false | ```C++ []\nclass Solution {\npublic:\n int repeatedNTimes(vector<int>& nums)\n {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n\n map<int, int> count;\n for(int i=0; i<nums.size()/2+2; i++)\n {\n if(count[nums[i]] == 1) return nums[i];\n count[nums[... | 2 | 0 | ['C++', 'Java', 'Python3'] | 0 |
n-repeated-element-in-size-2n-array | ✌✌HashSet Solution||Easy | hashset-solutioneasy-by-tamosakatwa-289j | 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 | tamosakatwa | NORMAL | 2023-03-19T03:35:10.872112+00:00 | 2023-03-19T03:35:10.872143+00:00 | 282 | 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)$$ --... | 2 | 0 | ['Java'] | 1 |
n-repeated-element-in-size-2n-array | C++ || easy || Explained ||Map || ✅ | c-easy-explained-map-by-tridibdalui04-09vu | Store Frequencies of all digit in a map\n2. itarate over the map if the freq is >= size/2 then return that\n\n\nclass Solution {\npublic:\n int repeatedNTime | tridibdalui04 | NORMAL | 2022-10-20T13:16:12.063559+00:00 | 2022-10-20T13:16:12.063599+00:00 | 1,272 | false | 1. Store Frequencies of all digit in a map\n2. itarate over the map if the freq is >= size/2 then return that\n\n```\nclass Solution {\npublic:\n int repeatedNTimes(vector<int>& a) {\n int n=a.size();\n unordered_map<int,int>mp;\n for(int i=0;i<n;i++)\n mp[a[i]]++;\n for(auto i... | 2 | 0 | ['C'] | 0 |
n-repeated-element-in-size-2n-array | Very Easy Javascript Solution faster than 90%!!!! | very-easy-javascript-solution-faster-tha-ik4b | \n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar repeatedNTimes = function(a) {\n let d = []\n for(let i of a){\n if(d.includes(i)){ | harsh_sutaria_25 | NORMAL | 2022-09-30T05:42:11.064902+00:00 | 2022-09-30T05:42:11.064927+00:00 | 709 | false | ```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar repeatedNTimes = function(a) {\n let d = []\n for(let i of a){\n if(d.includes(i)){\n return i \n }else{\n d.push(i)\n }\n }\n \n \n};\n``` | 2 | 0 | ['JavaScript'] | 0 |
n-repeated-element-in-size-2n-array | Java Solution. | java-solution-by-harsh6645-d5k1 | class Solution {\n public int repeatedNTimes(int[] nums) {\n\t\n Arrays.sort(nums);\n for(int i = 0 ; i<nums.length-1; i++){\n if(nu | Harsh6645 | NORMAL | 2022-09-25T06:34:41.996811+00:00 | 2022-09-25T06:34:41.996853+00:00 | 686 | false | class Solution {\n public int repeatedNTimes(int[] nums) {\n\t\n Arrays.sort(nums);\n for(int i = 0 ; i<nums.length-1; i++){\n if(nums[i] == nums[i+1]){\n return nums[i];\n } \n }\n return nums[nums.length-1];\n }\n} | 2 | 0 | ['Java'] | 0 |
n-repeated-element-in-size-2n-array | Java 0ms, 100% fast, pigeon hole | java-0ms-100-fast-pigeon-hole-by-dmproni-85zg | In some bucket of every 3 numbers there should be a repeated num by definition of a problem, so we need to compare only every 3 numbers:\n\nclass Solution {\n | dmproni | NORMAL | 2022-09-20T17:11:38.634392+00:00 | 2022-09-20T17:11:38.634438+00:00 | 340 | false | In some bucket of every 3 numbers there should be a repeated num by definition of a problem, so we need to compare only every 3 numbers:\n```\nclass Solution {\n public int repeatedNTimes(int[] nums) {\n for (int i = 0; i < nums.length - 3; i += 3) {\n if (nums[i] == nums[i + 1] || nums[i] == nums[... | 2 | 0 | [] | 0 |
n-repeated-element-in-size-2n-array | easy solution | easy-solution-by-mohit_gusain-4dz4 | \nclass Solution {\npublic:\nint repeatedNTimes(vector<int>& nums) {\nsort(nums.begin(),nums.end());\nfor(int i=0;i<nums.size();i++)\n{\nif(nums[i]==nums[i+1])/ | Mohit_gusain | NORMAL | 2022-05-19T17:16:07.576302+00:00 | 2022-05-20T07:26:32.258390+00:00 | 142 | false | ```\nclass Solution {\npublic:\nint repeatedNTimes(vector<int>& nums) {\nsort(nums.begin(),nums.end());\nfor(int i=0;i<nums.size();i++)\n{\nif(nums[i]==nums[i+1])//all element are distincct and only one element is repeating\n{\nreturn nums[i];\n}\n}\nreturn 0;\n}\n};\n``` | 2 | 0 | ['C'] | 0 |
n-repeated-element-in-size-2n-array | C++ | 2 Approaches | O(n) Run Time. | c-2-approaches-on-run-time-by-pankajtanw-0hkb | For a detailed explanation - https://www.pankajtanwar.in/code/n-repeated-element-in-size-2n-array \n\nFirst Appraoch -\n\n\nclass Solution {\npublic:\n int r | pankajtanwar | NORMAL | 2021-10-06T17:06:07.176468+00:00 | 2021-10-06T17:06:07.176547+00:00 | 179 | false | * For a detailed explanation - https://www.pankajtanwar.in/code/n-repeated-element-in-size-2n-array \n\n**First Appraoch** -\n\n```\nclass Solution {\npublic:\n int repeatedNTimes(vector<int>& nums) {\n map<int,int> list;\n \n for(int num: nums) {\n list[num]++;\n }\n \n... | 2 | 0 | ['C'] | 0 |
n-repeated-element-in-size-2n-array | Python: faster than 88%, less memory than 94% | python-faster-than-88-less-memory-than-9-e4ef | \nclass Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:\n for tup in enumerate(nums):\n if tup[1] in nums[tup[0]+1:]:\n | travanj05 | NORMAL | 2021-09-23T17:51:26.479501+00:00 | 2021-09-23T17:51:26.479539+00:00 | 58 | false | ```\nclass Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:\n for tup in enumerate(nums):\n if tup[1] in nums[tup[0]+1:]:\n return tup[1]\n ```\n\t\t | 2 | 0 | [] | 0 |
n-repeated-element-in-size-2n-array | JavaScript Solution using hashmap - beats 97.78% | javascript-solution-using-hashmap-beats-egifi | Using hashmap\n\n\n\nvar repeatedNTimes = function(nums) {\n let map = {};\n for (let i = 0; i < nums.length; i++) {\n if(!map[nums[i]]) {\n | cchukwuka | NORMAL | 2021-08-10T08:50:20.192329+00:00 | 2021-08-10T09:07:36.801375+00:00 | 213 | false | Using hashmap\n\n```\n\nvar repeatedNTimes = function(nums) {\n let map = {};\n for (let i = 0; i < nums.length; i++) {\n if(!map[nums[i]]) {\n const element = nums[i];\n map[element] = true;\n } else {\n return nums[i];\n }\n }\n};\n\n```\n | 2 | 0 | ['JavaScript'] | 0 |
n-repeated-element-in-size-2n-array | Java | simple 1-pass solution(100%) | O(n) time O(1) space | java-simple-1-pass-solution100-on-time-o-13q0 | Since, the half of the array contains duplicate elements, in most on the test cases at least two subsequent numbers will be same and checking nums[i] == nums[i- | kaushaldokania | NORMAL | 2021-07-29T18:17:27.293469+00:00 | 2021-07-29T18:17:27.293533+00:00 | 124 | false | Since, the half of the array contains duplicate elements, in most on the test cases at least two subsequent numbers will be same and checking `nums[i] == nums[i-1]` will do.\n\nBut, in worst case, when the duplicates are evenly distributed like [1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0], we can compare last and 2nd last ele... | 2 | 1 | ['Java'] | 0 |
n-repeated-element-in-size-2n-array | Java O(1), no use extra space, beats 100% solution | java-o1-no-use-extra-space-beats-100-sol-mx1g | java\n// AC:\n// Runtime: 0 ms, faster than 100.00% of Java online submissions for N-Repeated Element in Size 2N Array.\n// Memory Usage: 39.8 MB, less than 57. | ly2015cntj | NORMAL | 2021-05-14T11:48:16.930424+00:00 | 2021-05-14T11:50:35.202527+00:00 | 252 | false | ```java\n// AC:\n// Runtime: 0 ms, faster than 100.00% of Java online submissions for N-Repeated Element in Size 2N Array.\n// Memory Usage: 39.8 MB, less than 57.40% of Java online submissions for N-Repeated Element in Size 2N Array.\n// \n// \u601D\u8DEF\uFF1A\u8003\u8651\u4E0D\u4F7F\u7528 O(n) \u7A7A\u95F4\u7684\u50... | 2 | 0 | ['Java'] | 0 |
n-repeated-element-in-size-2n-array | python | faster than 97.20% | python-faster-than-9720-by-prachijpatel-vv3l | \nclass Solution:\n def repeatedNTimes(self, A: List[int]) -> int:\n d = {}\n for i in A:\n if i not in d:\n d[i] = 1 | prachijpatel | NORMAL | 2021-04-29T11:40:22.376821+00:00 | 2021-05-11T03:33:25.643607+00:00 | 192 | false | ```\nclass Solution:\n def repeatedNTimes(self, A: List[int]) -> int:\n d = {}\n for i in A:\n if i not in d:\n d[i] = 1\n else:\n return i\n``` | 2 | 0 | ['Python', 'Python3'] | 2 |
n-repeated-element-in-size-2n-array | Javascript 99% speed one-liner | javascript-99-speed-one-liner-by-saynn-rcle | \n/**\n * @param {number[]} A\n * @return {number}\n */\nvar repeatedNTimes = function(A) {\n return A.find(a => A.filter(n => n === a).length > 1)\n};\n | saynn | NORMAL | 2021-03-21T12:40:58.963073+00:00 | 2021-03-21T12:40:58.963115+00:00 | 140 | false | ```\n/**\n * @param {number[]} A\n * @return {number}\n */\nvar repeatedNTimes = function(A) {\n return A.find(a => A.filter(n => n === a).length > 1)\n};\n``` | 2 | 0 | ['JavaScript'] | 0 |
n-repeated-element-in-size-2n-array | Java solution - O(n) time O(1) space | java-solution-on-time-o1-space-by-akiram-ryjm | \nclass Solution {\n public int repeatedNTimes(int[] A) {\n int n = A.length;\n for (int i = 0; i < n; i++) {\n int j = (i + 1) % n; | akiramonster | NORMAL | 2021-03-02T04:51:25.167932+00:00 | 2021-03-02T04:51:55.078149+00:00 | 82 | false | ```\nclass Solution {\n public int repeatedNTimes(int[] A) {\n int n = A.length;\n for (int i = 0; i < n; i++) {\n int j = (i + 1) % n;\n int k = (j + 1) % n;\n if (A[i] == A[j] || A[i] == A[k]) return A[i];\n if (A[j] == A[k]) return A[j];\n }\n ... | 2 | 0 | [] | 0 |
n-repeated-element-in-size-2n-array | Easy to understand || Two approach || C++ | easy-to-understand-two-approach-c-by-cod-ctn7 | 1)Map Based approach\n\n//Because Size is 2N and (N+1) elements are distinct\n//exactly one element is repeating N times\nclass Solution {\npublic:\n int re | code1511 | NORMAL | 2020-12-13T14:26:24.820278+00:00 | 2020-12-13T14:39:48.075107+00:00 | 159 | false | **1)Map Based approach**\n```\n//Because Size is 2N and (N+1) elements are distinct\n//exactly one element is repeating N times\nclass Solution {\npublic:\n int repeatedNTimes(vector<int>& A) {\n unordered_map<int,int>u;\n for(int i=0;i<A.size();i++){\n u[A[i]]++;\n }\n int n=... | 2 | 0 | ['C', 'C++'] | 0 |
n-repeated-element-in-size-2n-array | Python Beats 97% | python-beats-97-by-ikm98-h194 | \n def repeatedNTimes(self, A: List[int]) -> int:\n \n counts = [0]*10001\n \n for val in A:\n if counts[val] == 1:\n | IKM98 | NORMAL | 2020-11-28T20:21:41.239843+00:00 | 2020-11-28T20:21:41.239872+00:00 | 218 | false | ```\n def repeatedNTimes(self, A: List[int]) -> int:\n \n counts = [0]*10001\n \n for val in A:\n if counts[val] == 1:\n return val\n counts[val] += 1\n``` | 2 | 0 | ['Counting Sort', 'Python', 'Python3'] | 1 |
n-repeated-element-in-size-2n-array | Clean JavaScript Solution | clean-javascript-solution-by-shimphillip-ebjb | \n// time O(n log n) space O(1)\nvar repeatedNTimes = function(A) {\n A.sort((a, b) => a - b)\n \n for(let i=0; i<A.length; i++) {\n if(A[i] === | shimphillip | NORMAL | 2020-11-03T03:30:51.666760+00:00 | 2020-11-30T21:45:59.764837+00:00 | 219 | false | ```\n// time O(n log n) space O(1)\nvar repeatedNTimes = function(A) {\n A.sort((a, b) => a - b)\n \n for(let i=0; i<A.length; i++) {\n if(A[i] === A[i+1]) {\n return A[i]\n }\n }\n};\n\n// time O(n) space O(n)\nvar repeatedNTimes = function(A) {\n const map = {}\n \n for(c... | 2 | 0 | ['JavaScript'] | 0 |
n-repeated-element-in-size-2n-array | CPP | Faster than 100% | Easy | cpp-faster-than-100-easy-by-pranjalb-fhpz | A very simple approach using arrays.\nSince the maximum size of the vector is 10000, and 0 < A[i] < 10000.\n\nWe use the indexes as the count of the number in t | pranjalb | NORMAL | 2020-08-29T08:34:47.738370+00:00 | 2020-08-29T08:34:47.738417+00:00 | 275 | false | A very simple approach using arrays.\nSince the maximum size of the vector is 10000, and 0 < A[i] < 10000.\n\nWe use the indexes as the count of the number in the array.\n\nThen we check is the Arr[i] is greater than 0 and is equal to the half of the size of the vector, if yes, we return the value.\n\n```\n\tConsider t... | 2 | 0 | ['C', 'C++'] | 0 |
n-repeated-element-in-size-2n-array | Java shortest solution and without HashMap | java-shortest-solution-and-without-hashm-egi4 | If all elements but one are unique, just order the array and find the repeated value.\n\n\nclass Solution {\n public int repeatedNTimes(int[] A) {\n A | kedakai | NORMAL | 2020-06-06T15:56:33.305525+00:00 | 2020-06-06T15:56:33.305553+00:00 | 52 | false | If all elements but one are unique, just order the array and find the repeated value.\n\n```\nclass Solution {\n public int repeatedNTimes(int[] A) {\n Arrays.sort(A);\n \n for(int i = 0; i < A.length; ++i) {\n if(A[i] == A[i+1]) {\n return A[i];\n }\n ... | 2 | 0 | [] | 0 |
n-repeated-element-in-size-2n-array | Simple JS Solution: faster than 100% | simple-js-solution-faster-than-100-by-hb-x4r1 | \n/**\n * @param {number[]} A\n * @return {number}\n */\nvar repeatedNTimes = function(A) {\n let m = new Map();\n for (let x of A) {\n if (!m.has( | hbjorbj | NORMAL | 2020-03-29T23:06:13.764727+00:00 | 2020-03-29T23:06:13.764761+00:00 | 253 | false | ```\n/**\n * @param {number[]} A\n * @return {number}\n */\nvar repeatedNTimes = function(A) {\n let m = new Map();\n for (let x of A) {\n if (!m.has(x)) m.set(x,1);\n else return x;\n }\n};\n``` | 2 | 0 | ['JavaScript'] | 0 |
n-repeated-element-in-size-2n-array | python, explained | python-explained-by-rmoskalenko-rs71 | The questions is basically asking to find a non-unique value. There are many ways to do it, but how to decide which one works best?\n\nFrom the performance poin | rmoskalenko | NORMAL | 2020-03-22T01:05:32.292589+00:00 | 2020-03-22T01:05:32.292631+00:00 | 198 | false | The questions is basically asking to find a non-unique value. There are many ways to do it, but how to decide which one works best?\n\nFrom the performance point of view, you can use https://wiki.python.org/moin/TimeComplexity as a reference. \n\nSo for example, if we try something like:\n\n- Let\'s sort the values ...... | 2 | 0 | [] | 0 |
n-repeated-element-in-size-2n-array | Java novel O(n) time and O(1) space solution, very easy to follow | java-novel-on-time-and-o1-space-solution-2pc9 | \nclass Solution {\n public int repeatedNTimes(int[] A) {\n int majority = 0;\n int vote = 1;\n for(int i=1; i<A.length-1; i++) { //tr | tgaurav10 | NORMAL | 2020-02-09T11:41:23.482877+00:00 | 2020-02-09T12:08:24.528564+00:00 | 144 | false | ```\nclass Solution {\n public int repeatedNTimes(int[] A) {\n int majority = 0;\n int vote = 1;\n for(int i=1; i<A.length-1; i++) { //try to find the majority, note that we\'re ignoring the last element\n\t\t// so that we can get a majority (more than 50%)\n if(A[majority] == A[i])... | 2 | 0 | [] | 1 |
n-repeated-element-in-size-2n-array | Java solution using set beats 100% runtime and memory | java-solution-using-set-beats-100-runtim-4xwt | \n//we only need find the number which has count not equal to one\n//so when we add number into set, if it is already there, set.add(number) will return false\n | tigerforrest | NORMAL | 2019-12-25T02:17:59.824949+00:00 | 2019-12-25T02:17:59.825033+00:00 | 94 | false | ```\n//we only need find the number which has count not equal to one\n//so when we add number into set, if it is already there, set.add(number) will return false\nclass Solution {\n public int repeatedNTimes(int[] A) {\n Set<Integer> set = new HashSet<>(); \n for(int a: A){\n if(set.a... | 2 | 0 | [] | 0 |
n-repeated-element-in-size-2n-array | Java 0ms beats 100% memory | java-0ms-beats-100-memory-by-gaofan104-bidy | \nclass Solution {\n public int repeatedNTimes(int[] A) {\n for (int i=0; i<A.length-2; i++){\n // there must exist two repeated numbers wh | gaofan104 | NORMAL | 2019-09-20T12:31:15.901969+00:00 | 2019-09-20T12:31:15.902020+00:00 | 113 | false | ```\nclass Solution {\n public int repeatedNTimes(int[] A) {\n for (int i=0; i<A.length-2; i++){\n // there must exist two repeated numbers who are separated by at most 1 unique number\n if (A[i] == A[i+1] || A[i] == A[i+2])\n return A[i];\n }\n return A[A.le... | 2 | 0 | [] | 0 |
n-repeated-element-in-size-2n-array | JAVA 0ms 100.0% | java-0ms-1000-by-voidcake-s69j | \n public int repeatedNTimes(int[] A) {\n List list = new ArrayList();\n for(int n:A){\n if(list.contains(n))\n retur | voidcake | NORMAL | 2019-09-20T02:10:44.201807+00:00 | 2019-09-20T02:10:44.201854+00:00 | 313 | false | ```\n public int repeatedNTimes(int[] A) {\n List list = new ArrayList();\n for(int n:A){\n if(list.contains(n))\n return n;\n list.add(n);\n }\n return -1;\n }\n``` | 2 | 0 | ['Java'] | 0 |
n-repeated-element-in-size-2n-array | JAVA too fast solution O(n/2) :), constant memory | java-too-fast-solution-on2-constant-memo-zxke | IDEA: No three elements can have unique values except when array size is 4.\n\n```\nclass Solution {\n public int repeatedNTimes(int[] A) {\n int a = | rostau3 | NORMAL | 2019-06-15T07:41:20.386810+00:00 | 2019-06-15T07:41:20.386865+00:00 | 193 | false | IDEA: No three elements can have unique values except when array size is 4.\n\n```\nclass Solution {\n public int repeatedNTimes(int[] A) {\n int a = A[0];\n int b = A[1];\n int c = A[2];\n int i = 3;\n if (A.length == 4 && A[0] == A[3])\n return A[0];\n \n ... | 2 | 0 | [] | 1 |
n-repeated-element-in-size-2n-array | Java 1 line !! | java-1-line-by-stachi-ariw | ```\n public int repeatedNTimes(int[] A) {\n Set set = new HashSet<>();\n\n for(int n : A) if(!set.add(n)) return n;\n\n throw null;\n | stachi | NORMAL | 2019-06-03T19:21:36.461677+00:00 | 2019-06-03T19:22:17.870526+00:00 | 157 | false | ```\n public int repeatedNTimes(int[] A) {\n Set<Integer> set = new HashSet<>();\n\n for(int n : A) if(!set.add(n)) return n;\n\n throw null;\n }\n | 2 | 0 | [] | 0 |
n-repeated-element-in-size-2n-array | Python Solution Faster than 96.11% | python-solution-faster-than-9611-by-neoh-ppp1 | \nclass Solution:\n def repeatedNTimes(self, A: List[int]) -> int:\n lst = []\n for i in range(len(A)):\n if A[i] not in lst:\n | neoh0030 | NORMAL | 2019-06-02T09:16:49.213571+00:00 | 2019-06-02T09:16:49.213636+00:00 | 155 | false | ```\nclass Solution:\n def repeatedNTimes(self, A: List[int]) -> int:\n lst = []\n for i in range(len(A)):\n if A[i] not in lst:\n lst.append(A[i])\n else:\n return(A[i])\n``` | 2 | 0 | [] | 0 |
n-repeated-element-in-size-2n-array | Java - 0ms - 100% - Very Straightforward. Use an array to act as collision | java-0ms-100-very-straightforward-use-an-avx4 | \nclass Solution {\n public int repeatedNTimes(int[] A) {\n boolean[] numbers = new boolean[10000];\n\t\tfor (int i = 0; i < A.length; i++) {\n\t\t\ti | anthonychin | NORMAL | 2019-04-11T21:00:05.875154+00:00 | 2019-04-11T21:00:05.875229+00:00 | 235 | false | ```\nclass Solution {\n public int repeatedNTimes(int[] A) {\n boolean[] numbers = new boolean[10000];\n\t\tfor (int i = 0; i < A.length; i++) {\n\t\t\tif (numbers[A[i]] == true) {\n\t\t\t\treturn A[i];\n\t\t\t} else {\n\t\t\t\tnumbers[A[i]] = true;\n\t\t\t}\n }\n return -1; \n }\n}\n``` | 2 | 0 | [] | 2 |
n-repeated-element-in-size-2n-array | [Python] Using pandas can do it very fast but I just cant import the module | python-using-pandas-can-do-it-very-fast-gczjc | \'\'\'\nclass Solution:\n \n def repeatedNTimes(self, A: List[int]) -> int:\n import pandas as pd\n lb = {\'values\': A}\n a= pd.Data | huanzhen | NORMAL | 2019-03-30T05:44:42.622812+00:00 | 2019-03-30T05:44:42.622857+00:00 | 1,370 | false | \'\'\'\nclass Solution:\n \n def repeatedNTimes(self, A: List[int]) -> int:\n import pandas as pd\n lb = {\'values\': A}\n a= pd.DataFrame(lb)\n \n return(a[\'values\'].value_counts().idxmax())\n\'\'\'\nTraceback:\nModuleNotFoundError: No module named \'pandas\'\nLine 4 in repea... | 2 | 0 | [] | 1 |
n-repeated-element-in-size-2n-array | C# code | c-code-by-fadi17-0hzs | \npublic int RepeatedNTimes(int[] A) {\n var set = new HashSet<int>();\n foreach(int x in A)\n {\n if(set.Contains(x))\n | fadi17 | NORMAL | 2019-03-30T03:24:51.497450+00:00 | 2019-03-30T03:24:51.497489+00:00 | 261 | false | ````\npublic int RepeatedNTimes(int[] A) {\n var set = new HashSet<int>();\n foreach(int x in A)\n {\n if(set.Contains(x))\n return x;\n else\n {\n set.Add(x);\n }\n }\n \n return -1;\n }\n```` | 2 | 0 | [] | 2 |
minimum-amount-of-time-to-collect-garbage | [Java/C++/Python] Explanation with Observations | javacpython-explanation-with-observation-macz | Intuition\nObservation 1:\n"While one truck is driving or picking up garbage, the other two trucks cannot do anything."\nWe can simply sum up the total running | lee215 | NORMAL | 2022-08-28T04:01:37.770501+00:00 | 2022-08-28T04:01:37.770532+00:00 | 14,984 | false | # **Intuition**\nObservation 1:\n"While one truck is driving or picking up garbage, the other two trucks cannot do anything."\nWe can simply sum up the total running time for each truck,\nthey don\'t affect each other.\n\n\nObservation 2:\n"Picking up one unit of any type of garbage takes 1 minute."\nWe don\'t care how... | 179 | 2 | ['C', 'Python', 'Java'] | 26 |
minimum-amount-of-time-to-collect-garbage | ✅✅✅ Simple sum - O(N) time & O(1) space | simple-sum-on-time-o1-space-by-kreakemp-fatv | Up Vote if you like the solution \n\n1. Count all the garbage size irrespective of type - as each garbage is taking 1min\n2. Keep tracking last g, p, m visited | kreakEmp | NORMAL | 2022-08-28T04:02:49.335354+00:00 | 2023-11-20T21:41:34.415269+00:00 | 5,670 | false | <b> Up Vote if you like the solution </b>\n\n1. Count all the garbage size irrespective of type - as each garbage is taking 1min\n2. Keep tracking last g, p, m visited house - as we do not need to move further. Here we are tracking sum up to last occurance and not the index.\n\n### C++\n```\n int garbageCollection(v... | 76 | 1 | ['C++', 'Java'] | 8 |
minimum-amount-of-time-to-collect-garbage | 【Video】Give me 10 minutes - Beats 98% - How we think about a solution | video-give-me-10-minutes-beats-98-how-we-xofw | Intuition\nIterate through from the last index.\n\n---\n\n# Solution Video\n\nhttps://youtu.be/GZWR5cWZ3pw\n\n\u25A0 Timeline\n0:05 Talk about time to pick up a | niits | NORMAL | 2023-11-20T05:28:59.012663+00:00 | 2023-11-21T08:53:16.725742+00:00 | 3,884 | false | # Intuition\nIterate through from the last index.\n\n---\n\n# Solution Video\n\nhttps://youtu.be/GZWR5cWZ3pw\n\n\u25A0 Timeline\n`0:05` Talk about time to pick up all garbages \n`1:44` Talk about time to travel to the next house\n`5:37` Demonstrate how it works\n`8:00` Coding\n`11:12` Time Complexity and Space Complexi... | 53 | 0 | ['C++', 'Java', 'Python3', 'JavaScript'] | 5 |
minimum-amount-of-time-to-collect-garbage | find last index, java | find-last-index-java-by-clasiqh-em3o | Solution:\n for every character add 1 to your sum for pickup time.\n find the last index of each type of garbage, use prefix sum to find travel time till that i | clasiqh | NORMAL | 2022-08-28T04:00:28.796050+00:00 | 2022-08-30T08:58:24.810044+00:00 | 2,502 | false | **Solution:**\n* for every character add 1 to your sum for pickup time.\n* find the last index of each type of garbage, use prefix sum to find travel time till that index.\n\n**Code:**\n\n public int garbageCollection(String[] gar, int[] travel) {\n int p=0, m=0, g=0, sum=0;\n\n for(int i=0; i<gar.leng... | 43 | 5 | ['Prefix Sum', 'Java'] | 5 |
minimum-amount-of-time-to-collect-garbage | 🚀 Easy Iterative Approach || Explained Intuition🚀 | easy-iterative-approach-explained-intuit-kttb | Problem Description\n\nGiven an array garbage representing the types of garbage at each house (M for metal, P for paper, G for glass), and an array travel repre | MohamedMamdouh20 | NORMAL | 2023-11-20T02:29:36.800858+00:00 | 2023-11-20T04:14:39.950118+00:00 | 6,498 | false | # Problem Description\n\nGiven an array `garbage` representing the types of garbage at each house (`M` for metal, `P` for paper, `G` for glass), and an array `travel` representing the travel time between consecutive houses, **determine** the **minimum** number of minutes needed for three garbage trucks to pick up all t... | 42 | 1 | ['Array', 'String', 'C', 'Prefix Sum', 'Python', 'C++', 'Java', 'Python3'] | 2 |
minimum-amount-of-time-to-collect-garbage | C++/Python loop & accumulate||94ms Beats 100% | cpython-loop-accumulate94ms-beats-100-by-tos7 | Intuition\n Describe your first thoughts on how to solve this problem. \n\ntotal time=time for collecting garbage + time for traveling\n\nDivide the questions i | anwendeng | NORMAL | 2023-11-20T01:27:22.917143+00:00 | 2023-11-20T23:30:01.278342+00:00 | 3,554 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n```\ntotal time=time for collecting garbage + time for traveling\n```\nDivide the questions into 2 parts; it might make the solution easier.\ntime for collecting garbage is very easy; other is also not difficult.\n# Approach\n<!-- Describ... | 22 | 2 | ['Array', 'String', 'C++', 'Python3'] | 3 |
minimum-amount-of-time-to-collect-garbage | [Python3] Greedy + prefix sum || beats 100% | python3-greedy-prefix-sum-beats-100-by-y-biwm | Intuition\n- Find last position (the most right house) for each type of garbage.\n- Find distance for every house using prefix sum (use itertools.accumulate to | yourick | NORMAL | 2023-11-20T02:09:10.608908+00:00 | 2023-11-20T02:17:04.353646+00:00 | 958 | false | # Intuition\n- Find last position (the most right house) for each type of garbage.\n- Find distance for every house using prefix sum (use [`itertools.accumulate`](https://docs.python.org/3/library/itertools.html#itertools.accumulate) to simplify code).\n- Don\'t forget to count the garbage (1 sek to peek 1 unit of any ... | 20 | 0 | ['Greedy', 'Prefix Sum', 'Python', 'Python3'] | 3 |
minimum-amount-of-time-to-collect-garbage | Beats 100% | time O(n) | space O(n) | beats-100-time-on-space-on-by-dee_coder0-k95d | Code\n\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n int totalTime = 0;\n int len = garbage.length;\n | dee_coder01 | NORMAL | 2022-12-25T06:28:35.687690+00:00 | 2022-12-25T06:29:05.865741+00:00 | 2,322 | false | # Code\n```\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n int totalTime = 0;\n int len = garbage.length;\n totalTime+=1*garbage[0].length();\n for(int i = 1; i<len; i++){\n totalTime+=1*garbage[i].length();\n totalTime+=3*travel... | 15 | 0 | ['Java'] | 4 |
minimum-amount-of-time-to-collect-garbage | python explained solution easy | python-explained-solution-easy-by-nitish-yx5h | Calculate count of paper,glass and metal and total time taken to collecte each one of them. \nTotal time taken can be calculated by the index of the last house | nitish3170 | NORMAL | 2022-08-28T05:20:54.855453+00:00 | 2022-09-01T19:27:46.422002+00:00 | 1,461 | false | Calculate count of paper,glass and metal and total time taken to collecte each one of them. \nTotal time taken can be calculated by the index of the last house with that item and adding the total time taken to reach that house.\nAdd all value and return.\n\n**CODE:**\n```\ndef garbageCollection(self, garbage: List[str]... | 14 | 0 | ['Prefix Sum', 'Python'] | 1 |
minimum-amount-of-time-to-collect-garbage | ✅C++ | ✅Count | ✅Easy & efficient solution | c-count-easy-efficient-solution-by-yash2-qbc5 | \nclass Solution \n{\npublic:\n int garbageCollection(vector<string>& gar, vector<int>& tra) \n {\n int cnt=0;\n int last_g=0, last_p=0, las | Yash2arma | NORMAL | 2022-08-28T04:46:27.278125+00:00 | 2022-08-28T05:05:37.224469+00:00 | 1,552 | false | ```\nclass Solution \n{\npublic:\n int garbageCollection(vector<string>& gar, vector<int>& tra) \n {\n int cnt=0;\n int last_g=0, last_p=0, last_m=0;\n \n for(int i=0; i<gar.size(); i++)\n {\n for(auto it:gar[i])\n {\n //finding last inde... | 14 | 2 | ['C', 'Prefix Sum', 'C++'] | 1 |
minimum-amount-of-time-to-collect-garbage | Adhoc 2 Pass || with explanation || O(1) Space | adhoc-2-pass-with-explanation-o1-space-b-qias | Intuition\n Just a adhoc problem by seeing how the test cases are working.\n \nObservation\n \n 1. We have to take either all \'M\' or all \'P\' or al | xxvvpp | NORMAL | 2022-08-28T04:03:23.220782+00:00 | 2022-08-29T07:40:17.430516+00:00 | 939 | false | **Intuition**\n Just a adhoc problem by seeing how the test cases are working.\n \n**Observation**\n \n 1. We have to take either all **\'M\'** or all **\'P\'** or all **\'G\'** together at one iteration.\n 2. The **time of travel after the last position of each character from left will not be counted in tot... | 14 | 6 | ['C', 'Java'] | 3 |
minimum-amount-of-time-to-collect-garbage | Easy C++ code with intuition, optimization, complexity analysis | easy-c-code-with-intuition-optimization-udryg | \n# Intuition\n\nLet\'s say we find time taken for one type. \n- We start from first house, then check if this house has that grabage or not. If it has we picku | sachuverma | NORMAL | 2022-08-28T04:01:15.289235+00:00 | 2022-08-28T04:01:48.717094+00:00 | 1,277 | false | \n# Intuition\n\nLet\'s say we find time taken for one type. \n- We start from first house, then check if this house has that grabage or not. If it has we pickup the garbage and calculate cost to travel to this house from last house which had same garbage.\n- Otherwise, we just go to next house.\n\nWe repreat this proc... | 14 | 5 | [] | 5 |
minimum-amount-of-time-to-collect-garbage | Prefix Sum | prefix-sum-by-votrubac-fxm1 | We need to track the distance to the last house with the garbage of each type.\n\nC++\ncpp\nint garbageCollection(vector<string>& garb, vector<int>& travel) {\n | votrubac | NORMAL | 2022-08-28T04:02:11.739874+00:00 | 2022-08-28T05:57:55.900654+00:00 | 2,190 | false | We need to track the distance to the last house with the garbage of each type.\n\n**C++**\n```cpp\nint garbageCollection(vector<string>& garb, vector<int>& travel) {\n int dist[128] = {};\n partial_sum(begin(travel), end(travel), begin(travel));\n for (int i = 1; i < garb.size(); ++i)\n for (auto g : ga... | 12 | 1 | [] | 2 |
minimum-amount-of-time-to-collect-garbage | ✅✅C++ Easy and Simple O(N) solution ✅✅ | c-easy-and-simple-on-solution-by-parziva-9923 | Approach:\n1. We initialize three variables lastM, lastP, lastG to store the last occurences of each type of garbage.\n2. We then calculate the time for picking | Parzival1509 | NORMAL | 2023-11-20T06:27:37.470878+00:00 | 2023-11-20T06:27:37.470900+00:00 | 1,529 | false | # Approach:\n1. We initialize three variables ```lastM, lastP, lastG``` to store the last occurences of each type of garbage.\n2. We then calculate the time for picking up the garbages, which is equal to the sum of length of all the strings and store it in ```ans``` variable.\n3. We then calculate the time to travel to... | 11 | 0 | ['C++'] | 2 |
minimum-amount-of-time-to-collect-garbage | Easy javascript solution (16 lines) | easy-javascript-solution-16-lines-by-com-q192 | \nconst garbageCollection = (garbage, travel) => {\n let travelTime = 0\n garbage = garbage.reverse()\n \n for (const type of [\'G\', \'P\', \'M\']) {\n | ComsiComsa | NORMAL | 2022-09-18T15:26:30.016951+00:00 | 2022-09-18T15:41:56.924384+00:00 | 583 | false | ```\nconst garbageCollection = (garbage, travel) => {\n let travelTime = 0\n garbage = garbage.reverse()\n \n for (const type of [\'G\', \'P\', \'M\']) {\n const lastHouseWithGarbage = garbage.findIndex(house => house.includes(type))\n \n if (lastHouseWithGarbage === -1) {\n continue\n }\n\n tra... | 10 | 0 | ['JavaScript'] | 1 |
minimum-amount-of-time-to-collect-garbage | [Java/Python 3] Prefix sum of travel time. | javapython-3-prefix-sum-of-travel-time-b-u7wf | The time cost of each truck includes the following 2 parts:\n1. Gabage pick up time: depends on the total units of the specific type of gabage at all houses;\n2 | rock | NORMAL | 2022-08-28T04:06:18.816845+00:00 | 2022-08-28T14:52:39.341703+00:00 | 1,529 | false | The time cost of each truck includes the following `2` parts:\n1. Gabage pick up time: depends on the total units of the specific type of gabage at all houses;\n2. Travel time: depends on the time cost from house `0` to the last house that has the type of gabage corresponding to the truck. We can use prefix sum to comp... | 10 | 0 | ['Java', 'Python3'] | 2 |
minimum-amount-of-time-to-collect-garbage | ✔C++|Prefix Sum |O(N)| Easy✔ | cprefix-sum-on-easy-by-xahoor72-yr6b | Intuition\n Describe your first thoughts on how to solve this problem. \nConcept is to use prefix sum as we have given time from one to another house instead xo | Xahoor72 | NORMAL | 2023-02-01T16:11:38.238651+00:00 | 2023-02-01T16:11:38.238683+00:00 | 837 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nConcept is to use prefix sum as we have given time from one to another house instead xounting one by one from one to other house just find the last index at which certain type of grabage is present and count all the units of garbage pres... | 8 | 0 | ['Array', 'Prefix Sum', 'C++'] | 2 |
minimum-amount-of-time-to-collect-garbage | ✅😍100% Beats Google Approach🔥🔥🔥 | 100-beats-google-approach-by-sourav_n06-lktj | Intuition\n Describe your first thoughts on how to solve this problem. \nI saw it on Instagram\n# Approach\n Describe your approach to solving the problem. \nIn | sourav_n06 | NORMAL | 2023-11-20T05:14:26.375605+00:00 | 2023-11-20T05:14:26.375633+00:00 | 1,731 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI saw it on Instagram\n# Approach\n<!-- Describe your approach to solving the problem. -->\nInput: garbage = ["MMM","PGM","GP"], travel = [3,10]\nOutput: 37\nExplanation:\nThe metal garbage truck takes 7 minutes to pick up all the metal g... | 7 | 1 | ['Python', 'C++', 'Java', 'JavaScript'] | 2 |
minimum-amount-of-time-to-collect-garbage | Easy Python Solution using Prefix Sum | easy-python-solution-using-prefix-sum-by-1wqw | Important observation:\nAs For commute time, we only care about when a specific kind of garbage last appears. Because we can skip the remaining if that kind of | siyu_ | NORMAL | 2022-09-10T00:14:10.202018+00:00 | 2022-09-10T00:14:36.280251+00:00 | 526 | false | Important observation:\nAs For commute time, we only care about when a specific kind of garbage **last appears**. Because we can skip the remaining if that kind of garbage doesn\'t appear anymore.\nTo make things easier, we will use **prefix sum** to help us do the calculation.\n\nTherefore, the algorithm is very intui... | 7 | 0 | ['Counting', 'Prefix Sum', 'Python', 'Python3'] | 1 |
minimum-amount-of-time-to-collect-garbage | implementation + hashmap | implementation-hashmap-by-harshitmaurya-5pbm | \n\nSimply Find the limit for every \'P\',\'M\' and \'G\'\n\nthen loop for every garbage of type \'P\',\'M\' and \'G\' and add count of the garbage of current s | HarshitMaurya | NORMAL | 2022-08-28T04:01:37.837179+00:00 | 2022-08-28T04:01:37.837222+00:00 | 794 | false | \n\nSimply Find the limit for every \'P\',\'M\' and \'G\'\n\nthen loop for every garbage of type \'P\',\'M\' and \'G\' and add count of the garbage of current string and time cost till current house \n\n\n```\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n long ans=0;\n ... | 7 | 1 | ['Java'] | 2 |
minimum-amount-of-time-to-collect-garbage | Insane Bit Manipulations. No Nested Loops. Top Execution Time (84-97 ms in C++). | insane-bit-manipulations-no-nested-loops-jf0p | Intuition\nWe need to calculate the minimum time to collect all garbage from the houses, spread across the line, so that collection trucks visit them in order. | sergei99 | NORMAL | 2023-11-20T16:19:35.400252+00:00 | 2024-02-19T00:33:59.541365+00:00 | 96 | false | # Intuition\nWe need to calculate the minimum time to collect all garbage from the houses, spread across the line, so that collection trucks visit them in order. There are 3 kinds of garbage and 3 trucks each collecting one specific kind. On input we have distances in minutes between the houses and information of garba... | 6 | 0 | ['Array', 'String', 'Binary Search', 'Bit Manipulation', 'C++'] | 2 |
minimum-amount-of-time-to-collect-garbage | Beginner Friendly | Reverse Order Aproach | Simple | Easy To Understand | Java | Python3 |C++ | C# | beginner-friendly-reverse-order-aproach-oqcw9 | Intuition\n Describe your first thoughts on how to solve this problem. \nIt iterates through an array of strings (garbage), where each string represents a locat | antovincent | NORMAL | 2023-11-20T13:31:44.168638+00:00 | 2023-11-20T13:31:44.168661+00:00 | 535 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt iterates through an array of strings (garbage), where each string represents a location, and an array of integers (travel), where each integer represents the travel distance between consecutive locations. Considers the lengths of the s... | 6 | 0 | ['Dynamic Programming', 'C', 'PHP', 'Java', 'TypeScript', 'Python3', 'Ruby', 'Kotlin', 'JavaScript', 'C#'] | 0 |
minimum-amount-of-time-to-collect-garbage | Idea Explained || Counting and Prefix Sum || C++ Clean Code | idea-explained-counting-and-prefix-sum-c-i3jx | Intuition :\n\n Idea here is simple, we need to count the number of different type of garbages at each house and travel time to reach a house.\n Also, a garbage | i_quasar | NORMAL | 2022-08-28T04:08:12.743022+00:00 | 2022-08-28T04:45:00.005942+00:00 | 290 | false | **Intuition :**\n\n* Idea here is simple, we need to count the number of different type of garbages at each house and travel time to reach a house.\n* Also, a garbage truck of some type will only stop at a house if it has garbage of that type, else move to next house.\n\n* If a truck stops at a particular house, we can... | 6 | 1 | ['Counting', 'Prefix Sum'] | 2 |
minimum-amount-of-time-to-collect-garbage | O(N), O(1) simple solution with clear explanation, single for loop | on-o1-simple-solution-with-clear-explana-nur5 | Intuition\nAt first glance and read of the question we would like to calculate the travel time taken by each truck and the time taken by them to process their r | naruto_1994 | NORMAL | 2023-11-20T03:27:19.342437+00:00 | 2023-11-20T03:28:42.331946+00:00 | 64 | false | # Intuition\nAt first glance and read of the question we would like to calculate the travel time taken by each truck and the time taken by them to process their respective waste and once we sum it we would have our answer.\n\n# Approach\nThings to observe, that were kind of hidden in the problem description, before rea... | 5 | 0 | ['Go'] | 1 |
minimum-amount-of-time-to-collect-garbage | Easy Approach c++ O(n) | easy-approach-c-on-by-akshat161997-k5gd | \nvoid countFreq(string s, int &G, int &P, int &M){\n for(int i=0;i<s.length();i++){\n if(s[i]==\'G\') G++;\n else if(s[i]==\'M\') | akshat161997 | NORMAL | 2022-08-28T16:50:02.257056+00:00 | 2022-08-28T16:50:02.257097+00:00 | 430 | false | ```\nvoid countFreq(string s, int &G, int &P, int &M){\n for(int i=0;i<s.length();i++){\n if(s[i]==\'G\') G++;\n else if(s[i]==\'M\') M++;\n else if(s[i]==\'P\') P++;\n }\n }\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int n=garba... | 5 | 0 | [] | 3 |
minimum-amount-of-time-to-collect-garbage | ✅Python || Easy Approach || Prefix Sum || Hashmap | python-easy-approach-prefix-sum-hashmap-vozvi | \nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n \n from collections import defaultdict\n\n | chuhonghao01 | NORMAL | 2022-08-28T04:22:42.627608+00:00 | 2022-08-28T04:22:42.627633+00:00 | 706 | false | ```\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n \n from collections import defaultdict\n\n ans = 0\n lastH = {}\n num = defaultdict(int)\n\n for i in range(len(garbage)):\n for char in garbage[i]:\n ... | 5 | 0 | ['Prefix Sum', 'Python', 'Python3'] | 0 |
minimum-amount-of-time-to-collect-garbage | ✅[C++] (BRUTE FORCE ) full explain Prefix sum + Map , Easy and readable | c-brute-force-full-explain-prefix-sum-ma-j4gr | Please UPVOTE if you like it and thanks\nThe idea is to traverse from right and calculate total time for three of trucks :\nBut How : \ntimem : total time for | Pathak_Ankit | NORMAL | 2022-08-28T04:21:25.219533+00:00 | 2022-08-28T04:56:44.939013+00:00 | 433 | false | Please UPVOTE if you like it and thanks\n**The idea is to traverse from right and calculate total time for three of trucks :**\nBut How : \ntimem : total time for M garbage\ntimem = last occurence of M + no. of M;\nBut why last occurence : becz M\'s truck have to wait for last M garbage using prefix sum of total time ... | 5 | 1 | ['C', 'Prefix Sum'] | 2 |
minimum-amount-of-time-to-collect-garbage | C++||very easy Solution||O(N)||space O(1) | cvery-easy-solutiononspace-o1-by-baibhav-evng | \n//at first just store last index of Metal , paper , glass\n//rest see the code\nclass Solution {\npublic:\n int garbageCollection(vector<string>& gar, vect | baibhavkr143 | NORMAL | 2022-08-28T04:02:03.583207+00:00 | 2022-08-28T04:41:38.181749+00:00 | 157 | false | ```\n//at first just store last index of Metal , paper , glass\n//rest see the code\nclass Solution {\npublic:\n int garbageCollection(vector<string>& gar, vector<int>& travel) {\n \n int glass=-1,paper=-1,metal=-1; //storing last index of each garbage\n \n for(int i=0;i<gar.size();i++)\... | 5 | 2 | [] | 1 |
minimum-amount-of-time-to-collect-garbage | O(N) T.C & S.C O(1) SOLUTION BEGINNERS WITHOUT MAP!!! | on-tc-sc-o1-solution-beginners-without-m-222a | 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 | aero_coder | NORMAL | 2023-11-20T16:13:47.755603+00:00 | 2023-11-23T08:56:18.807125+00:00 | 225 | 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(1)\n\n# Code\n```\nclass Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vec... | 4 | 0 | ['C++'] | 0 |
minimum-amount-of-time-to-collect-garbage | Simple and Easy C++ code with Explanation using Single Loop || Prefix Sum || Beats 100% ✅ | simple-and-easy-c-code-with-explanation-kudjx | \n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n1. We need to find the prefix sum of the travel array, to find the minimum time t | Nilogrib | NORMAL | 2023-11-20T10:07:04.557568+00:00 | 2023-11-20T10:07:04.557591+00:00 | 1,303 | false | \n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. We need to find the prefix sum of the `travel` array, to find the minimum time taken by the trucks to travel to the re... | 4 | 0 | ['Array', 'String', 'Prefix Sum', 'C++'] | 1 |
minimum-amount-of-time-to-collect-garbage | ✅☑[C++/Java/Python/JavaScript] || 2 Approaches || EXPLAINED🔥 | cjavapythonjavascript-2-approaches-expla-5bae | PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n(Also explained in the code)\n\n#### Approach 1(HashMaps)\n1. Prefix Sum Calculation:\n\n - prefixSum ve | MarkSPhilip31 | NORMAL | 2023-11-20T07:50:03.364836+00:00 | 2023-11-20T07:50:03.364859+00:00 | 642 | false | # PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n**(Also explained in the code)**\n\n#### ***Approach 1(HashMaps)***\n1. **Prefix Sum Calculation:**\n\n - `prefixSum` vector stores the prefix sum of the `travel` vector.\n - It helps in calculating the distance traveled up to a certain point efficiently.\n1.... | 4 | 0 | ['Array', 'String', 'C', 'Prefix Sum', 'C++', 'Java', 'Python3', 'JavaScript'] | 0 |
minimum-amount-of-time-to-collect-garbage | Eay concise Python solution 1 pass O(n) travel backwards | eay-concise-python-solution-1-pass-on-tr-kflu | Observe that every truck will have to travel to the last house that has the garbage of its kind and stop there. Therefore, the original problem is equivalent to | gauau | NORMAL | 2023-11-20T01:56:58.971623+00:00 | 2023-11-20T02:02:04.457657+00:00 | 183 | false | Observe that every truck will have to travel to the last house that has the garbage of its kind and stop there. Therefore, the original problem is equivalent to "each truck starts at its last index and ends at index 0"\n-> We can traverse the input array backwards and solve the problem in 1 pass\n```\ndef garbageCollec... | 4 | 0 | [] | 1 |
minimum-amount-of-time-to-collect-garbage | C++/CPP : Simple Logic | ccpp-simple-logic-by-piyushghante-hfbr | \n\n# Code\n\nclass Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n \n int n=garbage.size();\n\n | piyushghante | NORMAL | 2023-09-08T11:40:34.009646+00:00 | 2023-09-08T12:08:24.479899+00:00 | 216 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n \n int n=garbage.size();\n\n int p=0;\n int m=0;\n int g=0;\n\n int p_travel_cost=0;\n int m_travel_cost=0;\n int g_travel_cost=0;\n\n int... | 4 | 0 | ['C++'] | 0 |
minimum-amount-of-time-to-collect-garbage | C++||Easy and Simple || | ceasy-and-simple-by-adil_2024-1hf6 | 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 | adil_2024 | NORMAL | 2023-04-04T05:49:40.796296+00:00 | 2023-04-04T05:49:40.796344+00:00 | 631 | 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)$$ --... | 4 | 0 | ['C++'] | 0 |
minimum-amount-of-time-to-collect-garbage | C++ ||10 lines||most optimized||O(n)||O(1) | c-10-linesmost-optimizedono1-by-sheetal0-s29i | Intuition\nWe start from last house, then check if this house has that grabage or not. If it has we pickup the garbage and calculate cost to travel to this hous | sheetal0797 | NORMAL | 2023-01-28T07:34:44.037985+00:00 | 2023-01-28T07:34:44.038029+00:00 | 308 | false | # Intuition\nWe start from last house, then check if this house has that grabage or not. If it has we pickup the garbage and calculate cost to travel to this house which had same garbage. and keep adding cost to travel now onwards to the first house.\nOtherwise, we just go to next house.\n\n\n# Approach\n\n# Complexity... | 4 | 0 | ['C++'] | 0 |
minimum-amount-of-time-to-collect-garbage | Simple Java Solution faster than 97% | simple-java-solution-faster-than-97-by-s-rw8f | \n\nclass Solution {\n public int garbageCollection(String[] g, int[] travel) {\n int ans = getTimeForGarbage(g,travel,\'M\')+getTimeForGarbage(g,tr | Sarthak_Singh_ | NORMAL | 2022-12-25T06:35:52.856445+00:00 | 2022-12-25T06:35:52.856490+00:00 | 457 | false | \n```\nclass Solution {\n public int garbageCollection(String[] g, int[] travel) {\n int ans = getTimeForGarbage(g,travel,\'M\')+getTimeForGarbage(g,travel,\'G\')+getTimeForGarbage(g,travel,\'P\');\n return ans; \n\n }\n private static int getTimeForGarbage(String[] g, int[] travel, Ch... | 4 | 1 | ['Java'] | 1 |
minimum-amount-of-time-to-collect-garbage | Python Well explained | Simple solution | python-well-explained-simple-solution-by-512n | As mentioned in the hint we fist calculate the maximum index for each catagory where at least 1 unit of garbage of that type is present. \n\n2. Here IN takes O( | vkadu68 | NORMAL | 2022-11-02T21:06:10.590948+00:00 | 2022-11-02T21:06:10.590993+00:00 | 315 | false | 1. As mentioned in the hint we fist calculate the maximum index for each catagory where at least 1 unit of garbage of that type is present. \n\n2. Here IN takes O(1) because the categopries are constant\nthen we take the sum of the travel array unilt that index for each category and then add it into our result.\n\n3. w... | 4 | 0 | ['Python'] | 0 |
minimum-amount-of-time-to-collect-garbage | ✅✅Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-9vxn | Using Prefix Sum\n\n Time Complexity :- O(N)\n\n Space Complexity :- O(1)\n\n\nclass Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vec | __KR_SHANU_IITG | NORMAL | 2022-08-29T08:11:01.267323+00:00 | 2022-08-29T08:11:01.267347+00:00 | 270 | false | * ***Using Prefix Sum***\n\n* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(1)***\n\n```\nclass Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n \n int n = garbage.size();\n \n // find the last position of each type of garbage\n ... | 4 | 0 | ['C', 'Prefix Sum', 'C++'] | 1 |
minimum-amount-of-time-to-collect-garbage | Easy C++ Code || Beats 100% Submission || O(1) Space || Prefix Sum | easy-c-code-beats-100-submission-o1-spac-ht7h | ```\nint garbageCollection(vector&v, vector& t) {\n int i,n=v.size(),m=-1,g=-1,p=-1,ans=0;\n for(i=n-1;i>=0;i--){\n for(char c : v[i]){ | vidit987 | NORMAL | 2022-08-28T10:54:48.518067+00:00 | 2022-08-28T10:56:27.580621+00:00 | 133 | false | ```\nint garbageCollection(vector<string>&v, vector<int>& t) {\n int i,n=v.size(),m=-1,g=-1,p=-1,ans=0;\n for(i=n-1;i>=0;i--){\n for(char c : v[i]){\n // storing the last index of each char \'P\',\'M\',\'G\';\n if(c==\'P\' && p==-1)p=i;\n if(c==\'G\'... | 4 | 0 | ['C', 'Prefix Sum'] | 1 |
minimum-amount-of-time-to-collect-garbage | Java Easy Solution using Map | java-easy-solution-using-map-by-devkd-ooyq | Java Easy Solution using HashMap\n\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n int ans=0;\n //Creating | DevKD | NORMAL | 2022-08-28T04:26:44.062159+00:00 | 2022-08-28T04:26:44.062202+00:00 | 455 | false | # Java Easy Solution using HashMap\n```\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n int ans=0;\n //Creating a map to store type of garbage and where it is found\n HashMap<Character,List<Integer>> map=new HashMap<Character,List<Integer>>();\n char[]... | 4 | 0 | ['Math', 'Java'] | 1 |
minimum-amount-of-time-to-collect-garbage | C++ Using hashmap || Beginner friendly & east to understand approach | c-using-hashmap-beginner-friendly-east-t-f18c | \nclass Solution {\npublic:\n int findTime(vector<string>& garbage, vector<int>& travel, char type, unordered_map<char, int> &mpp){\n int minute = 0;\ | shm_47 | NORMAL | 2022-08-28T04:26:12.333147+00:00 | 2022-08-28T04:28:30.265186+00:00 | 330 | false | ```\nclass Solution {\npublic:\n int findTime(vector<string>& garbage, vector<int>& travel, char type, unordered_map<char, int> &mpp){\n int minute = 0;\n \n //every house\n for(int i=0; i<garbage.size(); i++){\n if(mpp[type]>0){ //if that type of garbage remains to collect\... | 4 | 0 | ['C'] | 1 |
minimum-amount-of-time-to-collect-garbage | Python explained | python-explained-by-sachin_c-kbw6 | Just keep track of last occuarnce of each garbage type.\nSince we know the number of types we can set a multiplier from start.\nAnd since each of garbage takes | sachin_c | NORMAL | 2022-08-28T04:21:49.410470+00:00 | 2022-08-28T04:23:38.634845+00:00 | 459 | false | Just keep track of last occuarnce of each garbage type.\nSince we know the number of types we can set a multiplier from start.\nAnd since each of garbage takes same amount of time and each truck takes same amount of time to travel we can just append our solution and just decrease multiplier if last occurance of garbage... | 4 | 0 | ['Python'] | 1 |
minimum-amount-of-time-to-collect-garbage | CPP | Easy | Prefix sum | cpp-easy-prefix-sum-by-amirkpatna-vkia | Intuition : Just a simple greedy problem my approach was bit different though.\nI calculated prefix sum of travel.\nAnd simply I keep adding number of particula | amirkpatna | NORMAL | 2022-08-28T04:02:24.379070+00:00 | 2022-08-28T04:05:39.342500+00:00 | 387 | false | **Intuition :** Just a simple greedy problem my approach was bit different though.\nI calculated `prefix sum` of `travel`.\nAnd simply I keep adding number of particular garbages occurs for any type in my answer\nand after that I started from back and kept looking which which garbage is occuring where for the first tim... | 4 | 0 | ['Prefix Sum', 'C++'] | 1 |
minimum-amount-of-time-to-collect-garbage | [Python3] simulation | python3-simulation-by-ye15-rigf | Please pull this commit for solutions of weekly 308.\n\nIntuition\nThe total time can be decomposed into 1) time to collect gargage and 2) time to travel to nex | ye15 | NORMAL | 2022-08-28T04:01:56.523890+00:00 | 2022-08-28T04:49:36.481271+00:00 | 335 | false | Please pull this [commit](https://github.com/gaosanyong/leetcode/commit/ea6bc01b091cbf032b9c7ac2d3c09cb4f5cd0d2d) for solutions of weekly 308.\n\n**Intuition**\nThe total time can be decomposed into 1) time to collect gargage and 2) time to travel to next stop. \nHere, the first component is simply the sum of length of... | 4 | 0 | ['Python3'] | 1 |
minimum-amount-of-time-to-collect-garbage | Efficient Garbage Collection with Optimized Travel Time using C++ ✅✅ | optimal-solution-beats-100-using-c-by-ha-t6da | IntuitionThe problem involves collecting different types of garbage from several houses and minimizing the total travel time. Each type of garbage is collected | harish_cs2023 | NORMAL | 2025-02-09T07:11:22.831615+00:00 | 2025-02-09T12:13:44.406853+00:00 | 75 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem involves collecting different types of garbage from several houses and minimizing the total travel time. Each type of garbage is collected by a specific truck. The approach involves first counting the amount of each type of garb... | 3 | 0 | ['C++'] | 0 |
minimum-amount-of-time-to-collect-garbage | Python Easy & Brute force Solution | python-easy-brute-force-solution-by-labd-75a8 | Approach\nBrute force\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n\n# Code\n\nclass Solution:\n def garbageCollection(self, gar | labdhigathani9999 | NORMAL | 2023-11-20T12:45:10.111984+00:00 | 2023-11-20T12:47:20.698205+00:00 | 39 | false | # Approach\nBrute force\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n\n# Code\n```\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n join_garbage = "".join(garbage)\n count = 0\n for i in join_garbage:\n if i =... | 3 | 0 | ['Python', 'Python3'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.