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-deletions-to-make-array-beautiful | ✅cpp easy with intuition || O(N) Time, O(1) space | cpp-easy-with-intuition-on-time-o1-space-4gn3 | ```\nINTUITION\n1. since we have to find the minimum deletions, we dont have to \n\tactually delete the elements , we just have to count those elements.\n2. Now | namanvijay814 | NORMAL | 2022-03-27T04:08:38.169631+00:00 | 2022-03-27T04:37:23.114091+00:00 | 1,257 | false | ```\nINTUITION\n1. since we have to find the minimum deletions, we dont have to \n\tactually delete the elements , we just have to count those elements.\n2. Now if we delete the element and shift all the elements towards left , it will\n\tcause time limit exceeded.\n3. To handle above case we can observe one thing tha... | 19 | 1 | ['Greedy', 'C'] | 7 |
minimum-deletions-to-make-array-beautiful | C++ / Java || With explanation O(1) space | c-java-with-explanation-o1-space-by-kami-odif | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n \n int deletion(0), n(size(nums));\n \n for (int i=0; i<n-1; | kamisamaaaa | NORMAL | 2022-03-27T04:01:34.169232+00:00 | 2022-03-27T05:14:03.265486+00:00 | 1,384 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n \n int deletion(0), n(size(nums));\n \n for (int i=0; i<n-1; ) {\n int newIndex = i-deletion; // index will alter by number of deletions done.\n if ((newIndex % 2 == 0) and nums[i] == nums[i+1]) ... | 18 | 0 | ['C', 'Java'] | 4 |
minimum-deletions-to-make-array-beautiful | Python | Greedy | python-greedy-by-mikey98-s5gk | ```\nclass Solution:\n def minDeletion(self, nums: List[int]) -> int:\n # Greedy !\n # we first only consider requirement 2: nums[i] != nums[i | Mikey98 | NORMAL | 2022-03-27T04:01:07.012650+00:00 | 2022-03-27T04:01:07.012678+00:00 | 1,287 | false | ```\nclass Solution:\n def minDeletion(self, nums: List[int]) -> int:\n # Greedy !\n # we first only consider requirement 2: nums[i] != nums[i + 1] for all i % 2 == 0\n # at the begining, we consider the num on the even index\n # when we delete a num, we need consider the num on the odd i... | 16 | 0 | ['Greedy', 'Python', 'Python3'] | 4 |
minimum-deletions-to-make-array-beautiful | C++ Two Pointers + Greedy O(N) Time O(1) Space | c-two-pointers-greedy-on-time-o1-space-b-tmbw | See my latest update in repo LeetCode\n\n## Solution 1. Two Pointers + Greedy\n\nWe can greedily find the even and odd pairs from left to right.\n\nWhy greedy? | lzl124631x | NORMAL | 2022-03-27T04:01:29.777824+00:00 | 2022-03-27T06:33:45.490095+00:00 | 1,580 | false | See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Two Pointers + Greedy\n\nWe can greedily find the even and odd pairs from left to right.\n\n**Why greedy**? Think if the first two elements, if they are equal, we have to delete one of them -- deleting the rest of the numb... | 14 | 1 | [] | 1 |
minimum-deletions-to-make-array-beautiful | C++ | 5-6 lines code | O(n) time, O(1) space | c-5-6-lines-code-on-time-o1-space-by-om_-5yjd | Time Complexity: O(n)\nSpace Complexity: O(1)\n``` \nint minDeletion(vector& nums) {\n int i=0, n=nums.size(), count=0;\n while(i<n){\n | om_1609 | NORMAL | 2022-03-27T04:30:06.857103+00:00 | 2022-03-27T06:33:19.780218+00:00 | 636 | false | Time Complexity: O(n)\nSpace Complexity: O(1)\n``` \nint minDeletion(vector<int>& nums) {\n int i=0, n=nums.size(), count=0;\n while(i<n){\n while(i<n-1 && nums[i]==nums[i+1])i++, count++; \n i+=2; \n }\n\t\t//if length of remaining sequence\xA0 is odd remove last element ... | 10 | 0 | ['Greedy', 'C'] | 0 |
minimum-deletions-to-make-array-beautiful | Python Simple Solution O(n) Time and O(1) Space | python-simple-solution-on-time-and-o1-sp-07rt | We iterate over nums from left to right and greedily choose elements which satisfy the given condition in our final array. While iterating, we need to keep a co | mrunankmistry52 | NORMAL | 2022-03-27T04:09:32.161938+00:00 | 2022-03-27T04:14:34.367914+00:00 | 634 | false | We iterate over nums from left to right and **greedily choose elements** which satisfy the given condition in our final array. While iterating, we need to **keep a count** of how many elements we have chosen so far to make greedy choices.\n\n### Idea:\n1. Iterate from left to right uptil second last element:\n 1.1 I... | 9 | 0 | ['Greedy', 'Python', 'Python3'] | 1 |
minimum-deletions-to-make-array-beautiful | Simple Java Solution - One pass | simple-java-solution-one-pass-by-pavanku-yxx2 | ```\nclass Solution {\n public int minDeletion(int[] nums) {\n if(nums.length==0)\n return 0;\n Integer prev = null;\n int ci | pavankumarchaitanya | NORMAL | 2022-03-27T04:05:27.901274+00:00 | 2022-03-27T04:05:27.901313+00:00 | 501 | false | ```\nclass Solution {\n public int minDeletion(int[] nums) {\n if(nums.length==0)\n return 0;\n Integer prev = null;\n int ci = 0;\n for(int i=0;i<nums.length;i++){\n \n if(prev!=null)\n {\n if(nums[i]!=prev){\n ... | 8 | 1 | [] | 0 |
minimum-deletions-to-make-array-beautiful | ✅ [C++] | EASY SOLUTION | TC : O(N) | SC : O(1) | c-easy-solution-tc-on-sc-o1-by-jaysudani-x3v6 | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n \n int ans=0;\n int sz=nums.size();\n \n for(int i=0; | jaysudani | NORMAL | 2022-03-29T04:04:05.246857+00:00 | 2022-03-29T06:31:17.258393+00:00 | 364 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n \n int ans=0;\n int sz=nums.size();\n \n for(int i=0;i<sz-1;i++){\n //if effective index is even and it has same number at its index + 1 then we have to remove it \n if((i-ans)%2==0 and ... | 7 | 0 | ['C++'] | 0 |
minimum-deletions-to-make-array-beautiful | o(n) solution Easy | on-solution-easy-by-sathish_mccall-w86h | Please upvote if you found the answer useful\nSo we have delete a value at i+1 if i is even and then nums[i]==nums[i+1],\nso according to that if we make one de | Sathish_McCall | NORMAL | 2022-06-28T06:31:29.866702+00:00 | 2022-06-28T06:31:29.866749+00:00 | 271 | false | **Please upvote if you found the answer useful**\nSo we have delete a value at i+1 if i is even and then nums[i]==nums[i+1],\nso according to that if we make one deletion all the indexes of the array will move ahead by 1,\nSo if we have n no of deletions, the elements of array will move ahead by n.\nAccording to that ,... | 6 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | ANSWERED ALL QUES | SIMPLE | EXPLAINED ALL CONCEPTS | answered-all-ques-simple-explained-all-c-fnhf | Intuition\n Describe your first thoughts on how to solve this problem. \nSNOWBALL METHOD:\nAs we go through the nums array if we got valid element to remove we | prathmeshdeshpande101 | NORMAL | 2022-11-24T18:39:09.637333+00:00 | 2022-11-24T18:39:09.637382+00:00 | 715 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSNOWBALL METHOD:\nAs we go through the nums array if we got valid element to remove we are going to increase the size of eleSize;\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUsed SNOWBALL METHOD:\nif we got t... | 5 | 0 | ['Array', 'Two Pointers', 'Greedy', 'Sliding Window', 'Java'] | 1 |
minimum-deletions-to-make-array-beautiful | Easy To Understand || C++ || O(n) TIme | easy-to-understand-c-on-time-by-pranjal_-6gry | \n\n\nint minDeletion(vector<int>& nums) {\n int n=nums.size();\n int cnt=0, si=0;\n \n for(int i=0;i<n-1;i++) {\n if(num | pranjal_gaur | NORMAL | 2022-03-27T07:12:40.665825+00:00 | 2022-03-27T18:30:18.161435+00:00 | 302 | false | \n\n```\nint minDeletion(vector<int>& nums) {\n int n=nums.size();\n int cnt=0, si=0;\n \n for(int i=0;i<n-1;i++) {\n if(nums[i]==nums[i+1] && si%2==0) cnt++;\n else si++;\n }\n if(si%2==0) cnt++;\n \n return cnt;\n }\n``` | 5 | 0 | ['C'] | 0 |
minimum-deletions-to-make-array-beautiful | Time-O(n) Space-O(1) || Beginners friendly | time-on-space-o1-beginners-friendly-by-s-b9hr | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int result=0;\n int i;\n for( i=0;i<nums.size()-1;)\n {\n | Shishir_Sharma | NORMAL | 2022-03-27T04:03:57.513218+00:00 | 2022-03-27T06:16:09.479083+00:00 | 351 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int result=0;\n int i;\n for( i=0;i<nums.size()-1;)\n {\n \n if(nums[i]==nums[i+1])\n {\n i++;\n result++;\n }\n else\n {\... | 5 | 0 | ['C', 'C++'] | 0 |
minimum-deletions-to-make-array-beautiful | Easy solution ✅✅ | easy-solution-by-coder_96677-pqsp | \n# Code\n\n#include <iostream>\n#include <vector>\n\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n if(nums.size()==1 ){\n | Coder_96677 | NORMAL | 2023-09-12T18:30:05.087033+00:00 | 2023-09-12T18:30:05.087057+00:00 | 493 | false | \n# Code\n```\n#include <iostream>\n#include <vector>\n\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n if(nums.size()==1 ){\n return 1;\n }\n int i=0;\n int count =0;\n \n while(i<nums.size()-1){\n if(nums[i]==nums[i+1]){\n ... | 4 | 0 | ['C++'] | 0 |
minimum-deletions-to-make-array-beautiful | C++ || O(n) time O(1) space || Clean and Concise code | c-on-time-o1-space-clean-and-concise-cod-74dh | \n int minDeletion(vector<int>& nums) {\n int n=nums.size(),ans=0,i=0;\n while(i<n)\n {\n if(i<n-1 && nums[i]==nums[i+1]) ans | ashay028 | NORMAL | 2022-06-28T05:12:48.444691+00:00 | 2022-06-28T05:12:48.444736+00:00 | 189 | false | ```\n int minDeletion(vector<int>& nums) {\n int n=nums.size(),ans=0,i=0;\n while(i<n)\n {\n if(i<n-1 && nums[i]==nums[i+1]) ans++, i--;\n i+=2;\n }\n if((n-ans)%2) ans++;\n return ans;\n }\n``` | 4 | 0 | [] | 1 |
minimum-deletions-to-make-array-beautiful | Java Solution with Intuition | java-solution-with-intuition-by-arcpri-f2qi | Intuition\n\nIf we analyse the problem a little, we\'ll see that its indirectly asking us to create a new array after the deletions. Since its not asking for an | arcpri | NORMAL | 2022-03-31T21:01:56.123227+00:00 | 2022-03-31T21:02:33.270008+00:00 | 323 | false | **Intuition**\n\nIf we analyse the problem a little, we\'ll see that its indirectly asking us to create a new array after the deletions. Since its not asking for an actual array to be returned, but rather the number of deletions, we need not create an actual array, we can just simulate its creation. \n\nFor this purpos... | 4 | 0 | ['Java'] | 0 |
minimum-deletions-to-make-array-beautiful | C++/Python | Intuituitive | Easy to Understand | Two Pointers | O(n) Solution | cpython-intuituitive-easy-to-understand-l1e3k | Intuition\n We have to take care of new index formed after deletion so let\'s mantain another pointer j\n We have pointer i for traversing in the array\n As sta | TejPratap1 | NORMAL | 2022-03-27T10:44:14.176785+00:00 | 2022-03-27T11:01:23.163336+00:00 | 304 | false | **Intuition**\n* We have to take care of new index formed after deletion so let\'s mantain another pointer j\n* We have pointer i for traversing in the array\n* As stated, if nums[i] == nums[i+1] and j%2 == 0 we have to perform deletion, as we are oerforming deletion size reduces so no need to increament j\n* At last a... | 4 | 0 | ['Two Pointers', 'C', 'Python'] | 0 |
minimum-deletions-to-make-array-beautiful | Intuition Easy (EVEN ODD) | intuition-easy-even-odd-by-iyershridhar-zlym | The main catch for the problem is nums.length should be even after all of the operation \nObserve a pattern \nafter the operation\n1 . nums.length is odd (5) - | iyershridhar | NORMAL | 2022-03-27T04:58:38.928095+00:00 | 2022-03-27T05:07:53.543472+00:00 | 185 | false | The main catch for the problem is nums.length should be even after all of the operation \nObserve a pattern \nafter the operation\n1 . nums.length is odd (5) -> 0 1 2 3 4\n2 . nums.length is even (6) -> 0 1 2 3 4 5\nnow lets suppose we have done some operation optimally and our ans vector size at this point of time is... | 4 | 0 | ['Greedy'] | 1 |
minimum-deletions-to-make-array-beautiful | Simple C++ Solution with comments - O(N) time, O(1) space | simple-c-solution-with-comments-on-time-9qdew | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int n = nums.size();\n int vindex = 0, ans = 0; // vindex -> virtual inde | the_og_rises | NORMAL | 2022-03-27T04:19:40.387722+00:00 | 2022-03-27T04:19:40.387750+00:00 | 132 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int n = nums.size();\n int vindex = 0, ans = 0; // vindex -> virtual index after deletion of the the element from array\n \n for(int i=0; i<n; i++){\n if(vindex%2==0){ // if vindex is even then only yo... | 4 | 0 | ['C'] | 0 |
minimum-deletions-to-make-array-beautiful | C++ | O(N) time O(1) space | c-on-time-o1-space-by-anugamsiddhartha-teca | \n\n\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int count=0;\n int n=nums.size();\n int dele=0;\n for(in | anugamsiddhartha | NORMAL | 2022-03-27T04:12:01.544507+00:00 | 2022-03-27T04:12:01.544534+00:00 | 173 | false | \n\n```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int count=0;\n int n=nums.size();\n int dele=0;\n for(int i=0;i<nums.size()-1;i++)\n {\n if((i-dele)%2==0)\n {\n if(nums[i]==nums[i+1])\n {\n ... | 4 | 0 | ['C'] | 0 |
minimum-deletions-to-make-array-beautiful | C++ | easy to understood | c-easy-to-understood-by-smit3901-fw75 | \tint minDeletion(vector& nums) {\n\t\t\tint size = nums.size();\n\t\t\tint cnt = 0;\n\t\t\tfor(int i=0;i< size-1;)\n\t\t\t{\n\t\t\t\tif(nums[i] == nums[i+1])\n | smit3901 | NORMAL | 2022-03-27T04:04:32.557822+00:00 | 2022-03-27T04:04:32.557859+00:00 | 230 | false | \tint minDeletion(vector<int>& nums) {\n\t\t\tint size = nums.size();\n\t\t\tint cnt = 0;\n\t\t\tfor(int i=0;i< size-1;)\n\t\t\t{\n\t\t\t\tif(nums[i] == nums[i+1])\n\t\t\t\t{\n\t\t\t\t\ti++;\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ti += 2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(size % 2 == 0 and cnt % 2... | 4 | 0 | ['C'] | 0 |
minimum-deletions-to-make-array-beautiful | ✅ C++ | 3 lines | explanation | O(n) time | O(1) space | c-3-lines-explanation-on-time-o1-space-b-t18w | As we do not need to sort the array, just compare the consecutive elements\n if they are equal, increment the ans\n else just skip\n last check would be, if the | arihantjain01 | NORMAL | 2022-03-27T04:01:07.163342+00:00 | 2022-06-22T09:50:43.973587+00:00 | 350 | false | * As we do not need to sort the array, just compare the consecutive elements\n* if they are equal, increment the ```ans```\n* else just skip\n* last check would be, if the vector size is even or not\n* as ```ans = number of deletions```, ```size of vector - ans``` would mean the final vector size after deletions. if it... | 4 | 1 | ['C'] | 3 |
minimum-deletions-to-make-array-beautiful | C++ || super easy 4 lines; | c-super-easy-4-lines-by-shradhaydham24-17nd | 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 | shradhaydham24 | NORMAL | 2023-09-12T19:35:31.424120+00:00 | 2023-09-12T19:35:31.424147+00:00 | 102 | 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)$$ --... | 3 | 0 | ['C++'] | 1 |
minimum-deletions-to-make-array-beautiful | Simple Python Solution with O(n) time complexity and O(1) space complexity | simple-python-solution-with-on-time-comp-jumn | \nclass Solution(object):\n def minDeletion(self, nums):\n """\n :type nums: List[int]\n :rtype: int\n """\n \n if | SumanthBharadwaj | NORMAL | 2022-06-28T15:19:44.144213+00:00 | 2022-06-28T15:19:44.144259+00:00 | 183 | false | ```\nclass Solution(object):\n def minDeletion(self, nums):\n """\n :type nums: List[int]\n :rtype: int\n """\n \n if len(nums) > 1:\n# The \'pointer\' points to the left hand side array element in comparision ie nums[i]\n# The \'high\' points to the right hand side array el... | 3 | 0 | ['Python'] | 1 |
minimum-deletions-to-make-array-beautiful | c++ solution || two approaches|| O(1) space | c-solution-two-approaches-o1-space-by-sr-2s80 | Using stack :\n\nclass Solution {\npublic:\n int minDeletion(vector<int>& a) {\n stack<int>s;\n int n=a.size(),index=-1,count=0;\n for(i | srinidhi_kanugula | NORMAL | 2022-06-16T14:03:08.832227+00:00 | 2022-06-16T14:04:15.619930+00:00 | 196 | false | Using stack :\n```\nclass Solution {\npublic:\n int minDeletion(vector<int>& a) {\n stack<int>s;\n int n=a.size(),index=-1,count=0;\n for(int i=0;i<n;i++){\n if(!s.empty() && a[i]==s.top() && index%2==0){\n count++;\n }\n else{\n ind... | 3 | 0 | ['Stack', 'C'] | 0 |
minimum-deletions-to-make-array-beautiful | 3 Different Solutions [Simple, Greedy and Faster ] | 3-different-solutions-simple-greedy-and-tofst | This solution is based on a approch that we need a pair who has distinct elements (That\'s what the ques saying basically)\n\'\'\'\n\n def minDeletion(self, | vi_ek | NORMAL | 2022-04-15T06:36:20.556186+00:00 | 2022-04-15T06:36:20.556227+00:00 | 195 | false | This solution is based on a approch that we need a pair who has distinct elements (That\'s what the ques saying basically)\n\'\'\'\n\n def minDeletion(self, nums: List[int]) -> int:\n ans =0 \n l=None\n for i in nums:\n if l is None:\n l=i\n elif l!=i:\n ... | 3 | 0 | ['Greedy', 'C', 'Python'] | 0 |
minimum-deletions-to-make-array-beautiful | C++,Simple O(n) and O(1) solution | csimple-on-and-o1-solution-by-aashuchoud-d8kh | In this First of all we will check if the give array is empty or of size 1, if so then we will simply return 0;\nNow, for the real test cases...\nwe will mainta | aashuchoudhary52 | NORMAL | 2022-04-08T08:10:18.511877+00:00 | 2022-04-08T08:10:18.511904+00:00 | 56 | false | In this First of all we will check if the give array is empty or of size 1, if so then we will simply return 0;\nNow, for the real test cases...\nwe will maintain a "K" which will store the no. of elements we will delete.\nNow for every index we will check for (i-k)%2 coz ,index of elements will be sifted to left when ... | 3 | 0 | ['C', 'Iterator'] | 0 |
minimum-deletions-to-make-array-beautiful | Java - Simple , Easy and 100% faster O(N) Time O(1) Space | java-simple-easy-and-100-faster-on-time-1gsdp | If nums length is 0 , no need to delete so return 0.\nelse\nstart with 0 index and check if i and i+1 are less than n and if nums[i] & nums[i+1] are not equals | shivamchhn | NORMAL | 2022-03-29T18:13:13.365001+00:00 | 2022-04-05T17:43:29.001561+00:00 | 233 | false | If nums length is 0 , no need to delete so return 0.\nelse\nstart with 0 index and check if i and i+1 are less than n and if nums[i] & nums[i+1] are not equals we don\'t need to delete i or i+1 so make i = i+2 .\nif nums[i] & nums[i+1] are equals then we have to delete either i or i+1 . Instead of doing deleting just i... | 3 | 0 | ['Greedy', 'Java'] | 2 |
minimum-deletions-to-make-array-beautiful | ✅C++ | O(N) To O(1) Space | c-on-to-o1-space-by-shivam242424-sker | Solution 1: Using Stack
Time Complexity : O(N)
Space Complexity : O(N).
Solution 2 : Optimal in Space
Time Complexity : O(N)
Space Complexity : O(1)
If U li | shivam242424 | NORMAL | 2022-03-28T13:56:23.014100+00:00 | 2025-03-24T06:51:41.619883+00:00 | 58 | false | # Solution 1: Using **Stack**
``` C++ []
class Solution
{
public:
int minDeletion(vector<int>& nums)
{
int del = 0, i = 0, n = nums.size();
stack<pair<int, int>> st; // pair stores prev value and index after shifting
while(i < n)
{
if(!st.empty())
{
// index is even and prev and curr ... | 3 | 0 | ['C'] | 0 |
minimum-deletions-to-make-array-beautiful | [Typescript] Readable Solution with Code Documentation | typescript-readable-solution-with-code-d-677r | \n// Leetcode: https://leetcode.com/problems/minimum-deletions-to-make-array-beautiful/\n\nvar minDeletion = (nums: number[]): number => {\n let deletions = | hardanish-singh | NORMAL | 2022-03-28T11:16:16.098894+00:00 | 2024-07-05T18:17:04.609925+00:00 | 220 | false | ```\n// Leetcode: https://leetcode.com/problems/minimum-deletions-to-make-array-beautiful/\n\nvar minDeletion = (nums: number[]): number => {\n let deletions = 0;\n\n for (let i = 0; i < nums.length; i += 2) {\n if (nums[i] === nums[i + 1]) {\n i--;\n deletions++;\n }\n }\n\... | 3 | 0 | ['TypeScript'] | 2 |
minimum-deletions-to-make-array-beautiful | C++ || Simple & Easy Code || 3 lines || Explained | c-simple-easy-code-3-lines-explained-by-74xsm | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int cnt=0;\n for(int i=0;i<nums.size()-1;i++){\n if(nums[i] == | agrasthnaman | NORMAL | 2022-03-27T20:23:44.194129+00:00 | 2022-03-27T20:23:44.194171+00:00 | 207 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int cnt=0;\n for(int i=0;i<nums.size()-1;i++){\n if(nums[i] == nums[i+1] && (i-cnt)%2 == 0){cnt++;} \n //just check for nums[i] != nums[i + 1] for all i % 2 == 0\n // (i - cnt) is the index of eleme... | 3 | 0 | ['Greedy', 'C', 'C++'] | 0 |
minimum-deletions-to-make-array-beautiful | Easy C++ solution | easy-c-solution-by-rajsaurabh-vcuf | ``` \nint minDeletion(vector& v)\n{ \n int c = 0;\n int n = v.size();\n for (int i = 0; i <n-1 ; i++)\n if (v[i] == v[i + 1] | rajsaurabh | NORMAL | 2022-03-27T05:37:30.505515+00:00 | 2022-03-27T05:38:16.405999+00:00 | 44 | false | ``` \nint minDeletion(vector<int>& v)\n{ \n int c = 0;\n int n = v.size();\n for (int i = 0; i <n-1 ; i++)\n if (v[i] == v[i + 1] && i% 2 == c%2 ) c++;\n \n return c + (n- c) % 2;\n }\n\t | 3 | 0 | [] | 2 |
minimum-deletions-to-make-array-beautiful | C++ | O(n) solution with comments | c-on-solution-with-comments-by-ashutosht-vc1t | We just need to change the index after deletions to get the new index value in every iteration.\nUPVOTE if you like it!!\n\n\nclass Solution {\npublic:\n in | ashutosht1845 | NORMAL | 2022-03-27T05:30:36.853305+00:00 | 2022-03-27T06:01:02.865051+00:00 | 48 | false | We just need to change the index after deletions to get the new index value in every iteration.\nUPVOTE if you like it!!\n\n```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n if(nums.size()==1) return 1;\n \n int count=0;\n int n=nums.size();\n \n for(i... | 3 | 0 | ['C'] | 0 |
minimum-deletions-to-make-array-beautiful | C++ || O(n) time O(1) space || commented solution | c-on-time-o1-space-commented-solution-by-s901 | \'\'\'\n\n int minDeletion(vector& nums) {\n int n= nums.size();\n int n1=n;\n int i=0, j=0;\n int cnt=0;\n\t\t\n // j is | Pain01 | NORMAL | 2022-03-27T04:36:19.608987+00:00 | 2022-03-27T04:36:19.609026+00:00 | 129 | false | \'\'\'\n\n int minDeletion(vector<int>& nums) {\n int n= nums.size();\n int n1=n;\n int i=0, j=0;\n int cnt=0;\n\t\t\n // j is virtual index after removing ith element\n while(i<n-1 && j<n1){\n if(j%2==0 && nums[i]==nums[i+1])\n {\n n1--;... | 3 | 0 | ['Greedy', 'C'] | 4 |
minimum-deletions-to-make-array-beautiful | JAVA | O(1) space | Easy to Understand | java-o1-space-easy-to-understand-by-chai-atd6 | \nclass Solution {\n public int minDeletion(int[] nums) {\n \n int i = 0, n = nums.length;\n int currIndex = 0;\n if(nums.length= | Chaitanya1706 | NORMAL | 2022-03-27T04:02:45.617597+00:00 | 2022-03-27T04:02:45.617647+00:00 | 148 | false | ```\nclass Solution {\n public int minDeletion(int[] nums) {\n \n int i = 0, n = nums.length;\n int currIndex = 0;\n if(nums.length==1) return 1;\n int count = 0;\n while(i<n){\n if(currIndex%2==0){ // if index is even then delete all the continuous duplicate ele... | 3 | 1 | ['Java'] | 0 |
minimum-deletions-to-make-array-beautiful | Easy understanding | easy-understanding-by-akshay3213-tf1m | All we have to is \n1. if (ind % 2 == 0) then nums[i] != nums[i + 1]\n2. final length of array must be even\n\n- For requirement 1,\nwe keep track of elements(i | akshay3213 | NORMAL | 2022-03-27T04:01:58.425748+00:00 | 2022-03-27T04:05:41.391769+00:00 | 286 | false | All we have to is \n1. if (ind % 2 == 0) then nums[i] != nums[i + 1]\n2. final length of array must be even\n\n- For requirement 1,\nwe keep track of elements(index), we see if the 1st condition holds or not, if not remove them(deletion++).\n\n\n- For requirement 2,\nWe just have to check result array\'s length, if eve... | 3 | 1 | [] | 0 |
minimum-deletions-to-make-array-beautiful | Easy Java Solution || Stack | easy-java-solution-stack-by-ravikumar50-vong | 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 | ravikumar50 | NORMAL | 2024-05-02T20:33:01.359227+00:00 | 2024-05-02T20:33:01.359255+00:00 | 107 | 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-deletions-to-make-array-beautiful | minimum-deletions-to-make-array-beautiful | minimum-deletions-to-make-array-beautifu-ppf9 | Intuition\n Describe your first thoughts on how to solve this problem. \n- involves iterating through the input vector, checking adjacent elements for duplicate | TusharMaithani | NORMAL | 2023-08-30T15:31:29.076294+00:00 | 2023-10-04T10:51:13.906915+00:00 | 52 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- involves iterating through the input vector, checking adjacent elements for duplicates, and incrementing a deletion counter when necessary.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- OPTIMAL APPROACH:\nThe... | 2 | 0 | ['Array', 'Ordered Map', 'C++'] | 0 |
minimum-deletions-to-make-array-beautiful | C++ Time - O(N) Space - O(1) | c-time-on-space-o1-by-nayancode93-jn7q | Code\n\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n vector<int>vec;\n int ans=0,s=nums.size(),j=0;\n if(s==1)\n | nayanCode93 | NORMAL | 2022-11-28T01:51:20.640021+00:00 | 2022-11-28T01:51:20.640049+00:00 | 872 | false | # Code\n```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n vector<int>vec;\n int ans=0,s=nums.size(),j=0;\n if(s==1)\n return 1;\n \n for(int i=0;i<nums.size()-1;i++){\n if(j%2==0){\n if(nums[i]==nums[i+1]){\n ... | 2 | 0 | ['C++'] | 0 |
minimum-deletions-to-make-array-beautiful | Very basic C++ approach using flag | very-basic-c-approach-using-flag-by-fazi-ayu3 | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int c=0;\n bool flag=true;\n cout<<flag<<endl;\n for(int i=0 | fazith | NORMAL | 2022-07-25T07:21:29.112316+00:00 | 2022-07-25T07:21:29.112364+00:00 | 67 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int c=0;\n bool flag=true;\n cout<<flag<<endl;\n for(int i=0;i<nums.size()-1;i++){\n if(flag){\n if(nums[i]==nums[i+1]){c++;continue;}\n }\n flag=!flag;\n }\n ... | 2 | 0 | ['C'] | 0 |
minimum-deletions-to-make-array-beautiful | [Python 3] Two Pointer Greedy Solution | python-3-two-pointer-greedy-solution-by-4u8xd | Approach:\nInitialise steps to 0.\nUse two pointers, one to iterate through the array and other to keep track of the index in the updated list after removing (a | hari19041 | NORMAL | 2022-04-01T14:08:18.795708+00:00 | 2022-04-01T14:08:18.795738+00:00 | 214 | false | **Approach**:\nInitialise steps to 0.\nUse two pointers, one to iterate through the array and other to keep track of the index in the updated list after removing (as the indices will change because of shifting).\n\nIf the index is not divisible by 2, then increment the index by 1. Otherwise, taking care of an edge case... | 2 | 0 | ['Two Pointers', 'Greedy', 'Python', 'Python3'] | 0 |
minimum-deletions-to-make-array-beautiful | Very Easy Solution: 2 steps foward 1 step backward, with explanation on thinking process | very-easy-solution-2-steps-foward-1-step-02xg | \npublic int minDeletion(int[] nums) {\n\tint c = 0;\n\tint i = 1;\n\n\twhile (i < nums.length) {\n\t\tif (nums[i-1] == nums[i]) {\n\t\t\tc++;\n\t\t\ti--; // " | didado | NORMAL | 2022-03-29T00:32:44.196407+00:00 | 2022-04-06T22:14:41.679652+00:00 | 43 | false | ```\npublic int minDeletion(int[] nums) {\n\tint c = 0;\n\tint i = 1;\n\n\twhile (i < nums.length) {\n\t\tif (nums[i-1] == nums[i]) {\n\t\t\tc++;\n\t\t\ti--; // "deleted" one element, to keep the check in pairs\n\t\t}\n\t\ti += 2;\n\t}\n\n\treturn (nums.length - c) % 2 == 0 ? c : c+1;\n}\n```\n========================... | 2 | 0 | ['Java'] | 1 |
minimum-deletions-to-make-array-beautiful | 2216 | C++ | Easy O(N) solution | 2216-c-easy-on-solution-by-yash2arma-iy0i | Code:\n\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) \n {\n int mini=0, i=0;\n \n //iterate till i is less than n- | Yash2arma | NORMAL | 2022-03-28T06:37:11.140400+00:00 | 2022-03-28T06:37:11.140437+00:00 | 94 | false | **Code:**\n```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) \n {\n int mini=0, i=0;\n \n //iterate till i is less than n-1 index\n while(i<nums.size()-1)\n {\n //(i%2+min)==0 to check whether we are at even index or odd\n if((i%2+mini)==0... | 2 | 0 | ['C'] | 0 |
minimum-deletions-to-make-array-beautiful | 🔥 O(1) space | easy java solution with explanation ✅ | o1-space-easy-java-solution-with-explana-m85c | \nHere to Make the array Beautiful array have to satisfy two conditions : \n nums.length is even.\n nums[i] != nums[i + 1] for all i % 2 == 0.\n\nHere , we wil | Himanshu__ranjan | NORMAL | 2022-03-28T06:17:14.205588+00:00 | 2022-03-28T11:02:56.765099+00:00 | 121 | false | \nHere to Make the array Beautiful array have to satisfy two conditions : \n* nums.length is even.\n* nums[i] != nums[i + 1] for all i % 2 == 0.\n\nHere , we will first try to satisfy condition 2 and later when all elements have satisfied the 2nd condition.Then only, we will verify 1st condition.\n\n***Checking Second... | 2 | 0 | ['Two Pointers', 'Greedy', 'Java'] | 1 |
minimum-deletions-to-make-array-beautiful | [JavaScript] 2216. Minimum Deletions to Make Array Beautiful | javascript-2216-minimum-deletions-to-mak-aa17 | ---\n\n- Implementation, after we write, is easy\n\n---\n\nWeekly Contest 286\n- Q1 answer - https://leetcode.com/problems/find-the-difference-of-two-arrays/dis | pgmreddy | NORMAL | 2022-03-28T01:59:02.729804+00:00 | 2022-03-28T23:20:19.126686+00:00 | 245 | false | ---\n\n- Implementation, after we write, is easy\n\n---\n\n**Weekly Contest 286**\n- **Q1** answer - https://leetcode.com/problems/find-the-difference-of-two-arrays/discuss/1889224/JavaScript-2215.-Find-the-Difference-of-Two-Arrays\n- **Q2** answer - https://leetcode.com/problems/minimum-deletions-to-make-array-beautif... | 2 | 0 | ['JavaScript'] | 0 |
minimum-deletions-to-make-array-beautiful | ✅✅✅✅Minimum Deletions to Make Array Beautiful | minimum-deletions-to-make-array-beautifu-zfiy | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) \n {\n int n=nums.size();\n int count=0;\n vector<int>v;\n in | krishnakr44 | NORMAL | 2022-03-27T16:06:51.728086+00:00 | 2022-03-27T16:06:51.728114+00:00 | 227 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) \n {\n int n=nums.size();\n int count=0;\n vector<int>v;\n int f=1;\n for(int i=0;i<n-1;i++)\n {\n //cheak even position\n if(i%2==0 && nums[i]==nums[i+1] && f==1){\n ... | 2 | 0 | ['C', 'C++'] | 0 |
minimum-deletions-to-make-array-beautiful | ✅ C++ || Easy to Understand || Using a Single Loop | c-easy-to-understand-using-a-single-loop-vlmp | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) \n {\n int size = nums.size();\n\t\tint ans = 0;\n\t\tfor(int i=0;i<size-1;i++)\n\ | mayanksamadhiya12345 | NORMAL | 2022-03-27T08:40:41.850268+00:00 | 2022-03-27T08:40:41.850296+00:00 | 37 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) \n {\n int size = nums.size();\n\t\tint ans = 0;\n\t\tfor(int i=0;i<size-1;i++)\n\t\t{\n\t\t\tif(nums[i] == nums[i+1])\n ans++;\n \n\t\t\telse\n i++;\n\t\t}\n \n // for the even le... | 2 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | Java/Python | Simple Greedy Solution Explained | javapython-simple-greedy-solution-explai-sx3r | Idea:\nif there are 2 consecutive elements that are equal and its a good index to delete then we delete it.\nevery step, good index to delete is:\nif we deleted | Avuvos | NORMAL | 2022-03-27T07:13:37.711667+00:00 | 2022-03-27T07:14:22.859872+00:00 | 97 | false | Idea:\nif there are 2 consecutive elements that are equal **and** its a good index to delete then we delete it.\nevery step, good index to delete is:\nif we deleted 0 elements, we want the **even** indices\nif we deleted 1 elements, we want the **odd** indicies\nif we deleted 2 elements, again we want the **even** indi... | 2 | 0 | ['Greedy', 'Python', 'Java'] | 0 |
minimum-deletions-to-make-array-beautiful | C++ || O(N) || with comments | c-on-with-comments-by-shm_47-rsm1 | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int count = 0;\n \n for(int i = 0; i < nums.size()-1; i++){ | shm_47 | NORMAL | 2022-03-27T07:10:33.441674+00:00 | 2022-03-27T07:10:33.441715+00:00 | 40 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int count = 0;\n \n for(int i = 0; i < nums.size()-1; i++){\n if((i- count) % 2 == 0 && nums[i]==nums[i+1]){ //checking dupliactes at even index\n count++; ... | 2 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | My Solution | my-solution-by-123_tripathi-3ftl | \nint minDeletion(vector<int>& nums) {\n int ans=0;\n for(int i=0;i<nums.size()-1;i++){\n if(nums[i] == nums[i+1]){\n an | 123_tripathi | NORMAL | 2022-03-27T06:04:46.040074+00:00 | 2022-06-01T10:27:11.421479+00:00 | 248 | false | ```\nint minDeletion(vector<int>& nums) {\n int ans=0;\n for(int i=0;i<nums.size()-1;i++){\n if(nums[i] == nums[i+1]){\n ans++;\n }else{\n i++;\n }\n }\n if((nums.size()-ans) % 2 != 0){\n ans++;\n }\n ret... | 2 | 0 | ['Greedy', 'C', 'Python', 'C++', 'Java', 'Python3'] | 0 |
minimum-deletions-to-make-array-beautiful | Both O(n) and O(1) space complexity Java solution | both-on-and-o1-space-complexity-java-sol-pr8f | First we will see the O(n) space complexity solution then we will move forward to the optimized one\nThe only reason I\'m telling you both solutions is to get t | sgshines737 | NORMAL | 2022-03-27T05:53:12.213715+00:00 | 2022-03-27T06:10:32.259932+00:00 | 45 | false | First we will see the O(n) space complexity solution then we will move forward to the optimized one\nThe only reason I\'m telling you both solutions is to get the intution behind it So make sure you read the whole post.\nFirst approach:\nIn this approach simply convert the array into arraylist\nand do what condition gi... | 2 | 1 | [] | 0 |
minimum-deletions-to-make-array-beautiful | Very Short C++ Code | very-short-c-code-by-maditya_01-e4l8 | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) { \n int n=nums.size();\n int cnt=0;\n\t\t//ind is our virtual index afte | maditya_01 | NORMAL | 2022-03-27T05:52:26.175791+00:00 | 2022-03-27T05:52:26.175829+00:00 | 24 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) { \n int n=nums.size();\n int cnt=0;\n\t\t//ind is our virtual index after deletion\n for(int i=0;i<n-1;i++){\n //ind--> we are shifting element to left to keep what will be the index of element after deleting el... | 2 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | C++ | O(n) time, O(1) space | Easy to Understand | c-on-time-o1-space-easy-to-understand-by-0unb | \n\nclass Solution {\npublic:\n int minDeletion(vector<int>& num) {\n int n = num.size(),ans=0;\n for(int i = 0; i < n ; i+=2) while(i+1<n and | Archit-Bikram | NORMAL | 2022-03-27T04:50:54.923097+00:00 | 2022-03-27T05:04:26.497634+00:00 | 26 | false | \n```\nclass Solution {\npublic:\n int minDeletion(vector<int>& num) {\n int n = num.size(),ans=0;\n for(int i = 0; i < n ; i+=2) while(i+1<n and num[i] == num[i+1]) i++,ans++; \n ans += (n-ans)&1;\n return ans;\n }\n};\n``` | 2 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | Java | Single Pointer | O(n) time, O(1) space | java-single-pointer-on-time-o1-space-by-82lej | We simply check if the next element is equal to the current.\n1. If it is equals, we delete the current element and add one to our ans.\n2. If it is not equal, | bumpyride12 | NORMAL | 2022-03-27T04:31:48.774169+00:00 | 2022-03-27T04:31:48.774195+00:00 | 71 | false | We simply check if the next element is equal to the current.\n1. If it is equals, we delete the current element and add one to our `ans`.\n2. If it is not equal, we increase the current index by `2`.\n3. At the end, if index is the last element of the array, then we know we must remove it to make the final array even s... | 2 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | [Python 3] O(N) time O(1) space | python-3-on-time-o1-space-by-a33584080-txvm | Variable index is to keep track of the current index of nums after "deletion"\nDuring for loop if index%2==0 and nums[i] == nums[i+1] we just don\'t increment i | a33584080 | NORMAL | 2022-03-27T04:18:49.008494+00:00 | 2022-03-27T04:18:49.008523+00:00 | 41 | false | Variable *index* is to keep track of the current index of *nums* after "deletion"\nDuring for loop if index%2==0 and nums[i] == nums[i+1] we just don\'t increment index.\n\n```\nclass Solution:\n def minDeletion(self, nums: List[int]) -> int:\n res=0\n index=0\n for i in range(len(nums)-1):\n ... | 2 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | C++ Easy | c-easy-by-kishan_akbari-sav6 | ```\nclass Solution {\npublic:\n int minDeletion(vector& v){\n \n int ans = 0;\n int x = 0;\n for(int i=0; i<(int)v.size(); ++i)\ | Kishan_Akbari | NORMAL | 2022-03-27T04:14:28.232563+00:00 | 2022-03-27T04:16:16.449955+00:00 | 24 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& v){\n \n int ans = 0;\n int x = 0;\n for(int i=0; i<(int)v.size(); ++i)\n {\n if(i%2==x && i+1<v.size())\n {\n if(v[i]==v[i+1]){\n ans++;\n x ^= ... | 2 | 0 | ['Greedy', 'C'] | 0 |
minimum-deletions-to-make-array-beautiful | C++ | Short and Easy | Shifting positions | c-short-and-easy-shifting-positions-by-c-2g3z | Let s=number of times to shift left. If we delete element from array, we have to increase it.\nthen i-s will be new position after shifting by s number of times | codingsuju | NORMAL | 2022-03-27T04:01:48.148523+00:00 | 2022-03-27T04:05:21.398069+00:00 | 123 | false | Let s=number of times to shift left. If we delete element from array, we have to increase it.\nthen i-s will be new position after shifting by s number of times to left\n```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int ans=0;\n int s=0;\n int n=nums.size();\n fo... | 2 | 1 | ['C'] | 0 |
minimum-deletions-to-make-array-beautiful | A simple dp solution | a-simple-dp-solution-by-infiniteflame-v5kp | \npublic int minDeletion(int[] nums) {\n\tint l = nums.length;\n\tint[] dp = new int[l];\n\tdp[0] = 0;\n\tfor(int i=1; i<l; i++) {\n\t\t// Check nums[i] != nums | infiniteflame | NORMAL | 2022-03-27T04:01:44.818647+00:00 | 2022-03-27T04:04:55.589955+00:00 | 145 | false | ```\npublic int minDeletion(int[] nums) {\n\tint l = nums.length;\n\tint[] dp = new int[l];\n\tdp[0] = 0;\n\tfor(int i=1; i<l; i++) {\n\t\t// Check nums[i] != nums[i + 1] for all i % 2 == 0.\n\t\tif((nums[i] == nums[i-1]) && ((i-1-dp[i-1])%2 == 0)) {\n\t\t\tdp[i] = dp[i-1] + 1;\n\t\t}\n\t\telse\n\t\t\tdp[i] = dp[i-1];\... | 2 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | 🚀0ms Runtime || Beats 100% || O(1) space || best optimal approach | 0ms-runtime-beats-100-o1-space-best-opti-tn5m | Intuition
A "beautiful array" is defined as one where every even-indexed element is different from the next element.
We iterate through the array, removing dupl | kaushik_aviral | NORMAL | 2025-03-16T14:53:39.121177+00:00 | 2025-03-16T14:53:39.121177+00:00 | 41 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
- A "beautiful array" is defined as one where every even-indexed element is different from the **next element**.
- We iterate through the array, removing duplicate elements that would violate this condition at even indices.
# Approach
<!-... | 1 | 0 | ['Array', 'Stack', 'Greedy', 'C++', 'Java', 'Python3'] | 0 |
minimum-deletions-to-make-array-beautiful | Using Two pointers Beats 94.71% Python3 | using-two-pointers-beats-9471-python3-by-2xjb | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires ensuring that no two consecutive elements in an array are the same | amanabiy | NORMAL | 2024-08-29T22:11:27.070948+00:00 | 2024-08-29T22:11:27.070975+00:00 | 6 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires ensuring that no two consecutive elements in an array are the same, and the array length is even. The simplest approach is to iterate from the left, removing duplicates when they appear next to each other. By carefull... | 1 | 0 | ['Two Pointers', 'Greedy', 'Python3'] | 0 |
minimum-deletions-to-make-array-beautiful | C++ using stack | c-using-stack-by-sam_455-eyxp | 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 | sam_455 | NORMAL | 2024-06-15T07:21:02.072950+00:00 | 2024-06-15T07:21:02.072982+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: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$... | 1 | 0 | ['C++'] | 0 |
minimum-deletions-to-make-array-beautiful | Intutive greedy stack approach | intutive-greedy-stack-approach-by-abhayd-5ju3 | Literally do what the questions says\n\n# Code\n\nclass Solution {\n public int minDeletion(int[] nums) {\n return util1(nums);\n }\n public int | AbhayDutt | NORMAL | 2023-10-03T16:01:40.904721+00:00 | 2023-10-03T16:01:40.904742+00:00 | 93 | false | Literally do what the questions says\n\n# Code\n```\nclass Solution {\n public int minDeletion(int[] nums) {\n return util1(nums);\n }\n public int util1(int[] arr) {\n Stack<Integer> s = new Stack<>();\n int operations = 0;\n for (int i : arr) {\n if (s.isEmpty() == fals... | 1 | 0 | ['Stack', 'Greedy', 'Java'] | 0 |
minimum-deletions-to-make-array-beautiful | Easy || Short || C++ | easy-short-c-by-ashu_kharya-4dbw | \n# Approach\n Describe your approach to solving the problem. \n1. If it equals to next element, increment ans and i by 1.\n2. Else incremenr by 2.\n3. Finally | ashu_kharya | NORMAL | 2023-09-12T06:45:00.898141+00:00 | 2023-09-12T06:45:00.898164+00:00 | 115 | false | \n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. If it equals to next element, increment ans and i by 1.\n2. Else incremenr by 2.\n3. Finally to make the array even size, again do +1. \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n- Spa... | 1 | 0 | ['C++'] | 1 |
minimum-deletions-to-make-array-beautiful | C# Solution in O(N) time & without space | c-solution-in-on-time-without-space-by-m-ugh4 | \n# Complexity\n- Time complexity:\nO(N)\n- Space complexity:\nO(1)\n# Code\n\npublic class Solution {\n public int MinDeletion(int[] nums) {\n int re | mohamedAbdelety | NORMAL | 2023-04-02T11:06:17.347099+00:00 | 2023-04-02T11:06:17.347154+00:00 | 18 | false | \n# Complexity\n- Time complexity:\nO(N)\n- Space complexity:\nO(1)\n# Code\n```\npublic class Solution {\n public int MinDeletion(int[] nums) {\n int res = 0, i = 0;\n while(i < nums.Length){\n int j = i + 1;\n while(j < nums.Length && nums[j] == nums[i]){\n res++;... | 1 | 0 | ['Array', 'C#'] | 0 |
minimum-deletions-to-make-array-beautiful | Very Easy Approach using Stacks | Greedy Approach | Faster than 20% | very-easy-approach-using-stacks-greedy-a-r6q6 | Intuition\n Describe your first thoughts on how to solve this problem. \n- At first I thought to arrange an array at every loop. But that approach was too costl | shubham-0707 | NORMAL | 2023-03-01T17:21:23.095797+00:00 | 2023-03-01T17:21:23.095860+00:00 | 47 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- At first I thought to arrange an array at every loop. But that approach was too costly and caused me TLE.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Then I thought of the stack approach.\n- Here I am check... | 1 | 0 | ['Stack', 'Greedy', 'Java'] | 0 |
minimum-deletions-to-make-array-beautiful | C++ || Using Stack || Easy Solution | c-using-stack-easy-solution-by-sunnynand-vzhv | 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 | sunnynandan665 | NORMAL | 2023-01-13T14:05:06.053693+00:00 | 2023-01-13T14:12:02.193743+00:00 | 66 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $... | 1 | 0 | ['C++'] | 0 |
minimum-deletions-to-make-array-beautiful | JavaScript O(N) with easy explanation | javascript-on-with-easy-explanation-by-d-h5be | \nvar minDeletion = function(nums) {\n \n let n = nums.length;\n \n let k = 0;\n for(let i = 0; i<n-1; i++) {\n \n /*\n | dimensionless_ | NORMAL | 2022-11-11T18:53:10.224644+00:00 | 2022-11-11T18:53:10.224681+00:00 | 74 | false | ```\nvar minDeletion = function(nums) {\n \n let n = nums.length;\n \n let k = 0;\n for(let i = 0; i<n-1; i++) {\n \n /*\n if i delete one element then all elements to right of it shift by one \n likewise for k deleted elements, indexes of the elements of right to them... | 1 | 0 | ['JavaScript'] | 0 |
minimum-deletions-to-make-array-beautiful | Java solution | Easy | java-solution-easy-by-sourin_bruh-nfkq | Please Upvote !!!\n\nclass Solution {\n public int minDeletion(int[] nums) {\n int delet = 0;\n int n = nums.length;\n \n for (in | sourin_bruh | NORMAL | 2022-09-19T17:42:34.658039+00:00 | 2022-09-19T17:42:34.658092+00:00 | 54 | false | ### **Please Upvote !!!**\n```\nclass Solution {\n public int minDeletion(int[] nums) {\n int delet = 0;\n int n = nums.length;\n \n for (int i = 0; i < n - 1; i++) {\n int newIndex = i - delet;\n if (newIndex % 2 == 0 && nums[i] == nums[i + 1]) {\n de... | 1 | 0 | ['Java'] | 0 |
minimum-deletions-to-make-array-beautiful | CPP | cpp-by-zehbar_rayani-2kfx | \tclass Solution {\n\tpublic:\n\t\tint minDeletion(vector& nums) {\n\t\t\tif(nums.empty()) return 0;\n\t\t\tint c= 0;\n\t\t\tfor(int i = 0;i<nums.size()-1;i+=2) | zehbar_rayani | NORMAL | 2022-09-05T19:20:45.070277+00:00 | 2022-09-05T19:20:45.070321+00:00 | 20 | false | \tclass Solution {\n\tpublic:\n\t\tint minDeletion(vector<int>& nums) {\n\t\t\tif(nums.empty()) return 0;\n\t\t\tint c= 0;\n\t\t\tfor(int i = 0;i<nums.size()-1;i+=2){\n\t\t\t\tif(nums[i] == nums[i+1]) {\n\t\t\t\t\ti--;\n\t\t\t\t\tc++;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn c + (nums.size()-c)%2 ;\n\t\t}\n\t}; | 1 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | [Python] Simple Intuitive solution | python-simple-intuitive-solution-by-gp05-04ll | In the approach, we are actaully doing pop element which does the left shift\n\nclass Solution:\n def minDeletion(self, nums: List[int]) -> int:\n i = | Gp05 | NORMAL | 2022-07-31T10:33:29.624160+00:00 | 2022-07-31T10:33:29.624205+00:00 | 77 | false | In the approach, we are actaully doing pop element which does the left shift\n```\nclass Solution:\n def minDeletion(self, nums: List[int]) -> int:\n i = 0\n count = 0\n while i + 1 < len(nums):\n if i % 2 == 0 and nums[i] == nums[i+1]:\n count += 1\n\t\t\t\t # left shi... | 1 | 0 | ['Stack', 'Python'] | 0 |
minimum-deletions-to-make-array-beautiful | Coded a solution in 1 minute and it's no worse than any others | coded-a-solution-in-1-minute-and-its-no-7qffk | I coded this solution in literally 1 minute. And I checked the top voted solutions in the discuss section. Surprisingly none is better than mine!\n\nO(1) space | tyler-liu | NORMAL | 2022-07-19T05:54:23.188508+00:00 | 2022-07-19T05:57:24.727393+00:00 | 35 | false | I coded this solution in literally 1 minute. And I checked the top voted solutions in the discuss section. Surprisingly none is better than mine!\n\n**O(1) space and O(n) time**\n\n```py\ndef minDeletion(self, nums: List[int]) -> int:\n res = i = 0\n while i + 1 < len(nums):\n if nums[i] != nums[i + 1]:\n ... | 1 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | Beautiful array using 2 methods | beautiful-array-using-2-methods-by-spide-7is0 | Method 1: using shifting of indexes\nclass Solution {\n public int minDeletion(int[] nums) {\n int count = 0;\n for(int i=0;i<nums.length-1;i++ | Spidey_Edith | NORMAL | 2022-06-29T07:45:02.703237+00:00 | 2022-06-29T07:45:02.703279+00:00 | 63 | false | Method 1: using shifting of indexes\nclass Solution {\n public int minDeletion(int[] nums) {\n int count = 0;\n for(int i=0;i<nums.length-1;i++){\n int m = i - count;\n if(m%2 == 0 && nums[i] == nums[i+1]){\n count++;\n }\n }\n \n if(... | 1 | 0 | ['Java'] | 0 |
minimum-deletions-to-make-array-beautiful | Simple Java Solution || faster than 71.91% of Java online submissions | simple-java-solution-faster-than-7191-of-dvvq | \n\nclass Solution {\n public int minDeletion(int[] nums) {\n int delete=0;\n for(int i =0; i < nums.length -1;i++){\n int ind = i-d | Shreyaspatil1903 | NORMAL | 2022-06-28T13:48:21.371229+00:00 | 2022-06-28T13:48:21.371256+00:00 | 59 | false | ```\n\nclass Solution {\n public int minDeletion(int[] nums) {\n int delete=0;\n for(int i =0; i < nums.length -1;i++){\n int ind = i-delete;\n if(ind%2 == 0 && nums[i] == nums[i+1]){\n delete++;\n \n }\n \n }\n \n ... | 1 | 0 | ['Greedy', 'Java'] | 0 |
minimum-deletions-to-make-array-beautiful | C++ | Shortest solution | Easy to comprehend | O(n) time | constant space | c-shortest-solution-easy-to-comprehend-o-qhi7 | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int n=nums.size(), ctr=0, op=0;\n for(int i=0; i<n-1; i++,ctr++) {\n | __ikigai__ | NORMAL | 2022-06-28T09:27:12.327049+00:00 | 2022-06-28T09:30:58.517215+00:00 | 15 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int n=nums.size(), ctr=0, op=0;\n for(int i=0; i<n-1; i++,ctr++) {\n if(!(ctr&1)) while(i+1<n&&nums[i+1]==nums[i]) i++, op++;\n }\n return (ctr&1)?op+1:op;\n }\n};\n``` | 1 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | Easy to understand two pointer solution in Golalng | easy-to-understand-two-pointer-solution-h0vtk | go\nfunc minDeletion(nums []int) int {\n left, right := 0, 1\n var deletions int\n for right < len(nums) {\n // Move the right pointer as much as needed s | user0440H | NORMAL | 2022-06-28T08:19:43.065720+00:00 | 2022-06-28T08:19:43.065754+00:00 | 29 | false | ```go\nfunc minDeletion(nums []int) int {\n left, right := 0, 1\n var deletions int\n for right < len(nums) {\n // Move the right pointer as much as needed so that the elements at\n\t// left and right are different\n for right < len(nums) && nums[right] == nums[left] {\n right++\n deletions++\n }\... | 1 | 0 | ['Two Pointers', 'Go'] | 0 |
minimum-deletions-to-make-array-beautiful | C++ Solution Using Deque | c-solution-using-deque-by-kunal_patil-8qyc | \'\'\'\n\n int minDeletion(vector& nums) {\n deque p,q;\n int ans=0;\n \n for(int i=0;i<nums.size();i++)\n {\n | kunal_patil | NORMAL | 2022-05-25T07:45:38.169065+00:00 | 2022-05-25T07:45:38.169096+00:00 | 63 | false | \'\'\'\n\n int minDeletion(vector<int>& nums) {\n deque<int> p,q;\n int ans=0;\n \n for(int i=0;i<nums.size();i++)\n {\n p.push_back(nums[i]);\n }\n \n q.push_back(p.front());\n p.pop_front();\n \n while(!p.empty())\n {\n ... | 1 | 0 | ['Queue', 'C'] | 0 |
minimum-deletions-to-make-array-beautiful | [Java] Stack | java-stack-by-teemo25-i5mb | \nclass Solution {\n\n public int minDeletion(int[] nums) {\n Deque<Integer> stack = new ArrayDeque();\n int delete = 0;\n for (int num : nums) {\n | teemo25 | NORMAL | 2022-05-21T17:59:48.184927+00:00 | 2022-05-21T17:59:48.184973+00:00 | 57 | false | ```\nclass Solution {\n\n public int minDeletion(int[] nums) {\n Deque<Integer> stack = new ArrayDeque();\n int delete = 0;\n for (int num : nums) {\n if (stack.size() % 2 == 0) {\n stack.push(num);\n } else {\n if (stack.peek() == num) {\n delete++;\n } else {\n ... | 1 | 0 | ['Java'] | 0 |
minimum-deletions-to-make-array-beautiful | Find the Shift Index After Removal | find-the-shift-index-after-removal-by-sr-ovuw | \nclass Solution {\n public int minDeletion(int[] nums) {\n int del = 0;\n int n = nums.length;\n \n for(int i = 0; i < nums.leng | Srijit_1998 | NORMAL | 2022-05-04T16:11:28.726680+00:00 | 2022-05-04T16:11:28.726798+00:00 | 25 | false | ```\nclass Solution {\n public int minDeletion(int[] nums) {\n int del = 0;\n int n = nums.length;\n \n for(int i = 0; i < nums.length-1; i++){\n int shiftIndex = (i - del);\n if(nums[i] == nums[i+1] && shiftIndex % 2 == 0){\n del++;\n }\n ... | 1 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | Java | O(N) | java-on-by-pratham_ghule-v9c2 | \nclass Solution {\n public int minDeletion(int[] nums) {\n int count=0;\n \n for(int i=0;i<nums.length;i+=2){\n if(i<nums.len | pratham_ghule | NORMAL | 2022-04-16T09:19:17.135202+00:00 | 2022-04-16T09:19:17.135249+00:00 | 89 | false | ```\nclass Solution {\n public int minDeletion(int[] nums) {\n int count=0;\n \n for(int i=0;i<nums.length;i+=2){\n if(i<nums.length-1 && nums[i]==nums[i+1]){\n count++;\n i--;\n }\n }\n \n if((nums.length-count)%2!=0)\n ... | 1 | 0 | ['Java'] | 1 |
minimum-deletions-to-make-array-beautiful | c solution with faster 95% and less memory 80% | c-solution-with-faster-95-and-less-memor-745z | \n/*\nShare\nYou are given a 0-indexed integer array nums. The array nums is beautiful if:\n\nnums.length is even.\nnums[i] != nums[i + 1] for all i % 2 == 0.\n | jason01200120 | NORMAL | 2022-04-12T09:53:10.811077+00:00 | 2022-04-14T12:36:51.866373+00:00 | 25 | false | ```\n/*\nShare\nYou are given a 0-indexed integer array nums. The array nums is beautiful if:\n\nnums.length is even.\nnums[i] != nums[i + 1] for all i % 2 == 0.\nNote that an empty array is considered beautiful.\n\nYou can delete any number of elements from nums. When you delete an element, all the elements to the rig... | 1 | 0 | ['C'] | 0 |
minimum-deletions-to-make-array-beautiful | Easy Stack Solution with comments | easy-stack-solution-with-comments-by-the-ak3u | \nclass Solution {\n public int minDeletion(int[] nums) {\n int currIdx = -1;\n int ans = 0;\n // stores beautiful array on the go\n | theashishmalik | NORMAL | 2022-04-10T10:09:51.930233+00:00 | 2022-04-10T10:09:51.930276+00:00 | 132 | false | ```\nclass Solution {\n public int minDeletion(int[] nums) {\n int currIdx = -1;\n int ans = 0;\n // stores beautiful array on the go\n Stack<Integer> st = new Stack<>();\n for(int i : nums) {\n if (st.isEmpty() || st.peek()!=i || currIdx%2!=0) {\n st.push... | 1 | 0 | ['Stack', 'Java'] | 0 |
minimum-deletions-to-make-array-beautiful | Easy Java Solution | easy-java-solution-by-ujjwalsharma-f0ei | \nclass Solution {\n public int minDeletion(int[] nums) {\n int count=0;\n \n for(int i=0;i<nums.length-1;i++){\n // shifting | UjjwalSharma | NORMAL | 2022-04-06T13:00:01.766538+00:00 | 2022-04-06T13:00:01.766587+00:00 | 32 | false | ```\nclass Solution {\n public int minDeletion(int[] nums) {\n int count=0;\n \n for(int i=0;i<nums.length-1;i++){\n // shifting the index if the 1st element is removed than \n // the index of the 2nd element will be 2-1=1 where \n // 1 is the number of count\n ... | 1 | 0 | ['Java'] | 0 |
minimum-deletions-to-make-array-beautiful | JAVA O(1) SPACE || EASY TO UNDERSTAND | java-o1-space-easy-to-understand-by-magi-m28a | \nclass Solution {\n public int minDeletion(int[] nums) {\n int n=nums.length;\n\n int dlt=0;\n for(int i=0;i<n-1;i++){\n if( | magic04 | NORMAL | 2022-04-04T09:27:28.146237+00:00 | 2022-07-21T12:57:41.183417+00:00 | 41 | false | ```\nclass Solution {\n public int minDeletion(int[] nums) {\n int n=nums.length;\n\n int dlt=0;\n for(int i=0;i<n-1;i++){\n if(nums[i]==nums[i+1] && (i-dlt)%2==0){ // i-dlt indicates the index shift in the left\n dlt++;\n }\n }\n if((n-dlt)%2=... | 1 | 0 | [] | 1 |
minimum-deletions-to-make-array-beautiful | Easy to Understand||C++ | easy-to-understandc-by-codekarle-al2b | class Solution {\npublic:\n\n int minDeletion(vector& nums) {\n int ans=0;\n for(int i=1;i<nums.size();i++){\n if(((i-1)-ans)%2==0 & | codekarle | NORMAL | 2022-04-02T06:12:26.179754+00:00 | 2022-04-02T06:12:26.179785+00:00 | 102 | false | class Solution {\npublic:\n\n int minDeletion(vector<int>& nums) {\n int ans=0;\n for(int i=1;i<nums.size();i++){\n if(((i-1)-ans)%2==0 && nums[i]==nums[i-1] ){\n ans++;\n }\n //12233\n }\n //12233 but size is odd so we have to remove one bu... | 1 | 0 | ['C', 'C++'] | 0 |
minimum-deletions-to-make-array-beautiful | Minimum Deletions to Make Array Beautiful | minimum-deletions-to-make-array-beautifu-9r5u | \n# First I am looking for value at index even and repeating at the next index. \n# If it occurs means one deletion means now all values shifts to even, and eve | prabhatm580 | NORMAL | 2022-04-02T05:49:01.874095+00:00 | 2022-04-02T05:49:01.874130+00:00 | 63 | false | ```\n# First I am looking for value at index even and repeating at the next index. \n# If it occurs means one deletion means now all values shifts to even, and even shifted to odd.\n# for example [1,1,2,2,3,3] at 0th index we found a repeating element \n# Now after deletion [1,2,2,3,3] becomes new array and now 2 is no... | 1 | 0 | ['Greedy', 'C', 'C++'] | 0 |
minimum-deletions-to-make-array-beautiful | ✅ 3ms fasterthan100 || greedy || TC: O(n), SC: O(1) || 2 ways | 3ms-fasterthan100-greedy-tc-on-sc-o1-2-w-0elv | If you\'ll like, do UpVote :)\n\nNote for Coding Interviews:\n\t\n\t1. I mentioned 2 solutions keeping Coding interviews in mind, where you can first talk abou | karankhara | NORMAL | 2022-03-31T20:12:00.960223+00:00 | 2022-04-01T15:29:48.722271+00:00 | 79 | false | If you\'ll like, do **UpVote** :)\n\n**Note for Coding Interviews:**\n\t\n\t1. I mentioned 2 solutions keeping Coding interviews in mind, where you can first talk about Solution 1 and,\n\t\t then optimize it right after using Solution 2 :) \n\t2. It is always recommended to start with brute force and then bring more ... | 1 | 0 | ['Java'] | 1 |
minimum-deletions-to-make-array-beautiful | O(n) Varun | on-varun-by-vchawla100-hk7l | Elegant solutionnnnn.\n\nclass Solution {\n public int minDeletion(int[] arr) { // odd even // 1 1 1 2 3 4 4;\n if(arr.length == 1) return 1;\n | vchawla100 | NORMAL | 2022-03-31T17:28:19.960237+00:00 | 2022-03-31T17:28:19.960275+00:00 | 47 | false | Elegant solutionnnnn.\n```\nclass Solution {\n public int minDeletion(int[] arr) { // odd even // 1 1 1 2 3 4 4;\n if(arr.length == 1) return 1;\n \n Queue<Integer> even = new ArrayDeque<>(); // \n Queue<Integer> odd = new ArrayDeque<>(); // \n int cnt = 0;\n boolean flag... | 1 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | C++ || Greedy || Clean Code | c-greedy-clean-code-by-niks07-ec4a | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int n=nums.size();\n int deletions=0;\n for(int i=0;i+deletions+1<n | niks07 | NORMAL | 2022-03-31T12:13:30.166623+00:00 | 2022-03-31T12:13:30.166668+00:00 | 71 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int n=nums.size();\n int deletions=0;\n for(int i=0;i+deletions+1<n;i+=2){\n while(i+deletions+1<n and nums[i+deletions]==nums[i+deletions+1])\n deletions++;\n }\n \n \n ... | 1 | 0 | ['Greedy', 'C'] | 0 |
minimum-deletions-to-make-array-beautiful | JAVA || STACK || EASY || EXPLAINATION | java-stack-easy-explaination-by-bhaskar2-3md0 | Here in order to solve this question we need to consider some cases and need to keep those in our mind:\n If stack has even elements that\'s if(stk.size()%2==0) | bhaskar20inn | NORMAL | 2022-03-30T19:56:11.118421+00:00 | 2022-03-30T19:56:11.118467+00:00 | 125 | false | Here in order to solve this question we need to consider some cases and need to keep those in our mind:\n* If stack has even elements that\'s `if(stk.size()%2==0)` then we know that only even indexes are needed to be considered as per real-time arraty so we just add that number in stack\n* Now second case is when we ha... | 1 | 0 | ['Stack', 'Greedy', 'Java'] | 0 |
minimum-deletions-to-make-array-beautiful | Python - Easy | python-easy-by-lokeshsk1-kt7k | \nclass Solution:\n def minDeletion(self, nums: List[int]) -> int:\n \n res = 0\n i = 0\n n = len(nums)\n \n while | lokeshsk1 | NORMAL | 2022-03-29T17:17:30.276433+00:00 | 2022-03-29T17:17:30.276469+00:00 | 107 | false | ```\nclass Solution:\n def minDeletion(self, nums: List[int]) -> int:\n \n res = 0\n i = 0\n n = len(nums)\n \n while i < n-1:\n if nums[i] == nums[i+1]:\n res += 1\n i += 1\n else:\n i += 2\n \n ... | 1 | 0 | ['Python', 'Python3'] | 0 |
minimum-deletions-to-make-array-beautiful | Minimum Deletions to Make Array Beautiful O(N) single pass C++ | minimum-deletions-to-make-array-beautifu-yanz | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n bool even=true;\n int count=0;\n for(int i=1;i<nums.size();i++){\n | arpitpachauri220 | NORMAL | 2022-03-29T14:35:07.556302+00:00 | 2022-03-29T14:35:07.556340+00:00 | 45 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n bool even=true;\n int count=0;\n for(int i=1;i<nums.size();i++){\n if(even==true && i%2==1){\n if(nums[i]==nums[i-1]){\n count++;\n even=false;\n }\n ... | 1 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | Simple Solution in Java || Elegant and Concise | simple-solution-in-java-elegant-and-conc-atus | \nclass Solution {\n public int minDeletion(int[] nums) {\n \n boolean evenIndex = true;\n int ans = 0; \n int i = 0;\n | PRANAV_KUMAR99 | NORMAL | 2022-03-29T04:57:34.954030+00:00 | 2022-03-29T05:01:00.715731+00:00 | 15 | false | ```\nclass Solution {\n public int minDeletion(int[] nums) {\n \n boolean evenIndex = true;\n int ans = 0; \n int i = 0;\n while(i < nums.length){\n if(evenIndex == false){\n // The current number is at odd index, the next will be at even index\n ... | 1 | 0 | [] | 0 |
minimum-deletions-to-make-array-beautiful | Beginner friendly Java Solution!!! | beginner-friendly-java-solution-by-kabil-lxot | \nclass Solution {\n public int minDeletion(int[] nums) {\n int deletions=0,shiftedIndex=0,numslen=nums.length;\n for(int i=0;i<numslen;i++){\n | kabiland | NORMAL | 2022-03-28T13:42:44.997000+00:00 | 2022-03-28T13:42:44.997028+00:00 | 25 | false | ```\nclass Solution {\n public int minDeletion(int[] nums) {\n int deletions=0,shiftedIndex=0,numslen=nums.length;\n for(int i=0;i<numslen;i++){\n shiftedIndex=i-deletions;\n if(shiftedIndex%2==0){\n if(i!=numslen-1 && nums[i]==nums[i+1])\n deleti... | 1 | 0 | ['Array', 'Java'] | 0 |
minimum-deletions-to-make-array-beautiful | C++ easy to understand | c-easy-to-understand-by-shanushan-oc1e | Just skip untill adjacent pair is equal.\n\n\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int ans = 0;\n int n = nums.si | shanushan | NORMAL | 2022-03-28T11:30:02.595033+00:00 | 2022-03-28T11:30:02.595061+00:00 | 29 | false | Just skip untill adjacent pair is equal.\n\n```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n int ans = 0;\n int n = nums.size();\n int i = 0;\n while(i < n){\n int j = i + 1;\n while(j < n and nums[i] == nums[j]){\n j += 1;\n ... | 1 | 0 | ['Two Pointers', 'Greedy'] | 0 |
minimum-deletions-to-make-array-beautiful | c++ || stack | c-stack-by-ayushanand245-4wju | \nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n bool k = false;\n int n = nums.size();\n if(n%2==0) k=true;\n | ayushanand245 | NORMAL | 2022-03-28T07:54:03.482027+00:00 | 2022-03-28T07:54:03.482061+00:00 | 23 | false | ```\nclass Solution {\npublic:\n int minDeletion(vector<int>& nums) {\n bool k = false;\n int n = nums.size();\n if(n%2==0) k=true;\n \n stack<int> st;\n int p=0;\n st.push(nums[p++]);\n int count=0;\n while(p < n){\n if((st.size()-1)%2==0 && ... | 1 | 0 | [] | 0 |
abbreviating-the-product-of-a-range | Modulo and Double | modulo-and-double-by-votrubac-lizi | First, after any multiplication, we get rid of trailing zeros, counting them in c.\n\nNow, how to find out the last 5 digits of the product? For that, we multip | votrubac | NORMAL | 2021-12-25T20:48:55.808879+00:00 | 2022-01-09T00:20:03.995591+00:00 | 2,604 | false | First, after any multiplication, we get rid of trailing zeros, counting them in `c`.\n\nNow, how to find out the last 5 digits of the product? For that, we multiply numbers, remove trailing zeros, and keep last `n` digits using the modulo operation. Simple.\n\nWhat about the first 5 digits? We could use `double`, multi... | 57 | 4 | ['C'] | 6 |
abbreviating-the-product-of-a-range | ✅ [C++/Java/Python] Scientific Notation || Very Detailed Explanation || With and Without Logarithm | cjavapython-scientific-notation-very-det-eo2l | \nPLEASE UPVOTE if you like \uD83D\uDE01 If you have any question, feel free to ask. \n\n\nThere is no free lunch, both logarithmic sum and scientific notation | linfq | NORMAL | 2021-12-25T16:01:56.731911+00:00 | 2022-01-18T06:40:58.360411+00:00 | 2,486 | false | \n**PLEASE UPVOTE if you like** \uD83D\uDE01 **If you have any question, feel free to ask.** \n<br>\n\nThere is no free lunch, both logarithmic sum and scientific notation will definitely lose accuracy. we can only discard the last digits and keep the most important prefix as many as possible, actually `float` even `do... | 36 | 3 | [] | 9 |
abbreviating-the-product-of-a-range | [Python] math soluthion, explained | python-math-soluthion-explained-by-dbabi-7uc9 | I will tidy up my code a bit later, for the moment what is important is idea. Basically, problem can be separated into 3 independet smaller problems:\n\n1. Find | dbabichev | NORMAL | 2021-12-25T16:00:46.438846+00:00 | 2021-12-25T16:00:46.438876+00:00 | 1,884 | false | I will tidy up my code a bit later, for the moment what is important is idea. Basically, problem can be separated into 3 independet smaller problems:\n\n1. Find number of trailing zeroes.\n2. Find last 5 digits which are not zeroes.\n3. Find first 5 digits.\n\nLet us deal with this problems one by one.\n1. To find numb... | 28 | 7 | ['Math'] | 6 |
abbreviating-the-product-of-a-range | [python] Feel so sorry about the man who was asked this problem in the interview. | python-feel-so-sorry-about-the-man-who-w-e3gh | I don\'t like this type of question, although I solved it in the contest. \nIt is pure math, and nearly doesn\'t contain any algorithem. Maybe the hedge fo | hxu10 | NORMAL | 2021-12-25T16:35:20.877631+00:00 | 2022-01-01T17:08:49.519512+00:00 | 1,237 | false | I don\'t like this type of question, although I solved it in the contest. \nIt is pure math, and nearly doesn\'t contain any algorithem. Maybe the hedge found like this problem. \n\n##### Also, according to @hqztrue , there are possibly some annoying edge testcases, if the product is like xxxxx99999999.... o... | 14 | 2 | [] | 2 |
abbreviating-the-product-of-a-range | [Python3] quasi brute-force | python3-quasi-brute-force-by-ye15-jt3g | Please check out this commit for solutions of biweekly 68. \n\n\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n ans = | ye15 | NORMAL | 2021-12-25T16:02:35.209453+00:00 | 2021-12-25T17:41:51.630253+00:00 | 964 | false | Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/8bba95f803d58a5e571fa13de6635c96f5d1c1ee) for solutions of biweekly 68. \n\n```\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n ans = prefix = suffix = 1\n trailing = 0 \n flag = False \n... | 14 | 3 | ['Python3'] | 6 |
abbreviating-the-product-of-a-range | Python | Use Log Value, explained | python-use-log-value-explained-by-zoo302-0ftp | First we notice that the trailing zeroes should be abbreviated, so we can calculate the number of trailing zeroes by calculating how many 2 and 5 in the result | zoo30215 | NORMAL | 2021-12-25T16:00:59.523268+00:00 | 2021-12-25T16:37:40.618744+00:00 | 436 | false | First we notice that the trailing zeroes should be abbreviated, so we can calculate the number of trailing zeroes by calculating how many `2` and `5` in the result of prime factorization of the product, and the number of trailing zeroes is the minimum between the two values.\n\nNext we notice that we only need to calcu... | 10 | 1 | [] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.