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-difference-between-highest-and-lowest-of-k-scores | C++ | Sliding Window and Recursive-backtracking solution | c-sliding-window-and-recursive-backtrack-yzoq | Intuition\nI first tried to solve using recursive-backtracking approach, which obviously gave me TLE. But still my code was working for smaller inputs. \nThe be | anandvaibhav | NORMAL | 2023-07-29T13:01:32.763759+00:00 | 2023-07-29T13:01:32.763780+00:00 | 24 | false | # Intuition\nI first tried to solve using recursive-backtracking approach, which obviously gave me TLE. But still my code was working for smaller inputs. \nThe better approach I found was first sorting and updating our ans for given window size.\n\n# Approach\nStart with sorting an array, defining two pointers i and j ... | 2 | 0 | ['Backtracking', 'Recursion', 'Sliding Window', 'C++'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | 90% Runtime, 85% Memory with Simple Code | 90-runtime-85-memory-with-simple-code-by-bshh | \n\n# Approach\nres = nums[k-1] - nums[0]\nSince nums is sorted, nums[k-1] - nums[0] returns max dif.\n\nres = min(res, nums[i] - nums[i - k + 1])\nFrom window | yw1033 | NORMAL | 2023-06-30T13:16:23.968786+00:00 | 2023-06-30T13:16:23.968819+00:00 | 623 | false | \n\n# Approach\n`res = nums[k-1] - nums[0]`\nSince nums is sorted, `nums[k-1] - nums[0]` returns max dif.\n\n`res = min(res, nums[i] - nums[i - k + 1])`\nFrom window of size k, the far left is the minimum \nand far right is the maximum value in the window since nums is sorted. \n`nums[i]` : Far right\n`nums[i - k + 1])... | 2 | 0 | ['Python3'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Python 2 line + CPP Soln With Explanation | python-2-line-cpp-soln-with-explanation-860jf | \nThis Q is asking what is the minimum difference between nums[i] and nums[i+(k-1)] for all.\n k-1 beacuse Total K Values = from nums[i] to nums[i+k-1]\n | speedyy | NORMAL | 2023-05-23T15:46:09.052054+00:00 | 2023-05-23T15:55:16.527093+00:00 | 800 | false | ```\nThis Q is asking what is the minimum difference between nums[i] and nums[i+(k-1)] for all.\n k-1 beacuse Total K Values = from nums[i] to nums[i+k-1]\n ------- -----------\n 1 value k-1 values\n ... | 2 | 0 | ['C++', 'Python3'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | 🔥 🔥🔥 JavaScript, easy to understand, faster than 94% Sliding Window 🔥 🔥🔥 | javascript-easy-to-understand-faster-tha-jfx0 | 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 | azamatval75 | NORMAL | 2023-04-15T14:18:05.774711+00:00 | 2023-04-15T19:16:50.396705+00:00 | 428 | 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(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(logn)\n<!-- Add your space complexity here,... | 2 | 0 | ['Sliding Window', 'JavaScript'] | 1 |
minimum-difference-between-highest-and-lowest-of-k-scores | ✅ С | Sorted and compare | s-sorted-and-compare-by-kosant-g36s | Complexity\n- Time complexity: O(N * logN)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(N)\n Add your space complexity here, e.g. O(n) \ | kosant | NORMAL | 2023-03-25T07:59:24.366194+00:00 | 2023-03-25T07:59:24.366231+00:00 | 2,440 | false | # Complexity\n- Time complexity: O(N * logN)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nint min(int a, int b) {\n if (a < b) return a;\n else return b;\n}\n\nint cmp(const void *a, const void *b) {\n ... | 2 | 0 | ['C', 'Sorting', 'C++'] | 1 |
minimum-difference-between-highest-and-lowest-of-k-scores | simple cpp solution | simple-cpp-solution-by-prithviraj26-jlpw | 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 | prithviraj26 | NORMAL | 2023-02-02T13:41:52.519046+00:00 | 2023-02-02T13:41:52.519080+00:00 | 846 | 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', 'C++'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Java Easy Solution || 100% working | java-easy-solution-100-working-by-himans-lnmb | 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 | himanshu_gupta_ | NORMAL | 2023-01-23T16:23:55.395325+00:00 | 2023-01-23T16:23:55.395368+00:00 | 1,262 | 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'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Python Solution | python-solution-by-marcmourning-wa90 | Intuition\nThe hardest issue was trying to figure out how to calculate the difference, based on the number of k students, no matter the size of the list. And th | marcmourning | NORMAL | 2022-12-30T04:59:51.760110+00:00 | 2022-12-30T04:59:51.760172+00:00 | 1,064 | false | # Intuition\nThe hardest issue was trying to figure out how to calculate the difference, based on the number of k students, no matter the size of the list. And then check each difference and compare it to the minimum difference, and then return the lowest possible difference. \n\n# Approach\nSimple usage of python buil... | 2 | 0 | ['Python3'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | C++ || sliding window approach | c-sliding-window-approach-by-als_venky-r7iz | \nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n if(k>nums.size()) return 0;\n sort(nums.begin(),nums.end());\ | ALS_Venky | NORMAL | 2022-09-17T06:13:11.799649+00:00 | 2022-09-17T06:13:11.799693+00:00 | 313 | false | ```\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n if(k>nums.size()) return 0;\n sort(nums.begin(),nums.end());\n int mini=nums[k-1]-nums[0];\n for(int i=k;i<nums.size();i++){\n mini=min(nums[i]-nums[i-k+1],mini);\n }\n return min... | 2 | 0 | ['C', 'Sorting', 'C++'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | JAVA easy solution 100% fast | java-easy-solution-100-fast-by-21arka200-eanq | \nclass Solution {\n public int minimumDifference(int[] nums, int k) {\n Arrays.sort(nums);\n int min=Integer.MAX_VALUE;\n int i=k;\n | 21Arka2002 | NORMAL | 2022-09-11T06:41:38.477656+00:00 | 2022-09-11T06:41:38.477742+00:00 | 1,027 | false | ```\nclass Solution {\n public int minimumDifference(int[] nums, int k) {\n Arrays.sort(nums);\n int min=Integer.MAX_VALUE;\n int i=k;\n while(i<=nums.length)\n {\n int h=nums[i-1];\n int l=nums[i-k];\n if(h-l<min)min=h-l;\n i+=1;\n ... | 2 | 0 | ['Sliding Window', 'Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Python Easy to Understand Beats 92% With Explanation | python-easy-to-understand-beats-92-with-o8pwo | Idea\nWe take a greedy approach to this problem. The greedy property is as follows:\n> There exists an optimal solution where the selected students form a subar | jflow2 | NORMAL | 2022-08-25T22:35:44.550537+00:00 | 2022-08-25T22:35:44.550577+00:00 | 544 | false | # Idea\nWe take a greedy approach to this problem. The greedy property is as follows:\n> There exists an optimal solution where the selected students form a subarray of the sorted scores.\n\nTo rephrase, we are claiming that an optimal solution may be selected from the subarrays of the array of sorted scores. To see th... | 2 | 0 | ['Greedy', 'Sliding Window', 'Python'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | ✔️Java solution | Sliding window | O(n) time complexity | Easy to understand | java-solution-sliding-window-on-time-com-42lb | Here\'s my code with O(n) complexity :\n```\nclass Solution {\n public int minimumDifference(int[] nums, int k) {\n if(nums.length==1){\n retu | Lord_Ambar | NORMAL | 2022-06-22T07:21:26.694325+00:00 | 2022-06-22T07:21:26.694355+00:00 | 865 | false | Here\'s my code with O(n) complexity :\n```\nclass Solution {\n public int minimumDifference(int[] nums, int k) {\n if(nums.length==1){\n return 0; \n }\n Arrays.sort(nums);\n int min = Integer.MAX_VALUE;\n int diff = 0;\n for(int e = k-1;e<nums.length;e++){\n ... | 2 | 1 | ['Sliding Window', 'Sorting', 'Java'] | 3 |
minimum-difference-between-highest-and-lowest-of-k-scores | C++ Sort ( m=min(m,nums[i+k-1]-nums[i])) | c-sort-mminmnumsik-1-numsi-by-mensenvau-bd1w | \nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n \n sort(nums.begin(),nums.end());\n int m=INT_MAX;\n | mensenvau | NORMAL | 2021-11-01T14:47:52.008963+00:00 | 2021-11-01T14:47:52.008994+00:00 | 66 | false | ```\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n \n sort(nums.begin(),nums.end());\n int m=INT_MAX;\n for(int i=0;i<=nums.size()-k;i++){\n m=min(m,nums[i+k-1]-nums[i]);\n }\n return m;\n }\n};\n``` | 2 | 0 | [] | 1 |
minimum-difference-between-highest-and-lowest-of-k-scores | Easy to understand JavaScript solution | easy-to-understand-javascript-solution-b-vau8 | \tvar minimumDifference = function(nums, k) {\n\t\tif (k === 1) return 0;\n\n\t\tlet minimum = Infinity;\n\t\tnums.sort((a, b) => b - a);\n\n\t\tfor (let index | tzuyi0817 | NORMAL | 2021-10-10T05:59:08.232465+00:00 | 2021-10-10T05:59:08.232499+00:00 | 269 | false | \tvar minimumDifference = function(nums, k) {\n\t\tif (k === 1) return 0;\n\n\t\tlet minimum = Infinity;\n\t\tnums.sort((a, b) => b - a);\n\n\t\tfor (let index = 0; index <= nums.length - k; index++) {\n\t\t\tconst max = nums[index];\n\t\t\tconst min = nums[index + k - 1];\n\n\t\t\tminimum = Math.min(minimum, max - min... | 2 | 0 | ['JavaScript'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Python O(nlogn) solution || sort first | python-onlogn-solution-sort-first-by-byu-wgp5 | \nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n \n n = len(nums)\n nums.sort()\n minv = nums[-1]- | byuns9334 | NORMAL | 2021-10-10T01:52:21.398592+00:00 | 2021-10-10T01:52:21.398624+00:00 | 256 | false | ```\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n \n n = len(nums)\n nums.sort()\n minv = nums[-1]-nums[0]\n for i in range(n-k+1):\n minv = min(minv, nums[i+k-1]-nums[i])\n return minv\n``` | 2 | 1 | ['Sorting', 'Python', 'Python3'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Simplest C++ solution. Easy to understand. | simplest-c-solution-easy-to-understand-b-kyq0 | \nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k)\n {\n int ans = INT_MAX;\n sort(nums.begin(),nums.end());\n | kfaisal-se | NORMAL | 2021-09-03T05:24:31.478662+00:00 | 2021-09-03T05:24:31.478716+00:00 | 265 | false | ```\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k)\n {\n int ans = INT_MAX;\n sort(nums.begin(),nums.end());\n \n for(int i=0;i<=nums.size()-k;i++)\n {\n ans = min(ans,nums[i+(k-1)] - nums[i]);\n }\n return ans;\n }\n};\n... | 2 | 1 | ['C'] | 1 |
minimum-difference-between-highest-and-lowest-of-k-scores | Runtime: 92 ms, faster than 100.00% of JavaScript online submissions | runtime-92-ms-faster-than-10000-of-javas-t9m3 | \nvar minimumDifference = function(nums, k) {\n if (nums.length===1) return 0;\n \n nums.sort((a,b)=>a-b);\n \n let left = 0;\n let right = k- | masha-nv | NORMAL | 2021-08-29T16:57:19.215113+00:00 | 2021-08-29T16:58:21.717643+00:00 | 270 | false | ```\nvar minimumDifference = function(nums, k) {\n if (nums.length===1) return 0;\n \n nums.sort((a,b)=>a-b);\n \n let left = 0;\n let right = k-1;\n \n let min = Infinity;\n \n while (right<nums.length){\n min = Math.min(min, nums[right]-nums[left]);\n right++;\n left... | 2 | 0 | ['JavaScript'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Python | Sort | 2 Lines | python-sort-2-lines-by-leeteatsleep-in8u | \nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums.sort()\n return min(nums[i+k-1] - nums[i] for i in ran | leeteatsleep | NORMAL | 2021-08-29T04:50:37.874525+00:00 | 2021-08-29T04:50:37.874553+00:00 | 285 | false | ```\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums.sort()\n return min(nums[i+k-1] - nums[i] for i in range(len(nums) - k + 1))\n```\n\nMore readable 5 liner:\n\n```\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums... | 2 | 1 | ['Sorting', 'Python', 'Python3'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Python 3, two lines - sort and sliding window | python-3-two-lines-sort-and-sliding-wind-waxb | \nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums.sort()\n return min(nums[i+k-1]-nums[i] for i in range( | silvia42 | NORMAL | 2021-08-29T04:06:21.601224+00:00 | 2021-08-29T04:06:21.601261+00:00 | 211 | false | ```\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums.sort()\n return min(nums[i+k-1]-nums[i] for i in range(len(nums)-k+1))\n``` | 2 | 0 | [] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | [Java] Sort & Sliding Window || Easy to understand | java-sort-sliding-window-easy-to-underst-ersm | \nclass Solution {\n public int minimumDifference(int[] nums, int k) {\n if(k == 1)return 0;\n int i = 0,j = k-1,res = Integer.MAX_VALUE;\n\t\t | abhijeetmallick29 | NORMAL | 2021-08-29T04:00:50.096091+00:00 | 2021-08-29T04:02:10.897745+00:00 | 585 | false | ```\nclass Solution {\n public int minimumDifference(int[] nums, int k) {\n if(k == 1)return 0;\n int i = 0,j = k-1,res = Integer.MAX_VALUE;\n\t\t\n Arrays.sort(nums);\n while(j < nums.length){\n res = Math.min(res,nums[j] - nums[i]);\n j++;\n i++;\n ... | 2 | 0 | ['Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Simple python solution | sliding window ✅ | simple-python-solution-sliding-window-by-07g2 | IntuitionTo solve with sliding windowComplexity
Time complexity: O(N Log N)
Space complexity: O(1)
Code | vaishnav_dinesh | NORMAL | 2025-03-17T09:26:44.239636+00:00 | 2025-03-17T09:26:44.239636+00:00 | 222 | false | # Intuition
To solve with sliding window
# Complexity
- Time complexity: O(N Log N)
- Space complexity: O(1)
# Code
```python3 []
class Solution:
def minimumDifference(self, nums: list[int], k: int) -> int:
L,R,min_v=0,k-1,float('inf')
nums.sort()
while R < len(nums):
... | 1 | 0 | ['Array', 'Sliding Window', 'Sorting', 'Python3'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | [Java] Easy 100% solution | java-easy-100-solution-by-ytchouar-pcvv | null | YTchouar | NORMAL | 2025-03-04T04:42:06.267307+00:00 | 2025-03-04T04:42:06.267307+00:00 | 377 | false | ```java []
class Solution {
public int minimumDifference(final int[] nums, final int k) {
final int n = nums.length;
Arrays.sort(nums);
int min = Integer.MAX_VALUE;
for(int i = 0; i < n - k + 1; ++i)
min = Math.min(min, nums[i + k - 1] - nums[i]);
return min;
... | 1 | 0 | ['Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | 🔥 Minimize Score Difference 🎯 | Sorting + Sliding Window 🚀 | But EASIEST Code | minimize-score-difference-sorting-slidin-5v5d | Intuition "Please make an ✨UPVOTE✨, Guys, if you like my approach and explanation... 👍 This will motivate me further in solving problems!"ApproachThe code follo | Sarad_Agarwal__MANG | NORMAL | 2025-01-30T18:50:31.834108+00:00 | 2025-01-30T18:50:31.834108+00:00 | 376 | false | # Intuition "Please make an ✨UPVOTE✨, Guys, if you like my approach and explanation... 👍 This will motivate me further in solving problems!"
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
The code follows the Sorting + Sliding Window approach.
Step-by-Step Explanation:
Edge Case Handl... | 1 | 0 | ['Array', 'Sliding Window', 'Sorting', 'Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | 🔥Minimize the Gap: Smallest Difference Between Scores🔥 | minimize-the-gap-smallest-difference-bet-0wv1 | IntuitionThe essence of the problem lies in minimizing the difference between the highest and lowest scores in a subset of size ( k ). To achieve this, we need | ghost030705 | NORMAL | 2024-12-27T05:26:27.860362+00:00 | 2024-12-27T05:26:27.860362+00:00 | 263 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The essence of the problem lies in minimizing the difference between the highest and lowest scores in a subset of size \( k \). To achieve this, we need to evaluate subsets where the scores are closely packed together, as such subsets are m... | 1 | 0 | ['C++'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Java | simple approach | java-simple-approach-by-siyadhri-0ljo | \n\n# Code\njava []\nclass Solution {\n public int minimumDifference(int[] nums, int k) {\n Arrays.sort(nums);\n int min=Integer.MAX_VALUE;\n | siyadhri | NORMAL | 2024-10-30T04:30:50.131737+00:00 | 2024-10-30T04:30:50.131763+00:00 | 269 | false | \n\n# Code\n```java []\nclass Solution {\n public int minimumDifference(int[] nums, int k) {\n Arrays.sort(nums);\n int min=Integer.MAX_VALUE;\n for(int i=0;i<nums.length-k+1;i++){\n int j=i+k-1;\n int temp=nums[j]-nums[i];\n min=Math.min(min,temp);\n }\n ... | 1 | 0 | ['Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Good Job Bro,Now Let Me Help You!! | good-job-bronow-let-me-help-you-by-yedug-spa9 | 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 | yeduganisaketh | NORMAL | 2024-04-12T02:36:47.371800+00:00 | 2024-04-12T02:36:47.371828+00:00 | 178 | 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 | ['Python3'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | [Java] Sorting, O(NlogN) , O(1) | java-sorting-onlogn-o1-by-20481a5432-4zdk | # Intuition\nDescribe your first thoughts on how to solve this problem. \n\n# Approach\n\nWe can sort the array and then compare every element at index i with | 20481A5432 | NORMAL | 2024-02-19T09:07:42.022158+00:00 | 2024-02-19T09:07:42.022213+00:00 | 478 | false | <!-- # Intuition\nDescribe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can sort the array and then compare every element at index i with the element at index **i+k-1**. Take the minimum difference of all such pairs.\n\n# Complexity\n<!... | 1 | 1 | ['Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Simple java code 5 ms beats 91 % | simple-java-code-5-ms-beats-91-by-arobh-ks6s | \n# Complexity\n- \n\n# Code\n\nclass Solution {\n public int minimumDifference(int[] arr, int k) {\n if(k==1){\n return 0;\n }\n | Arobh | NORMAL | 2023-12-27T02:53:55.715479+00:00 | 2023-12-27T02:53:55.715502+00:00 | 237 | false | \n# Complexity\n- \n\n# Code\n```\nclass Solution {\n public int minimumDifference(int[] arr, int k) {\n if(k==1){\n return 0;\n }\n int n=arr.length;\n Arrays.sort... | 1 | 0 | ['Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | mysol | mysol-by-samhitha_peddireddy-ydwa | 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 | samhitha_peddireddy | NORMAL | 2023-11-21T01:31:08.329715+00:00 | 2023-11-21T01:31:08.329740+00:00 | 71 | 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 | ['C#'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Sliding Window solution in C++ | sliding-window-solution-in-c-by-wx231-yhib | Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) | Wx231 | NORMAL | 2023-07-24T09:03:56.310747+00:00 | 2023-07-24T09:03:56.310766+00:00 | 44 | false | # Complexity\n- Time complexity: $$O(nlogn)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n if(nums.size()==1) return 0;\n sort(nums.begin(), nums.end());\n int i=0, j=k-1, result=INT_MAX;\n while(j<nums.siz... | 1 | 0 | ['Array', 'Two Pointers', 'Sliding Window', 'Sorting', 'C++'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | sliding window | sliding-window-by-dosadarsh-uvf4 | Intuition\nusing the concept of the sliding window to solve this problem\n\n# Approach\nin the approach we have take two index pointer head , tail\nhead used to | dosadarsh | NORMAL | 2023-07-14T05:44:35.392097+00:00 | 2023-07-14T05:44:35.392130+00:00 | 54 | false | # Intuition\nusing the concept of the sliding window to solve this problem\n\n# Approach\nin the approach we have take two index pointer head , tail\nhead used to decribe the current window last element and tail decribe the last window element\n\n# Complexity\n- Time complexity:\n\n\n- Space complexity:\n<!-- Add your ... | 1 | 0 | ['C++'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | nlogn | nlogn-by-pathaksanjeev38-h1n0 | \n\n# Code\n\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums.sort() # we sort the element\n l,r = 0,k-1\ | pathaksanjeev38 | NORMAL | 2023-06-26T06:14:29.105139+00:00 | 2023-06-26T06:14:29.105175+00:00 | 18 | false | \n\n# Code\n```\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums.sort() # we sort the element\n l,r = 0,k-1\n res = float("inf")\n\n while r < len(nums):\n res = min(res,nums[r]-nums[l])\n l,r = l+1,r+1\n return res\n\n# t... | 1 | 0 | ['Python3'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | one liner, sort + sliding window | one-liner-sort-sliding-window-by-7ffffff-rol0 | Code\n\n# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef minimum_difference(nums, k)\n return nums.sort.each_cons(k).map{|s| s.last-s. | 7fffffff | NORMAL | 2023-05-29T07:36:41.382985+00:00 | 2023-05-29T07:37:06.522751+00:00 | 13 | false | # Code\n```\n# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef minimum_difference(nums, k)\n return nums.sort.each_cons(k).map{|s| s.last-s.first}.min\nend\n\n``` | 1 | 0 | ['Sliding Window', 'Ruby'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Java easy solution 100% faster || beats 100%. | java-easy-solution-100-faster-beats-100-yj5bb | 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 | tausif_02 | NORMAL | 2023-05-07T17:46:03.332952+00:00 | 2023-05-07T17:46:03.333070+00:00 | 88 | 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 | ['Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | It's my fu**ing code... Beat 100 % .... Wanna learn something New Today ????? | its-my-fuing-code-beat-100-wanna-learn-s-vp1p | Intuition\n:: Sorting and pointers\n\n# Approach\n\ni.e for {1,3,4,6,7,8},and k=3 ;\ncompae difference of :: (1,4),(3,6),(4,7),(6,8).. just this is enough\n// s | Eun_ha | NORMAL | 2023-04-07T18:35:19.464487+00:00 | 2023-04-07T18:35:19.464537+00:00 | 24 | false | # Intuition\n**:: Sorting and pointers**\n\n# Approach\n<first sort and than compare the difference of the boundary elements for the window of k consecutive elements >\ni.e for {1,3,4,6,7,8},and k=3 ;\ncompae difference of :: (1,4),(3,6),(4,7),(6,8).. just this is enough\n// so our ans will min of(ans , diff(right boun... | 1 | 0 | ['Sorting', 'C++'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Minimum Difference Between Highest and Lowest of K Scores | minimum-difference-between-highest-and-l-1qz0 | Intuition\n Describe your first thoughts on how to solve this problem. \nusing list append method and two pointer algorithm\n\n# Approach\n Describe your approa | vengateshk18 | NORMAL | 2023-03-31T08:26:04.773346+00:00 | 2023-03-31T08:26:04.773381+00:00 | 179 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nusing list append method and two pointer algorithm\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\ntwo pointer algorithm\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nn... | 1 | 0 | ['Two Pointers', 'Python3'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | C Solution | c-solution-by-ychencs-r0hn | Intuition\n- Sort\n- Compare i and i + k - 1, which is the Difference Between Highest and Lowest of K Scores\n Describe your first thoughts on how to solve this | ychencs | NORMAL | 2023-02-21T14:32:17.429697+00:00 | 2023-02-21T14:32:17.429748+00:00 | 48 | false | # Intuition\n- Sort\n- Compare `i` and `i + k - 1`, which is the Difference Between Highest and Lowest of K Scores\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Quick sort\n2. For loop:\nCompare `i` and `i + k - 1`, choose the minimum one\n<!-- Describe your approach to solving ... | 1 | 0 | ['C'] | 1 |
minimum-difference-between-highest-and-lowest-of-k-scores | Easy Sliding Window C++ | easy-sliding-window-c-by-divyansh_mishra-ezzv | 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 | Divyansh_Mishra10 | NORMAL | 2023-02-12T15:19:58.869005+00:00 | 2023-02-12T15:19:58.869031+00:00 | 827 | 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)$$ -->\nO(n.log(n))\n- Space complexity:\n<!-- Add your space complexity here, e.g. ... | 1 | 0 | ['Sliding Window', 'Python', 'C++', 'Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | [Accepted] Swift | accepted-swift-by-vasilisiniak-zt5o | \nclass Solution {\n func minimumDifference(_ nums: [Int], _ k: Int) -> Int {\n \n let nu = nums.sorted()\n var mi = Int.max\n \n | vasilisiniak | NORMAL | 2023-01-13T09:03:26.806991+00:00 | 2023-01-13T09:03:26.807025+00:00 | 61 | false | ```\nclass Solution {\n func minimumDifference(_ nums: [Int], _ k: Int) -> Int {\n \n let nu = nums.sorted()\n var mi = Int.max\n \n for i in 0...(nu.count - k) {\n mi = min(mi, nu[i + k - 1] - nu[i])\n }\n \n return mi\n }\n}\n``` | 1 | 0 | ['Swift'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Sorting followed by Sliding Window Approach | sorting-followed-by-sliding-window-appro-qeyl | 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 | dev_007_fun | NORMAL | 2022-12-29T07:36:05.933746+00:00 | 2022-12-29T07:36:05.933775+00:00 | 21 | 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 | ['Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Python 99.70% time solution (beginner friendly) | python-9970-time-solution-beginner-frien-5nh4 | \n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nSort the input array first so it is easier to work with, then implement sliding w | Bread0307 | NORMAL | 2022-12-27T06:09:47.866882+00:00 | 2022-12-27T06:09:47.866927+00:00 | 581 | false | \n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSort the input array first so it is easier to work with, then implement sliding window ap... | 1 | 0 | ['Sliding Window', 'Sorting', 'Python3'] | 1 |
minimum-difference-between-highest-and-lowest-of-k-scores | Python 3 || C++ || O(nlogn) || Easy Solution | python-3-c-onlogn-easy-solution-by-sagar-k8me | Python 3:\n\tclass Solution:\n\t\tdef minimumDifference(self, nums: List[int], k: int) -> int:\n\t\t\tnums.sort()\n\t\t\tl, r = 0, k-1\n\t\t\tres = float("inf") | sagarhasan273 | NORMAL | 2022-11-11T15:23:45.324145+00:00 | 2022-11-11T15:23:45.324186+00:00 | 77 | false | ## Python 3:\n\tclass Solution:\n\t\tdef minimumDifference(self, nums: List[int], k: int) -> int:\n\t\t\tnums.sort()\n\t\t\tl, r = 0, k-1\n\t\t\tres = float("inf")\n\n\t\t\twhile r < len(nums):\n\t\t\t\tres = min(res, nums[r] - nums[l])\n\t\t\t\tl, r = l+1, r+1\n\n\t\t\treturn res\n\n## C++:\n\n\tclass Solution {\n\tpu... | 1 | 0 | ['C', 'Python'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Best Easy approach || 96.84% Beat || Python | best-easy-approach-9684-beat-python-by-k-3aj4 | Intuition\nSorting\n\n# Approach\nSliding Window\n\n# Complexity\n- Time complexity:\nO(NlogN)\n\n- Space complexity:\nO(K)\n\n# Code\n\nimport math\nclass Solu | k_shark_ocean | NORMAL | 2022-11-08T06:37:53.526430+00:00 | 2022-11-08T06:37:53.526476+00:00 | 155 | false | # Intuition\nSorting\n\n# Approach\nSliding Window\n\n# Complexity\n- Time complexity:\nO(NlogN)\n\n- Space complexity:\nO(K)\n\n# Code\n```\nimport math\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n lst=[]\n res=math.inf\n nums.sort()\n for i in range(... | 1 | 0 | ['Python3'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | 🎊 Python | O(n log(n) ) | Sort and traverse 🎊 | python-on-logn-sort-and-traverse-by-neos-ximh | Solution \nPlease upvote if you liked it :)\n1. Here, we sort the array first : O(nlogn)\n2. Then we just look compare difference between: [i-(k-1)] and [i] : | neosh11 | NORMAL | 2022-10-09T04:28:56.663048+00:00 | 2022-10-09T04:28:56.663085+00:00 | 14 | false | # Solution \n**Please upvote if you liked it :)**\n1. Here, we sort the array first : O(nlogn)\n2. Then we just look compare difference between: [i-(k-1)] and [i] : O(n)\n\nTotal complexity is O( n log(n) ) \n\n```\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n \n if... | 1 | 0 | [] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | java 4ms | java-4ms-by-anujrohitkumar3010-qcmh | Here is my code \n\nclass Solution {\n public int minimumDifference(int[] nums, int k) {\n int n=nums.length;\n if(k>n ) return -1;\n Ar | anujrohitkumar3010 | NORMAL | 2022-09-08T20:37:38.336237+00:00 | 2022-09-08T20:39:06.688102+00:00 | 219 | false | Here is my code \n```\nclass Solution {\n public int minimumDifference(int[] nums, int k) {\n int n=nums.length;\n if(k>n ) return -1;\n Arrays.sort(nums);\n int min =nums[k-1]-nums[0];\n for(int i=1;i+k-1<n;i++)\n min=Math.min(min,nums[i+k-1]-nums[i]);\n \n ... | 1 | 0 | ['Java'] | 1 |
minimum-difference-between-highest-and-lowest-of-k-scores | ✅✅Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-38ww | Approach 1 :- Using Sorting\n\n Time Complexity :- O(NlogN)\n\n Space Complexity :- O(1)\n\n\nclass Solution {\npublic:\n \n int minimumDifference(vector< | __KR_SHANU_IITG | NORMAL | 2022-09-02T11:01:45.849207+00:00 | 2022-09-02T11:01:45.849257+00:00 | 674 | false | * ***Approach 1 :- Using Sorting***\n\n* ***Time Complexity :- O(NlogN)***\n\n* ***Space Complexity :- O(1)***\n\n```\nclass Solution {\npublic:\n \n int minimumDifference(vector<int>& nums, int k) {\n \n // sort the array\n \n sort(nums.begin(), nums.end());\n \n int min... | 1 | 0 | ['C', 'Sorting', 'C++'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | C++ | Easy | Simple | c-easy-simple-by-akshat0610-rvtj | \nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) \n {\n sort(nums.begin(),nums.end(),greater<int>()); //sort\n \n | akshat0610 | NORMAL | 2022-08-31T11:34:22.967486+00:00 | 2022-08-31T11:34:22.967534+00:00 | 715 | false | ```\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) \n {\n sort(nums.begin(),nums.end(),greater<int>()); //sort\n \n int ans=INT_MAX;\n\n for(int i=0;i<nums.size();i++)\n {\n if(i<k)\n {\n if(i==(k-1)) //first actula size of ... | 1 | 0 | ['C', 'Sliding Window', 'C++'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | short | easy python code | short-easy-python-code-by-ayushigupta240-pcca | \ndef minimumDifference(self, nums: List[int], k: int) -> int:\n n=len(nums)\n if n==1 or k==1:\n return 0\n nums=sorted(nums)\n | ayushigupta2409 | NORMAL | 2022-08-29T12:51:29.178172+00:00 | 2022-08-29T12:51:29.178211+00:00 | 114 | false | ```\ndef minimumDifference(self, nums: List[int], k: int) -> int:\n n=len(nums)\n if n==1 or k==1:\n return 0\n nums=sorted(nums)\n least=nums[k-1]-nums[0]\n for j in range(1,n-k+1):\n least=min(least,nums[j+k-1]-nums[j])\n return least\n``` | 1 | 0 | ['Python', 'Python3'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Python | Sliding Window | O(nlogn) | python-sliding-window-onlogn-by-aryonbe-8zg6 | ```\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums.sort()\n cur = float(\'inf\')\n for i in rang | aryonbe | NORMAL | 2022-07-27T12:36:05.551538+00:00 | 2022-07-27T12:36:05.551571+00:00 | 277 | false | ```\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums.sort()\n cur = float(\'inf\')\n for i in range(len(nums)-k+1):\n cur = min(cur, nums[i+k-1]-nums[i])\n | 1 | 0 | ['Python'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Faster than 89.9% java submission easy understandable java code | faster-than-899-java-submission-easy-und-0fz9 | class Solution {\n public int minimumDifference(int[] nums, int k) {\n if(k==0)\n return 0;\n Arrays.sort(nums);\n int n = nums.leng | chirag_0401 | NORMAL | 2022-07-07T04:13:20.736981+00:00 | 2022-07-07T04:13:20.737033+00:00 | 230 | false | class Solution {\n public int minimumDifference(int[] nums, int k) {\n if(k==0)\n return 0;\n Arrays.sort(nums);\n int n = nums.length,i=0,mn=Integer.MAX_VALUE;\n \n for(i=0;i<=n-k;i++)\n {\n mn = Math.min(mn,nums[i+k-1]-nums[i]);\n \n }\n ... | 1 | 0 | ['Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Simple sliding window || easy to understand || c++ | simple-sliding-window-easy-to-understand-olbj | \n int minimumDifference(vector& nums, int k) {\n sort(nums.begin(),nums.end()) ;\n int i=0,j=0;\n int mini=INT_MAX;\n while(j<nums | Akshay1054 | NORMAL | 2022-05-23T15:01:31.982119+00:00 | 2022-05-23T15:01:31.982160+00:00 | 91 | false | \n int minimumDifference(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end()) ;\n int i=0,j=0;\n int mini=INT_MAX;\n while(j<nums.size()){\n if(j-i+1<k) j++;\n else if(j-i+1==k){\n int val=nums[j]-nums[i];\n if(val<mini) mini=val;\n... | 1 | 0 | ['C', 'Sliding Window'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | C++|Sort and Sliding Window|O(nlogn) Time Complexity | csort-and-sliding-windowonlogn-time-comp-in68 | \nint minimumDifference(vector<int>& nums, int k) {\n if(k == 1)\n return 0;\n sort(nums.begin(),nums.end());\n int max1 = nums[ | aniket212 | NORMAL | 2022-05-09T12:06:55.844250+00:00 | 2022-05-14T04:37:31.221389+00:00 | 136 | false | ```\nint minimumDifference(vector<int>& nums, int k) {\n if(k == 1)\n return 0;\n sort(nums.begin(),nums.end());\n int max1 = nums[k - 1] , min1 = nums[0];\n int ans = max1 - min1;\n for(int i = k ; i < nums.size() ; i++){\n max1 = nums[i];\n min1 = nu... | 1 | 0 | ['Array', 'Sliding Window'] | 1 |
minimum-difference-between-highest-and-lowest-of-k-scores | C++ | O(nlogn) time O(1) space | 14ms faster than 90% | 13.6MB less than 96% | c-onlogn-time-o1-space-14ms-faster-than-u4h51 | Runtime: 14 ms, faster than 90.53% of C++ online submissions for Minimum Difference Between Highest and Lowest of K Scores.\nMemory Usage: 13.6 MB, less than 96 | nguyenchiemminhvu | NORMAL | 2022-04-27T16:21:49.380174+00:00 | 2022-04-27T16:22:12.030134+00:00 | 45 | false | Runtime: 14 ms, faster than 90.53% of C++ online submissions for Minimum Difference Between Highest and Lowest of K Scores.\nMemory Usage: 13.6 MB, less than 96.30% of C++ online submissions for Minimum Difference Between Highest and Lowest of K Scores.\n\n```\nclass Solution \n{\npublic:\n int minimumDifference(vec... | 1 | 0 | [] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | ☕ Java - 8ms - Sliding Wndow - Explanation - O(NLogN) | java-8ms-sliding-wndow-explanation-onlog-l8ok | The trick to solving this problem is realizing that we don\'t actually need to find the difference of every number within a subset of numbers of size k. Given a | rar349 | NORMAL | 2022-04-24T19:01:49.507630+00:00 | 2022-04-24T19:02:58.814356+00:00 | 273 | false | The trick to solving this problem is realizing that we don\'t actually need to find the difference of every number within a subset of numbers of size k. Given a subset of size k, we only need to find the difference of the highest and lowest number.\n\nWith the above logic, it makes the most sense to start by **sorting ... | 1 | 0 | ['Sliding Window', 'Sorting', 'Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Python Easiest Solution | 96.98 % Faster | Sliding Window | Beg To adv | python-easiest-solution-9698-faster-slid-b4j8 | python\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums.sort()\n l, r = 0, k-1\n \n min_dif | rlakshay14 | NORMAL | 2022-04-15T20:41:51.631140+00:00 | 2022-04-15T20:41:51.631180+00:00 | 385 | false | ```python\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums.sort()\n l, r = 0, k-1\n \n min_diff = float(\'inf\') # max out possible value\n \n while r < len(nums):\n min_diff = min(min_diff, nums[r] - nums[l])\n l, ... | 1 | 0 | ['Sliding Window', 'Python', 'Python3'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | c++ sliding window | c-sliding-window-by-me_abhi_2511-mf82 | class Solution {\npublic:\n\n int minimumDifference(vector& nums, int k) {\n sort(nums.begin(),nums.end());\n int mx=INT_MAX;\n int i=0, | me_abhi_2511 | NORMAL | 2022-04-11T16:14:04.771799+00:00 | 2022-04-11T16:14:04.771830+00:00 | 130 | false | class Solution {\npublic:\n\n int minimumDifference(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int mx=INT_MAX;\n int i=0,j=0;\n while(j<nums.size())\n {\n if(j-i+1<k)\n j++;\n if(j-i+1==k)\n {\n mx=m... | 1 | 0 | ['C', 'Sliding Window'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | python easy fast solution | python-easy-fast-solution-by-akash795515-qi5g | class Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums.sort()\n i=0\n j=k-1\n l=[]\n while | akash795515 | NORMAL | 2022-04-11T06:13:07.321285+00:00 | 2022-04-11T06:13:07.321317+00:00 | 59 | false | class Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n nums.sort()\n i=0\n j=k-1\n l=[]\n while j<len(nums):\n b=nums[j]-nums[i]\n l.append(b)\n i+=1\n j=k-1+i\n return min(l)\n \n | 1 | 0 | ['Sliding Window'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Java | java-by-irock8929-pdpo | \nclass Solution {\n public int minimumDifference(int[] nums, int k) {\n if (k <= 1)\n return 0;\n \n Arrays.sort(nums);\n | irock8929 | NORMAL | 2022-04-06T23:10:26.147157+00:00 | 2022-04-06T23:10:26.147190+00:00 | 43 | false | ```\nclass Solution {\n public int minimumDifference(int[] nums, int k) {\n if (k <= 1)\n return 0;\n \n Arrays.sort(nums);\n int ans = Integer.MAX_VALUE;\n \n for (int i = 0; i < nums.length - k + 1; i++)\n ans = min(ans, nums[i + k - 1] - nums[i]);\n ... | 1 | 0 | [] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Easy solution || O(N) || Beats 50% of submissions | easy-solution-on-beats-50-of-submissions-3ck1 | ```\nclass Solution {\npublic:\n int minimumDifference(vector& nums, int k) {\n if(k==1)\n return 0;\n sort(nums.begin(),nums.end()) | Shristha | NORMAL | 2022-03-30T14:21:28.030916+00:00 | 2022-03-30T14:21:28.030953+00:00 | 193 | false | ```\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n if(k==1)\n return 0;\n sort(nums.begin(),nums.end());\n int res;\n res=(nums[k-1]-nums[0]);\n for(int i=k;i<nums.size();i++){\n res=min(res,(nums[i]-nums[i-(k-1)]));\n ... | 1 | 0 | ['C', 'C++'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Java | 0ms | Efficient Solution | Using Sliding Window | java-0ms-efficient-solution-using-slidin-ksqp | class Solution {\n public int minimumDifference(int[] nums, int k) {\n \n \n //Sliding Window\n \n if(nums.length == 1)\n | ishashank | NORMAL | 2022-03-22T14:38:14.236240+00:00 | 2022-03-22T14:38:14.236292+00:00 | 141 | false | class Solution {\n public int minimumDifference(int[] nums, int k) {\n \n \n //Sliding Window\n \n if(nums.length == 1)\n return 0;\n \n Arrays.sort(nums);\n \n int diff = Integer.MAX_VALUE;\n \n for(int i = k - 1; i < nums.lengt... | 1 | 0 | ['Sliding Window', 'Java'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | Python3 | python3-by-excellentprogrammer-kftb | \nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n a=float(\'inf\')\n s=[]\n b=sorted(nums)\n for | ExcellentProgrammer | NORMAL | 2022-03-20T10:12:44.360375+00:00 | 2022-03-20T10:12:44.360415+00:00 | 45 | false | ```\nclass Solution:\n def minimumDifference(self, nums: List[int], k: int) -> int:\n a=float(\'inf\')\n s=[]\n b=sorted(nums)\n for i in range(k-1,len(b)):\n if b[i]-b[i-k+1]<a:\n s.append(b[i]-b[i-k+1])\n return min(s)\n``` | 1 | 0 | [] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | C++ | Simple solution | c-simple-solution-by-riteshkhan-vdhp | \nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int l = nums.size();\n if(l==1) return 0;\n sort(nums. | RiteshKhan | NORMAL | 2022-03-15T05:57:35.096170+00:00 | 2022-03-15T05:57:35.096220+00:00 | 99 | false | ```\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n int l = nums.size();\n if(l==1) return 0;\n sort(nums.begin(), nums.end());\n int i=0, m = INT_MAX,p;\n while((i<l)&&(i+k-1 <l)){\n p = nums[i+k-1]-nums[i];\n m = min(m,p);\n ... | 1 | 0 | ['C'] | 0 |
minimum-difference-between-highest-and-lowest-of-k-scores | C++ beginner friendly | c-beginner-friendly-by-richach10-aez1 | \nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n \n sort(nums.begin(),nums.end(), greater<int>());\n \n | Richach10 | NORMAL | 2022-03-08T17:47:25.939415+00:00 | 2022-03-08T17:47:25.939450+00:00 | 151 | false | ```\nclass Solution {\npublic:\n int minimumDifference(vector<int>& nums, int k) {\n \n sort(nums.begin(),nums.end(), greater<int>());\n \n int i=0,j=k-1;\n int mini=INT_MAX;\n int res=0;\n while(j<nums.size())\n {\n mini=min(mini,nums[i]-nums[j]);\n... | 1 | 0 | ['C', 'C++'] | 0 |
set-matrix-zeroes | Any shorter O(1) space solution? | any-shorter-o1-space-solution-by-mzchen-45mk | My idea is simple: store states of each row in the first of that row, and store states of each column in the first of that column. Because the state of row0 and | mzchen | NORMAL | 2014-11-13T06:03:08+00:00 | 2024-02-14T07:40:17.985101+00:00 | 200,983 | false | My idea is simple: store states of each row in the first of that row, and store states of each column in the first of that column. Because the state of row0 and the state of column0 would occupy the same cell, I let it be the state of row0, and use another variable `col0` for column0. In the first phase, use matrix ele... | 1,936 | 17 | ['C++'] | 133 |
set-matrix-zeroes | ✅☑️ Best C++ 4 solution || Hash Table || Matrix || Brute Force -> Optimize || One Stop Solution. | best-c-4-solution-hash-table-matrix-brut-xwgo | Intuition\n Describe your first thoughts on how to solve this problem. \nWe can solve this problem using Four approaches. (Here I have explained all the possibl | its_vishal_7575 | NORMAL | 2023-02-11T17:44:27.247935+00:00 | 2023-02-11T17:44:27.247964+00:00 | 109,662 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can solve this problem using Four approaches. (Here I have explained all the possible solutions of this problem).\n\n1. Solved using Matrix with Extra space. TC : O((N*M)*(N+M)), SC : O(N*M).\n2. Solved using Matrix with Constant spa... | 1,005 | 2 | ['Array', 'Hash Table', 'Matrix', 'C++'] | 27 |
set-matrix-zeroes | My AC java O(1) solution (easy to read) | my-ac-java-o1-solution-easy-to-read-by-l-scc7 | public class Solution {\n public void setZeroes(int[][] matrix) {\n boolean fr = false,fc = false;\n for(int i = 0; i < matrix.length; i++) {\n | lz2343 | NORMAL | 2015-06-01T09:05:32+00:00 | 2018-10-25T19:58:56.410965+00:00 | 83,238 | false | public class Solution {\n public void setZeroes(int[][] matrix) {\n boolean fr = false,fc = false;\n for(int i = 0; i < matrix.length; i++) {\n for(int j = 0; j < matrix[0].length; j++) {\n if(matrix[i][j] == 0) {\n if(i == 0) fr = true;\n ... | 560 | 6 | [] | 30 |
set-matrix-zeroes | Full Explanation || Super easy || constant space | full-explanation-super-easy-constant-spa-teim | Intuition\nIn this approach, we can just improve the space complexity. So, instead of using two extra matrices row and col, we will use the 1st row and 1st colu | raunakkodwani | NORMAL | 2023-05-01T06:59:26.835480+00:00 | 2023-05-01T06:59:26.835515+00:00 | 53,816 | false | # Intuition\nIn this approach, we can just improve the space complexity. So, instead of using two extra matrices row and col, we will use the 1st row and 1st column of the given matrix to keep a track of the cells that need to be marked with 0. But here comes a problem. If we try to use the 1st row and 1st column to se... | 491 | 0 | ['Java'] | 16 |
set-matrix-zeroes | All approaches from brute force to optimal with easy explanation | all-approaches-from-brute-force-to-optim-t9mb | Method 1: (Brute force)\n-using another matrix (let\'s say it matrix2)\n1. we can copy all the elements of given matrix to matrix2\n2. while traversing given ma | pranjulagrawal9 | NORMAL | 2022-09-03T17:04:22.574240+00:00 | 2023-08-02T06:46:54.957971+00:00 | 37,073 | false | **Method 1:** (Brute force)\n-using another matrix (let\'s say it matrix2)\n1. we can copy all the elements of given matrix to matrix2\n2. while traversing given matrix whenever we encounter 0, we will make the entire row and column of the matrix2 to 0\n3. finally we can again copy all the elements of matrix2 to given ... | 465 | 1 | ['Array', 'Matrix', 'C++', 'Java'] | 16 |
set-matrix-zeroes | 【Video】O(1) space - Use the first row and column as a note. | video-o1-space-use-the-first-row-and-col-1kr7 | Intuition\nUse the first row and column as a note.\n\n---\n\n# Solution Video\n\nhttps://youtu.be/24Q1BR7gL2g\n\n### \u2B50\uFE0F\u2B50\uFE0F Don\'t forget to s | niits | NORMAL | 2024-12-07T01:16:38.881143+00:00 | 2024-12-07T01:16:38.881168+00:00 | 27,003 | false | # Intuition\nUse the first row and column as a note.\n\n---\n\n# Solution Video\n\nhttps://youtu.be/24Q1BR7gL2g\n\n### \u2B50\uFE0F\u2B50\uFE0F Don\'t forget to subscribe to my channel! \u2B50\uFE0F\u2B50\uFE0F\n\n**\u25A0 Subscribe URL**\nhttp://www.youtube.com/channel/UC9RMNwYTL3SXCP6ShLWVFww?sub_confirmation=1\n\nSu... | 244 | 0 | ['Array', 'Matrix', 'C++', 'Java', 'Python3'] | 1 |
set-matrix-zeroes | Python Solution w/ approach explanation & readable with space progression from: O(m+n) & O(1) | python-solution-w-approach-explanation-r-vh4j | Note: m = number of rows, n = number of cols\n\nBrute force using O(m*n) space: The initial approach is to start with creating another matrix to store the resul | cmeow | NORMAL | 2020-05-28T19:11:19.813141+00:00 | 2020-05-28T19:13:17.820082+00:00 | 33,671 | false | Note: m = number of rows, n = number of cols\n\n**Brute force using O(m*n) space:** The initial approach is to start with creating another matrix to store the result. From doing that, you\'ll notice that we want a way to know when each row and col should be changed to zero. We don\'t want to prematurely change the valu... | 244 | 2 | ['Python', 'Python3'] | 17 |
set-matrix-zeroes | 21 lines concise and easy understand C++ solution, O(1) space, three steps | 21-lines-concise-and-easy-understand-c-s-nhqj | class Solution {\n public:\n void setZeroes(vector<vector<int>>& matrix) {\n bool row = false, col = false;\n for(int i = 0; i < | allen231x | NORMAL | 2016-01-28T14:46:57+00:00 | 2018-10-23T02:21:00.261787+00:00 | 22,083 | false | class Solution {\n public:\n void setZeroes(vector<vector<int>>& matrix) {\n bool row = false, col = false;\n for(int i = 0; i < matrix.size(); i++){\n for(int j = 0; j < matrix[0].size(); j++){\n if(matrix[i][j] == 0) {\n if(i... | 156 | 2 | [] | 8 |
set-matrix-zeroes | ✅Set Matrix Zeroes || 2 Approach w/ Explanation || C++ | Python | Java | set-matrix-zeroes-2-approach-w-explanati-hfd6 | OBSERVATION:\nThe time complexity of this problem remains O(M*N), the only improvement we can do is of the space complexity. So we will have 2 approaches here\n | Maango16 | NORMAL | 2021-08-13T07:38:57.933600+00:00 | 2021-08-13T07:38:57.933661+00:00 | 9,989 | false | **OBSERVATION:**\nThe time complexity of this problem remains `O(M*N)`, the only improvement we can do is of the space complexity. So we will have 2 approaches here\n\n# **APPROACH I:**\n*Additional Memory Approach-*\nIf any cell of the matrix has a zero we can record its row and column number. All the cells of this re... | 139 | 2 | [] | 8 |
set-matrix-zeroes | CPP||C++||99.23%||Google||Amazon | cppc9923googleamazon-by-rupakpro107-wnvz | Approach-First of all create two vectors rowmarker and columnmarker to store the positions of column and row where the element is zero. \nIf element in either r | rupakpro107 | NORMAL | 2020-07-03T08:31:58.849547+00:00 | 2020-07-03T18:52:15.649752+00:00 | 10,587 | false | Approach-First of all create two vectors rowmarker and columnmarker to store the positions of column and row where the element is zero. \nIf element in either row marker or columnmarker is 0.Then make the element in the whole matrix 0. \n```\n void setZeroes(vector<vector<int>>& matrix) { \n int rowsize=matr... | 101 | 23 | ['C', 'C++'] | 6 |
set-matrix-zeroes | C++ | Simple | 99% Faster | O(1) Space | Upvote | c-simple-99-faster-o1-space-upvote-by-v4-7o4x | \n void setZeroes(vector<vector<int>>& a) {\n int n = a.size();\n int m = a[0].size();\n bool firstRow = false; // do we need to set fi | v4vijay | NORMAL | 2021-06-16T09:52:38.299354+00:00 | 2021-06-16T09:52:38.299386+00:00 | 12,635 | false | ```\n void setZeroes(vector<vector<int>>& a) {\n int n = a.size();\n int m = a[0].size();\n bool firstRow = false; // do we need to set first row zero\n bool firstCol = false; // do we need to ser first col zero\n for(int i=0; i<n; i++){\n for(int j=0; j<m; j++){\n\t\t... | 96 | 1 | ['C'] | 8 |
set-matrix-zeroes | My C++ O(1) yoooooo | my-c-o1-yoooooo-by-lugiavn-t3qo | I find the last row which has 0, and use it to store the 0-collumns.\nThen go row by row set them to 0.\nThen go column by column set them to 0.\nFinally set th | lugiavn | NORMAL | 2015-01-10T18:47:20+00:00 | 2018-09-30T02:27:50.611484+00:00 | 32,639 | false | I find the last row which has 0, and use it to store the 0-collumns.\nThen go row by row set them to 0.\nThen go column by column set them to 0.\nFinally set the last row which has 0. It's long but hey it's O(1) \n\n\n class Solution {\n public:\n void setZeroes(vector<vector<int> > &matrix) {\n ... | 70 | 2 | [] | 11 |
set-matrix-zeroes | O(1) space solution in Python | o1-space-solution-in-python-by-autekwing-50gx | class Solution:\n # @param {integer[][]} matrix\n # @return {void} Do not return anything, modify matrix in-place instead.\n def setZeroes(self, matrix | autekwing | NORMAL | 2015-07-30T03:38:25+00:00 | 2018-10-10T19:19:08.682070+00:00 | 22,026 | false | class Solution:\n # @param {integer[][]} matrix\n # @return {void} Do not return anything, modify matrix in-place instead.\n def setZeroes(self, matrix):\n m = len(matrix)\n if m == 0:\n return\n n = len(matrix[0])\n \n row_zero = False\n for i in range(... | 63 | 0 | [] | 13 |
set-matrix-zeroes | [Python] O(mn)/O(1) time/space solution, explained | python-omno1-timespace-solution-explaine-a5sy | The idea is to use first row and first column as indicator, if we need to set the whole corresponding column or row to zeros. We also keep r1 andc1variables: do | dbabichev | NORMAL | 2021-08-13T07:44:07.179415+00:00 | 2021-08-13T08:33:03.946460+00:00 | 4,189 | false | The idea is to use first row and first column as indicator, if we need to set the whole corresponding column or row to zeros. We also keep `r1 and `c1` variables: do we need to update first column and/or first row in the end. So, we have the following steps:\n\n1. Create `r1` and `c1`.\n2. Iterate through our matrix an... | 61 | 2 | ['Math'] | 6 |
set-matrix-zeroes | Java/Python O(1) space 11 lines solution | javapython-o1-space-11-lines-solution-by-7u82 | Java\n\n public void setZeroes(int[][] matrix) {\n int m = matrix.length, n = matrix[0].length, k = 0;\n // First row has zero?\n while | dietpepsi | NORMAL | 2015-11-19T18:06:40+00:00 | 2018-08-09T19:07:21.958197+00:00 | 21,131 | false | **Java**\n\n public void setZeroes(int[][] matrix) {\n int m = matrix.length, n = matrix[0].length, k = 0;\n // First row has zero?\n while (k < n && matrix[0][k] != 0) ++k;\n // Use first row/column as marker, scan the matrix\n for (int i = 1; i < m; ++i)\n for (int j =... | 51 | 2 | ['Python', 'Java'] | 12 |
set-matrix-zeroes | [Python] From O(M+N) space to O(1) space - with Picture - Clean & Concise | python-from-omn-space-to-o1-space-with-p-8jnv | Solution 1: Additional Memory Space\n- Let zeroRow[r] = True denote all the cells in row r must have value 0.\n- Let zeroCol[c] = True denote all the cells in c | hiepit | NORMAL | 2021-09-17T15:55:52.526541+00:00 | 2021-09-17T17:15:23.668938+00:00 | 1,756 | false | **Solution 1: Additional Memory Space**\n- Let `zeroRow[r] = True` denote all the cells in row `r` must have value 0.\n- Let `zeroCol[c] = True` denote all the cells in column `c` must have value 0.\n```python\nclass Solution:\n def setZeroes(self, matrix: List[List[int]]) -> None:\n m, n = len(matrix), len(m... | 48 | 0 | [] | 4 |
set-matrix-zeroes | My JAVA solution, easy to understand | my-java-solution-easy-to-understand-by-k-au4f | public void setZeroes(int[][] matrix) {\n int m=matrix.length;\n int n=matrix[0].length;\n int[] row = new int[m];\n int[] col = new | knighty | NORMAL | 2015-09-01T20:36:12+00:00 | 2015-09-01T20:36:12+00:00 | 5,214 | false | public void setZeroes(int[][] matrix) {\n int m=matrix.length;\n int n=matrix[0].length;\n int[] row = new int[m];\n int[] col = new int[n];\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n if(matrix[i][j]==0){\n row[i]=1;\n ... | 43 | 6 | ['Java'] | 7 |
set-matrix-zeroes | O(1) JAVA, straightforward idea | o1-java-straightforward-idea-by-januarui-1c1l | Use the first column and the first row as marker:\n1. first scan through the whole matrix, and if one row i has zero, label matrix[i][0] = 0, if column j has ze | januarui | NORMAL | 2015-10-16T06:06:26+00:00 | 2015-10-16T06:06:26+00:00 | 14,711 | false | Use the first column and the first row as marker:\n1. first scan through the whole matrix, and if one row i has zero, label matrix[i][0] = 0, if column j has zero, then label matrix[0][j] = 0.\nif we find the first row has zero, then mark a boolean row = true, if the first column has zeros, mark a boolean col = true;\n... | 40 | 1 | [] | 4 |
set-matrix-zeroes | ✅ 🔥 0 ms Runtime Beats 100% User🔥|| Code Idea ✅ || Algorithm & Solving Step ✅ || | 0-ms-runtime-beats-100-user-code-idea-al-ul63 | \n\n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n\n\n### Key Idea :\n1. Marking Rows and Columns:\n - Use the first row and the fir | Letssoumen | NORMAL | 2024-11-30T08:14:17.796414+00:00 | 2024-11-30T08:14:17.796475+00:00 | 5,535 | false | \n\n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n\n\n### **Key Idea** :\n1. **Marking Rows and Columns**:\n - Use the first row and the first ... | 39 | 1 | ['Array', 'Hash Table', 'Matrix', 'C++', 'Java', 'Python3'] | 1 |
set-matrix-zeroes | My java O(1) solution (easy to understand) | my-java-o1-solution-easy-to-understand-b-80nl | public class Solution {\n public void setZeroes(int[][] matrix) {\n if(matrix==null){\n return;\n }\n \n | xiangru_wang | NORMAL | 2015-02-13T00:27:48+00:00 | 2018-09-25T02:23:37.815620+00:00 | 18,187 | false | public class Solution {\n public void setZeroes(int[][] matrix) {\n if(matrix==null){\n return;\n }\n \n int m = matrix.length;\n int n = matrix[0].length;\n \n boolean rowHasZero = false;\n boolean colHasZ... | 39 | 7 | [] | 4 |
set-matrix-zeroes | Python solution using set | beats 100% | python-solution-using-set-beats-100-by-r-ba2w | \nclass Solution:\n def setZeroes(self, matrix: List[List[int]]) -> None:\n """\n Do not return anything, modify matrix in-place instead.\n | rougef4ak | NORMAL | 2020-04-20T12:37:18.575694+00:00 | 2020-04-20T12:37:18.575726+00:00 | 4,877 | false | ```\nclass Solution:\n def setZeroes(self, matrix: List[List[int]]) -> None:\n """\n Do not return anything, modify matrix in-place instead.\n """\n row = set()\n column = set()\n \n for i in range(len(matrix)):\n for j in range(len(matrix[0])):\n ... | 36 | 3 | ['Ordered Set', 'Python', 'Python3'] | 9 |
set-matrix-zeroes | Java easy to understand O(1) space solution with 2 passes | java-easy-to-understand-o1-space-solutio-8qlp | public class Solution {\n \n public void setZeroes(int[][] matrix) {\n if(matrix==null || matrix.length==0){\n return;\n }\n | krzykid | NORMAL | 2016-02-17T04:55:48+00:00 | 2018-08-14T04:38:15.208627+00:00 | 7,692 | false | public class Solution {\n \n public void setZeroes(int[][] matrix) {\n if(matrix==null || matrix.length==0){\n return;\n }\n \n boolean setFirstRowToZeroes = false;\n boolean setFirstColumnToZeroes = false;\n \n //check if first column needs to be se... | 34 | 3 | ['Java'] | 6 |
set-matrix-zeroes | ✅ Easiest | 4 approaches | Video | Line by line explanation | Beginner Friendly | easiest-4-approaches-video-line-by-line-82747 | Mastering LeetCode 73: Set Matrix Zeroes\n\nWelcome to our deep dive into LeetCode problem 73: Set Matrix Zeroes. This problem is an excellent exercise in matri | hackcode62 | NORMAL | 2024-09-11T01:52:03.365421+00:00 | 2024-09-11T01:54:22.936644+00:00 | 2,590 | false | # Mastering LeetCode 73: Set Matrix Zeroes\n\nWelcome to our deep dive into LeetCode problem 73: Set Matrix Zeroes. This problem is an excellent exercise in matrix manipulation and optimization. We\'ll explore four different approaches, starting with a brute force solution and gradually optimizing to achieve the most e... | 32 | 0 | ['Array', 'Hash Table', 'Matrix', 'Python3'] | 1 |
set-matrix-zeroes | [Python3] O(1) with reverse traversal | python3-o1-with-reverse-traversal-by-you-tr9y | Use the first cell of every row and column as a flag if all row or col values should be set to zeros.\nColumn with index 0 => matrix[0][j] are using like flag f | yourick | NORMAL | 2023-05-11T20:13:39.248577+00:00 | 2024-01-23T21:29:06.461564+00:00 | 5,563 | false | Use the first cell of every row and column as a flag if all row or col values should be set to zeros.\nColumn with index `0 => matrix[0][j]` are using like flag for `rows`.\nRow with index `0 => matrix[i][0]` are using like flag for columns.\nBut because the cell `matrix[0][0]` already are using like flag for `0` row ... | 27 | 0 | ['Matrix', 'Python', 'Python3'] | 4 |
set-matrix-zeroes | Javascript Fast and Simple | javascript-fast-and-simple-by-galberto80-fwtm | \nvar setZeroes = function(matrix) {\n\n var track = []\n \n // find zeros\n for(var i = 0; i < matrix.length; i++){\n for(var j = 0; j < matri | galberto807 | NORMAL | 2020-01-31T22:18:34.179985+00:00 | 2020-01-31T22:18:34.180019+00:00 | 3,923 | false | ```\nvar setZeroes = function(matrix) {\n\n var track = []\n \n // find zeros\n for(var i = 0; i < matrix.length; i++){\n for(var j = 0; j < matrix[0].length; j++){\n if(matrix[i][j] === 0) track.push([i, j]) \n }\n }\n\n for(var i = 0; i < track.length; i++){\n va... | 23 | 0 | ['JavaScript'] | 3 |
set-matrix-zeroes | 4 APPROACHES | 4-approaches-by-pranayharishchandra-4vf4 | BRUTE FORCE\n- traverse over matrix and when you find 0\n- traverse over it\'s row and col, if you encounter 1 then change it to -1\n- after traversing over who | pranayharishchandra | NORMAL | 2024-05-23T08:31:14.927213+00:00 | 2024-05-25T04:38:40.290613+00:00 | 4,314 | false | # BRUTE FORCE\n- traverse over matrix and when you find 0\n- traverse over it\'s row and col, if you encounter 1 then change it to -1\n- after traversing over whole matrix and finding all 0, now replace the -1 with 0\n | SC: O(1) | Optimized In-Place solution | java-tc-orc-sc-o1-optimized-in-place-sol-qqo9 | java\n/**\n * Optimized In-Place solution\n *\n * We can use the first cell of every row and column as a flag. This flag will\n * determine whether a row or a c | NarutoBaryonMode | NORMAL | 2021-10-11T03:41:37.161473+00:00 | 2021-10-11T03:42:33.272776+00:00 | 1,465 | false | ```java\n/**\n * Optimized In-Place solution\n *\n * We can use the first cell of every row and column as a flag. This flag will\n * determine whether a row or a column has to be set to zero.\n *\n * Time Complexity: O(2 * R * C)\n *\n * Space Complexity: O(1)\n *\n * R = Number of rows. C = Number of columns.\n */\ncl... | 21 | 0 | ['Array', 'Matrix', 'Java'] | 1 |
set-matrix-zeroes | Simple C++ solution|| Using extra space | simple-c-solution-using-extra-space-by-a-xgq0 | If you really found my solution helpful please upvote it, as it motivates me to post such kind of codes and help the coding community, if you have some queries | anubhavbaner7 | NORMAL | 2021-08-04T17:56:51.875418+00:00 | 2021-08-04T17:56:51.875463+00:00 | 2,070 | false | **If you really found my solution helpful please upvote it, as it motivates me to post such kind of codes and help the coding community, if you have some queries or some improvements please feel free to comment and share your views.**\n```\n void setZeroes(vector<vector<int>>& matrix) {\n int m=matrix.size();... | 21 | 1 | ['C', 'C++'] | 3 |
set-matrix-zeroes | 3 sweet and simple approach. BRUTE-FORCE || OPTIMAL || PRO-OPTIMAL. | 3-sweet-and-simple-approach-brute-force-tnenv | ```\nclass Solution {\npublic:\n void setZeroes(vector>& v) {\n int x,y;\n \n /-------------BRUTE FORCE APPROACH-----------------/\n/ | lazyfool_008 | NORMAL | 2021-06-18T09:06:03.408195+00:00 | 2021-06-18T09:06:03.408239+00:00 | 2,414 | false | ```\nclass Solution {\npublic:\n void setZeroes(vector<vector<int>>& v) {\n int x,y;\n \n /*-------------BRUTE FORCE APPROACH-----------------*/\n/* \n \n int m=v.size();\n int n=v[0].size();\n int temp[m][n];\n for(int i=0;i<m;i++)\n for(int j=... | 21 | 1 | ['C'] | 2 |
set-matrix-zeroes | ✅C++ Easy Solution Optimized | c-easy-solution-optimized-by-ayushsenapa-9dsx | \n\nclass Solution {\npublic:\n void setZeroes(vector<vector<int>>& matrix) {\n int col0 = true;\n // int rows = sizeof(matrix)/sizeof(matrix[0 | ayushsenapati123 | NORMAL | 2022-06-19T13:50:08.530700+00:00 | 2022-06-19T13:50:08.530741+00:00 | 1,680 | false | \n```\nclass Solution {\npublic:\n void setZeroes(vector<vector<int>>& matrix) {\n int col0 = true;\n // int rows = sizeof(matrix)/sizeof(matrix[0]);\n int rows = matrix.size();\n // int cols = sizeof(matrix[0]/sizeof(matrix[0][0]));\n int cols = matrix[0].size();\n \n ... | 18 | 0 | ['C', 'Matrix'] | 2 |
set-matrix-zeroes | JavaScript - Three Solutions. One is Suggested Transcribed to JS. 100% | javascript-three-solutions-one-is-sugges-hfx8 | \n\n\nDoing the Blind 75 and posting all solutions.\n\nHere is the \'Suggested Solution\' transcribed to JS. Cool solution if you Have to keep constant space. | casmith1987 | NORMAL | 2021-09-22T00:37:05.028845+00:00 | 2022-03-01T20:31:29.275838+00:00 | 2,914 | false | \n\n\nDoing the Blind 75 and posting all solutions.\n\nHere is the \'Suggested Solution\' transcribed to JS. Cool solution if you Have to keep constant space. A little convoluted otherwise imo.\n```\nvar setZ... | 18 | 0 | ['JavaScript'] | 3 |
set-matrix-zeroes | Is there a better constant space solution? | is-there-a-better-constant-space-solutio-r01a | My solution is kind of hackish - accpeted. So, I want to know if there is a better constant space solution?\n\nI traverse the matrix and if I find a zero, I rep | gpraveenkumar | NORMAL | 2013-12-28T00:31:44+00:00 | 2013-12-28T00:31:44+00:00 | 10,700 | false | My solution is kind of hackish - accpeted. So, I want to know if there is a better constant space solution?\n\nI traverse the matrix and if I find a zero, I replace all the elements, except the 0 elements, of the corresponding row and column with -1. Finally I make all the -1 to 0.\n\nThis algorithm would fail if the m... | 17 | 4 | [] | 10 |
set-matrix-zeroes | Constant Space Java solution | constant-space-java-solution-by-siyang2-ki1r | a b b \n\n b c c\n\n b c c\n\nStep1: Determine row1 and col1. Need to go through the first col and first row. Use two vars to store that information.\nStep2 | siyang2 | NORMAL | 2014-10-29T18:03:27+00:00 | 2014-10-29T18:03:27+00:00 | 4,392 | false | a b b \n\n b c c\n\n b c c\n\nStep1: Determine row1 and col1. Need to go through the first col and first row. Use two vars to store that information.\nStep2: Use "c" to determine "b". Need to go through the entire matrix. Once "c" is zero, set its corresponding two "b"s to zero.\nStep3: Use "b" to set "c". If "b" ... | 17 | 2 | ['Java'] | 3 |
set-matrix-zeroes | Very Short Python Solution with O(1) Space Complexity. 13 Lines of Code. | very-short-python-solution-with-o1-space-9ii8 | Idea is as follow:\nIts only necessary to find out which row and column contains 0. After this step, change all elements in certain row and column to 0. If no 0 | sktgater | NORMAL | 2017-02-02T18:51:16.353000+00:00 | 2018-09-18T20:12:44.305593+00:00 | 2,431 | false | Idea is as follow:\nIts only necessary to find out which row and column contains 0. After this step, change all elements in certain row and column to 0. If no 0 exists, do nothing.\n\n```\n# Two sets that record which row and column has 0\nrowSet = set()\ncolSet = set()\n# Iterate each element. \n# If it is 0, record r... | 17 | 10 | [] | 5 |
set-matrix-zeroes | Quiet simple answer, \u2018hacking\u2019 with javascript | quiet-simple-answer-u2018hackingu2019-wi-84pb | var setZeroes = function(matrix) {\n\n var r = matrix.length;\n var l = matrix[0].length;\n for (var i = 0; i < r; i++) {\n for (var j = 0; j < | handsomeone | NORMAL | 2016-04-06T07:46:06+00:00 | 2016-04-06T07:46:06+00:00 | 2,165 | false | var setZeroes = function(matrix) {\n\n var r = matrix.length;\n var l = matrix[0].length;\n for (var i = 0; i < r; i++) {\n for (var j = 0; j < l; j++) {\n if (matrix[i][j] === 0 && 1 / matrix[i][j] === Infinity) {\n for (var x = 0; x < r; x++) {\n matrix[x][... | 16 | 2 | [] | 6 |
set-matrix-zeroes | PYTHON || OPTIMAL SOLUTION 🔥 || EASY TO UNDERSTAND || | python-optimal-solution-easy-to-understa-3k7a | if it\'s help, please up \u2B06vote!\u2764\uFE0F and comment\uD83D\uDD25\n# Intuition\n Describe your first thoughts on how to solve this problem. \n- When we e | Adit_gaur | NORMAL | 2024-06-30T14:54:45.824272+00:00 | 2024-06-30T14:54:45.824306+00:00 | 1,447 | false | # if it\'s help, please up \u2B06vote!\u2764\uFE0F and comment\uD83D\uDD25\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- When we encounter a zero in the matrix, the entire row and column containing that zero need to be set to zero. This can be efficiently tracked using two sets, o... | 14 | 0 | ['Array', 'Hash Table', 'Matrix', 'Python', 'Python3'] | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.