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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
apply-operations-to-an-array | Short and sweet solution in Leetcode history | short-and-sweet-solution-in-leetcode-his-8jcu | \n\n# Code\n\nclass Solution {\npublic:\n vector<int> applyOperations(vector<int>& nums) {\n int n=nums.size();\n for(int i=0;i<n-1;i++){\n | vishnoi29 | NORMAL | 2022-11-06T04:17:40.476537+00:00 | 2022-11-06T04:17:40.476582+00:00 | 710 | false | \n\n# Code\n```\nclass Solution {\npublic:\n vector<int> applyOperations(vector<int>& nums) {\n int n=nums.size();\n for(int i=0;i<n-1;i++){\n if(nums[i]==nums[i+1]){\n nums[i]=nums[i]*2;\n nums[i+1]=0;\n }\n }\n int nc=0;\n for(i... | 9 | 0 | ['Array', 'C++'] | 1 |
apply-operations-to-an-array | Simple Do what is said!! | simple-do-what-is-said-by-arunk_leetcode-c47s | IntuitionThe problem requires us to process adjacent elements in an array and move all zeros to the end while preserving the order of non-zero elements.Approach | arunk_leetcode | NORMAL | 2025-03-01T04:28:46.847697+00:00 | 2025-03-01T04:28:46.847697+00:00 | 545 | false | # Intuition
The problem requires us to process adjacent elements in an array and move all zeros to the end while preserving the order of non-zero elements.
# Approach
1. Traverse the array once and check for adjacent equal elements.
2. If two consecutive elements are equal, double the first element and set the second ... | 8 | 0 | ['Array', 'Two Pointers', 'Simulation', 'C++'] | 0 |
apply-operations-to-an-array | Easy Python Solution | easy-python-solution-by-vistrit-aekb | \n# Code\n\nclass Solution:\n def applyOperations(self, nums: List[int]) -> List[int]:\n l=[]\n c=0\n for i in range(len(nums)-1):\n | vistrit | NORMAL | 2022-11-15T16:13:54.192701+00:00 | 2022-11-15T16:13:54.192748+00:00 | 1,124 | false | \n# Code\n```\nclass Solution:\n def applyOperations(self, nums: List[int]) -> List[int]:\n l=[]\n c=0\n for i in range(len(nums)-1):\n if(nums[i]==nums[i+1]):\n nums[i]=nums[i]*2\n nums[i+1]=0\n for i in nums:\n if i!=0:\n ... | 8 | 0 | ['Python', 'Python3'] | 0 |
apply-operations-to-an-array | C++ clean and simple sol || single pass || Time O(N) || Space O(1) | c-clean-and-simple-sol-single-pass-time-yj4mv | \nclass Solution {\npublic:\n vector<int> applyOperations(vector<int>& nums) {\n \n int j=0;\n for(int i=0;i<nums.size()-1;i++)\n | aniketpawar | NORMAL | 2022-11-06T05:59:52.769053+00:00 | 2022-11-06T09:12:45.505257+00:00 | 643 | false | ```\nclass Solution {\npublic:\n vector<int> applyOperations(vector<int>& nums) {\n \n int j=0;\n for(int i=0;i<nums.size()-1;i++)\n {\n if(nums[i]&&nums[i]==nums[i+1])\n {\n int a=nums[i]*2;\n nums[i]=nums[i+1]=0;\n nums[... | 8 | 0 | ['C'] | 0 |
apply-operations-to-an-array | Efficient Array Transformation: Merging & Zero Shifting | efficient-array-transformation-merging-z-g18u | IntuitionThe problem requires sequentially modifying the array by merging adjacent equal elements and shifting all zeros to the end. The key idea is to perform | anill056 | NORMAL | 2025-03-01T16:39:41.977521+00:00 | 2025-03-01T16:39:41.977521+00:00 | 14 | false | # Intuition
The problem requires sequentially modifying the array by merging adjacent equal elements and shifting all zeros to the end. The key idea is to perform these operations in a step-by-step manner while ensuring minimal extra operations and maintaining the relative order of elements.
# Approach
First, we itera... | 7 | 0 | ['Array', 'Simulation', 'C++'] | 0 |
apply-operations-to-an-array | Simple Java Solution | simple-java-solution-by-siddhant_2002-7x9g | Complexity
Time complexity: O(n)
Space complexity: O(1)
Code | siddhant_2002 | NORMAL | 2025-03-01T07:21:15.071822+00:00 | 2025-03-01T07:21:15.071822+00:00 | 369 | false | # Complexity
- Time complexity: $$O(n)$$
- Space complexity: $$O(1)$$
# Code
```java []
class Solution {
public int[] applyOperations(int[] nums) {
int len = nums.length;
for(int i = 0; i < len-1; i++)
{
if(nums[i] == nums[i+1])
{
nums[i] = nums[i] <... | 7 | 0 | ['Array', 'Two Pointers', 'Simulation', 'Java'] | 1 |
apply-operations-to-an-array | One Pass | one-pass-by-votrubac-qhuh | C++\ncpp\nvector<int> applyOperations(vector<int>& nums) {\n vector<int> res(nums.size());\n for(int i = 0, j = 0; i < nums.size(); ++i)\n if (nums | votrubac | NORMAL | 2022-11-14T17:35:48.411910+00:00 | 2022-11-14T17:35:48.411951+00:00 | 469 | false | **C++**\n```cpp\nvector<int> applyOperations(vector<int>& nums) {\n vector<int> res(nums.size());\n for(int i = 0, j = 0; i < nums.size(); ++i)\n if (nums[i]) {\n if (i < nums.size() - 1 && nums[i] == nums[i + 1]) {\n res[j++] = nums[i] * 2;\n nums[i + 1] = 0;\n ... | 7 | 0 | ['C'] | 1 |
apply-operations-to-an-array | Java One-pass | Time O(n) | Space O(n) | java-one-pass-time-on-space-on-by-chenli-niaz | \nclass Solution {\n public int[] applyOperations(int[] nums) {\n int[] ans = new int[nums.length];\n if (nums.length == 0) return ans;\n | chenlize96 | NORMAL | 2022-11-06T04:08:31.848622+00:00 | 2022-11-09T06:50:34.736758+00:00 | 761 | false | ```\nclass Solution {\n public int[] applyOperations(int[] nums) {\n int[] ans = new int[nums.length];\n if (nums.length == 0) return ans;\n int pointer = 0;\n for (int i = 0; i < nums.length - 1; i++) {\n if (nums[i] == nums[i + 1] && nums[i] != 0) {\n nums[i] *... | 7 | 0 | ['Java'] | 1 |
apply-operations-to-an-array | Brute Force Approach | brute-force-approach-by-burle_damodar-dzan | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Burle_Damodar | NORMAL | 2025-03-01T06:13:20.908288+00:00 | 2025-03-01T06:13:20.908288+00:00 | 284 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 6 | 0 | ['C++'] | 0 |
apply-operations-to-an-array | Good to go💯🚀. Must read Easy Template | good-to-go-must-read-easy-template-by-di-l008 | 26. Remove Duplicates from Sorted Array\n27. Remove Element\n80. Remove Duplicates from Sorted Array II\n283. Move Zeroes\n2460. Apply Operations to an Array\n9 | Dixon_N | NORMAL | 2024-09-19T21:36:43.266551+00:00 | 2024-09-19T22:51:13.387937+00:00 | 322 | false | [26. Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/solutions/5505499/my-accepted-java-solution/)\n[27. Remove Element](https://leetcode.com/problems/remove-element/solutions/5505493/good-to-go/)\n[80. Remove Duplicates from Sorted Array II](https://leetcode.com/p... | 6 | 0 | ['Java'] | 3 |
apply-operations-to-an-array | JAVA | apply-operations-to-an-array | java-apply-operations-to-an-array-by-ven-q0eq | \nclass Solution {\n public int[] applyOperations(int[] nums) {\n int k=0;\n int n=nums.length;\n for(int i=0;i<n-1;i++)\n {\n | Venkat089 | NORMAL | 2022-11-06T10:54:08.109872+00:00 | 2022-11-06T10:54:08.109912+00:00 | 681 | false | ```\nclass Solution {\n public int[] applyOperations(int[] nums) {\n int k=0;\n int n=nums.length;\n for(int i=0;i<n-1;i++)\n {\n if(nums[i]==nums[i+1]){\n nums[i]*=2;\n nums[i+1]=0;\n }\n if(nums[i]!=0)nums[k++]=nums[i];\n ... | 6 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | Java Easy Solution | java-easy-solution-by-abhishekalimchanda-fpf7 | \n# Code\n\nclass Solution {\n public int[] moveZeroes(int[] nums) {\n if(nums.length == 0 || nums == null) return nums;\n int j = 0;\n | abhishekalimchandani69 | NORMAL | 2022-11-06T06:15:01.450344+00:00 | 2022-11-06T06:15:01.450388+00:00 | 1,090 | false | \n# Code\n```\nclass Solution {\n public int[] moveZeroes(int[] nums) {\n if(nums.length == 0 || nums == null) return nums;\n int j = 0;\n for (int i : nums){\n if(i!=0) nums[j++] = i;\n }\n while (j< nums.length){\n nums[j++] = 0;\n }\n return n... | 6 | 0 | ['Java'] | 2 |
apply-operations-to-an-array | two pointers approach O(1) space || JAVA || python || python3 | two-pointers-approach-o1-space-java-pyth-limf | IntuitionApproachiterate every pair of elements and check whether it is same or not if same then perform actions he gave
Approach 1 :
create an empty arr of siz | yuvejkumar | NORMAL | 2025-03-01T17:40:43.153309+00:00 | 2025-03-01T17:40:43.153309+00:00 | 130 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
iterate every pair of elements and check whether it is same or not if same then perform actions he gave
Approach 1 :
create an empty arr of size nums.length
iterate in nums... | 5 | 0 | ['Python', 'Java', 'Python3'] | 0 |
apply-operations-to-an-array | JAVA | java-by-choudhry7-p71u | Code | choudhry7 | NORMAL | 2025-03-01T08:37:01.415894+00:00 | 2025-03-01T08:37:01.415894+00:00 | 87 | false |
# Code
```java []
class Solution {
public int[] applyOperations(int[] nums) {
int nz=0;
int n = nums.length;
for(int i=0;i<n;i++){
if(i < n-1 && nums[i]!=0 && nums[i]==nums[i+1]){
nums[i]*=2;
nums[i+1]=0;
}
if(nums[i]!=0)... | 5 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | Easy and Beginner Friendly Solution💯. Apply Operations to an Array (Optimized Solution 🚀) | easy-and-beginner-friendly-solution-appl-7ix8 | IntuitionThe problem requires modifying the array based on adjacent values and then rearranging it efficiently.The key steps involve merging adjacent equal elem | VATSAL_30 | NORMAL | 2025-03-01T04:25:47.746913+00:00 | 2025-03-01T04:25:47.746913+00:00 | 180 | false |
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires modifying the array based on adjacent values and then rearranging it efficiently.
The key steps involve merging adjacent equal elements and shifting non-zero elements to the front while pushing zeros to the end.
A s... | 5 | 0 | ['C++'] | 0 |
apply-operations-to-an-array | Beats 100% | Array | Two Pointers | Solution for LeetCode#2460 | beats-100-array-two-pointers-solution-fo-fm2i | IntuitionThe problem requires applying a specific operation to an array and then moving all non-zero elements to the left while preserving their relative order. | samir023041 | NORMAL | 2025-03-01T01:30:46.135696+00:00 | 2025-03-01T01:30:46.135696+00:00 | 548 | false | 
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires applying a specific operation to an array and then moving all non-zero elements to the left while preser... | 5 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | Easy Solution Using Java with Explaination | easy-solution-using-java-with-explainati-2mrc | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nThe approach is to use | hashcoderz | NORMAL | 2022-11-06T04:15:38.728642+00:00 | 2022-11-08T04:58:26.567971+00:00 | 2,519 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach is to use an arraylist and then add the elements in it.\nif nums[i]==nums[i+1] then we multiply nums[i]*=2 & set nums[i+1]=0.\nThen we count the number o... | 5 | 0 | ['Java'] | 3 |
apply-operations-to-an-array | ✅ Java Easy Solution ✅ | java-easy-solution-by-tangobee-l2fh | \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\n- Space complexity: | TangoBee | NORMAL | 2022-11-06T04:04:39.408003+00:00 | 2022-11-06T04:04:39.408038+00:00 | 852 | false | \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\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int[] applyOperations(int[] nums) {... | 5 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | ✅ 🔥 0ms Runtime Beats 100% || Efficient Array Transformation: Merging & Zero Shifting 🚀 | 0ms-runtime-beats-100-efficient-array-tr-7whe | 🌟 Intuition:The task is to modify the array by merging adjacent equal elements and moving zeros to the end. The idea is to:Merge Adjacent Equal Elements: If two | 4oICmhj3tm | NORMAL | 2025-03-03T13:14:13.558726+00:00 | 2025-03-03T13:16:52.147867+00:00 | 43 | false | 
# 🌟 Intuition:
The task is to modify the array by merging adjacent equal elements and moving zeros to the end. ***The idea is to:***
**Merge Adjacent Equal Elements:** If two adjacent numbers are the ... | 4 | 0 | ['Array', 'Java'] | 1 |
apply-operations-to-an-array | 🏆 THE MOST EASIEST TO UNDERSTAND SOLUTION | Beats 100 % 🎯 💯 | the-most-easiest-to-understand-solution-v9w98 | IntuitionThe problem requires modifying an array based on specific operations: doubling consecutive equal elements and shifting non-zero elements to the front. | Adiverse_7 | NORMAL | 2025-03-01T19:53:06.608374+00:00 | 2025-03-01T19:53:06.608374+00:00 | 18 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires modifying an array based on specific operations: doubling consecutive equal elements and shifting non-zero elements to the front.
Observing the requirements, a single pass can handle both operations efficiently.
# Ap... | 4 | 0 | ['C++'] | 2 |
apply-operations-to-an-array | 👩💻Easy 🔥 Just read & code💻 | easy-just-read-code-by-patilprajakta-85y8 | Please Upvote only if you get something from my Solution! 💡🙌Don't give up! Keep practising! 😊🔥📚First just store array length in variable n.Then create new array | patilprajakta | NORMAL | 2025-03-01T16:36:31.209665+00:00 | 2025-03-01T16:36:31.209665+00:00 | 94 | false | # Please Upvote only if you get something from my Solution! 💡🙌
# Don't give up! Keep practising! 😊🔥📚
------------------------------------------------------
First just store array length in variable n.
int n=nums.length;
Then create new array ans[] of size n.
int ans[]=new int[n];
Then use for loop & ju... | 4 | 0 | ['Array', 'Java'] | 0 |
apply-operations-to-an-array | 🔥Beats 100% |✨Easy Approach | Easy for Beginners | C++ | Java | beats-100-easy-approach-easy-for-beginne-mdrv | IntuitionWe need to modify the given array based on certain operations:
- If two consecutive elements are equal, double the first element and set the second ele | panvishdowripilli | NORMAL | 2025-03-01T14:28:56.925146+00:00 | 2025-03-01T14:28:56.925146+00:00 | 45 | false |

# Intuition
We need to modify the given array based on certain operations:
- If two consecutive elements are equal, double the first element and set the second element to 0.
... | 4 | 0 | ['Array', 'Simulation', 'C++', 'Java'] | 0 |
apply-operations-to-an-array | Optimal Solution ✅ for Applying Operations and Shifting Zeros in an Array | optimal-solution-for-applying-operations-vxrg | BEATS 100% 🚀Intuition 💡When two consecutive numbers are the same, we double the first and set the next to zero. Then, we simply move all non-zero numbers to the | lordprateekverma | NORMAL | 2025-03-01T13:04:55.209985+00:00 | 2025-03-01T13:04:55.209985+00:00 | 9 | false | ### BEATS 100% 🚀

# Intuition 💡
When two consecutive numbers are the same, we double the first and set the next to zero. Then, we simply move all non-zero numbers to the front and push zeros to the end.... | 4 | 0 | ['Two Pointers', 'C++'] | 0 |
apply-operations-to-an-array | JAVA CODE | java-code-by-ayeshakhan7-hsnl | Complexity
Time complexity: O(n)
Space complexity: O(1)
Code | ayeshakhan7 | NORMAL | 2025-03-01T08:29:37.394429+00:00 | 2025-03-01T08:29:37.394429+00:00 | 72 | false |
# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```java []
class Solution {
public int[] applyOperations(int[] nums) {
int n = nums.length;
//Simulation
... | 4 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | 🌟 Beats 96.37% 🌟 | ✔️ Easiest Solution & Beginner Friendly ✔️ | 🔥 1MS & 2MS 🔥 | 2 Solutions | beats-9359-easiest-solution-beginner-fri-wdbu | 🚀 Solution 1 : Brute Force (2MS)💡 IntuitionThe problem requires modifying an array based on adjacent equal elements and then shifting all zeros to the end. The | gauravpawar7 | NORMAL | 2025-03-01T04:18:30.501768+00:00 | 2025-03-01T04:19:33.200124+00:00 | 85 | false |
---

---

---
# 🚀 Solution 1 : Brute Force (2MS)
---
# 💡 Intuition
The problem require... | 4 | 0 | ['Array', 'Two Pointers', 'Greedy', 'Suffix Array', 'Sorting', 'Heap (Priority Queue)', 'Simulation', 'Combinatorics', 'C++', 'Java'] | 0 |
apply-operations-to-an-array | [ Python ] 🐍🐍 Simple Python Solution ✅✅ 89 ms | python-simple-python-solution-89-ms-by-s-61kh | \nclass Solution:\n def applyOperations(self, nums: List[int]) -> List[int]:\n for i in range(len(nums)-1):\n if nums[i]==nums[i+1]:\n | sourav638 | NORMAL | 2022-11-06T21:02:16.244754+00:00 | 2022-11-06T21:02:16.244784+00:00 | 1,139 | false | ```\nclass Solution:\n def applyOperations(self, nums: List[int]) -> List[int]:\n for i in range(len(nums)-1):\n if nums[i]==nums[i+1]:\n nums[i]*=2\n nums[i+1]=0 \n temp = []\n zeros = []\n a=nums\n for i in range(len(a)):\n ... | 4 | 0 | ['Python', 'Python3'] | 1 |
apply-operations-to-an-array | 🔥🔥 BINGO [ C++ ] Easy Clean Code :) | bingo-c-easy-clean-code-by-princesah999-jgt7 | \nclass Solution\n{\n public:\n vector<int> applyOperations(vector<int> &nums)\n {\n int n = nums.size() - 1;\n for (int | Princesah999 | NORMAL | 2022-11-06T05:09:27.116843+00:00 | 2022-11-06T05:09:27.116906+00:00 | 150 | false | ```\nclass Solution\n{\n public:\n vector<int> applyOperations(vector<int> &nums)\n {\n int n = nums.size() - 1;\n for (int i = 0; i < n;)\n {\n if (nums[i] == nums[i + 1])\n {\n nums[i] = nums[i] *2;\n ... | 4 | 0 | ['C', 'C++'] | 2 |
apply-operations-to-an-array | [C++] O(n) Easy Solution | c-on-easy-solution-by-ayush479-yisr | \nclass Solution {\npublic:\n vector<int> applyOperations(vector<int>& nums) {\n for(int i=0;i<nums.size()-1;i++){\n if(nums[i]==nums[i+1]) | Ayush479 | NORMAL | 2022-11-06T04:23:37.292581+00:00 | 2022-11-06T04:23:37.292623+00:00 | 184 | false | ```\nclass Solution {\npublic:\n vector<int> applyOperations(vector<int>& nums) {\n for(int i=0;i<nums.size()-1;i++){\n if(nums[i]==nums[i+1]){\n nums[i]*=2;\n nums[i+1]=0;\n }\n }\n int place=0;\n for(int i=0;i<nums.size();i++){\n ... | 4 | 0 | ['C'] | 0 |
apply-operations-to-an-array | ✔️ 2ms C++ solution | Explained | 2ms-c-solution-explained-by-coding_menan-nzyl | Here is the solution along with explanations in the comments:\n\nC++ []\nclass Solution {\npublic:\n vector<int> applyOperations(vector<int>& nums) {\n | coding_menance | NORMAL | 2022-11-06T04:02:16.728219+00:00 | 2022-11-06T04:08:14.651017+00:00 | 208 | false | Here is the solution along with explanations in the comments:\n\n``` C++ []\nclass Solution {\npublic:\n vector<int> applyOperations(vector<int>& nums) {\n for (int i{0}; i<nums.size()-1; ++i) {\n // checking if the number matches with the next one or not\n if (nums[i]==nums[i+1]) {\n ... | 4 | 0 | ['C++'] | 1 |
apply-operations-to-an-array | ✅C++ | ✅Brute-force approach | c-brute-force-approach-by-yash2arma-s7w4 | \nclass Solution \n{\npublic:\n vector<int> applyOperations(vector<int>& nums) \n {\n int n=nums.size();\n for(int i=0; i<n-1; i++)\n | Yash2arma | NORMAL | 2022-11-06T04:01:27.157283+00:00 | 2022-11-06T04:37:34.983170+00:00 | 1,531 | false | ```\nclass Solution \n{\npublic:\n vector<int> applyOperations(vector<int>& nums) \n {\n int n=nums.size();\n for(int i=0; i<n-1; i++)\n {\n if(nums[i]==nums[i+1])\n {\n nums[i] = 2*nums[i];\n nums[i+1] = 0;\n i++;\n ... | 4 | 0 | ['C', 'C++'] | 1 |
apply-operations-to-an-array | Beats 100% with JAVA Beginners Friendly || YoU HaVe To ChEck ThiS OUt | beats-100-with-java-beginners-friendly-y-53o9 | IntuitionThe main idea behind solving this problem is that if we follow the same process described in the problem's description, we need to first modify the arr | TAJUDDIN_USMAN_KHAN_2909 | NORMAL | 2025-03-01T23:51:37.712276+00:00 | 2025-03-02T01:34:43.304733+00:00 | 46 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The main idea behind solving this problem is that if we follow the same process described in the problem's description, we need to first modify the array as instructed and then move all the `0`s to the last positions. This is the naive brut... | 3 | 0 | ['Java'] | 1 |
apply-operations-to-an-array | Easiest solution , Very simple to understand for beginners also | easiest-solution-very-simple-to-understa-ayc3 | Intuition1.Initialization:
l is an empty list to store intermediate results.
ans is an empty list for the final answer.
x is a counter for the number of zeros e | Vedagna_12 | NORMAL | 2025-03-01T14:47:51.063306+00:00 | 2025-03-01T14:47:51.063306+00:00 | 34 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
**1.Initialization:**
- l is an empty list to store intermediate results.
- *ans* is an empty list for the final answer.
- x is a counter for the number of zeros encountered.
**2.Doubling and Zeroing:**
- The for loop goes through the lis... | 3 | 0 | ['Python3'] | 0 |
apply-operations-to-an-array | Easiest way | easiest-way-by-xayrulloh-39dz | Approach
If equal multiply by 2 (n * 2)
If result is zero (0) store it and don't add to result
Combine result and zeros (spread operator ...)
Complexity
Time c | Xayrulloh | NORMAL | 2025-03-01T07:44:29.101731+00:00 | 2025-03-01T07:44:29.101731+00:00 | 140 | false | # Approach
1. If equal multiply by 2 (n * 2)
2. If result is zero (0) store it and don't add to result
3. Combine result and zeros (spread operator ...)
# Complexity
- Time complexity:
O(n)
- Space complexity:
O(n) (IMO)
# Upwote if you want, I don't beg
# Code
```typescript []
function applyOperations(nums: number... | 3 | 0 | ['TypeScript'] | 1 |
apply-operations-to-an-array | ✅ Beginner Friendly | Easy to Understand | Two Pointers | Detailed Video Explanation 🔥 | beginner-friendly-easy-to-understand-two-t5j2 | IntuitionThe problem requires modifying an array in two steps:
If two adjacent elements are equal, double the first one and set the second to zero.
Shift all ze | sahilpcs | NORMAL | 2025-03-01T07:17:00.788561+00:00 | 2025-03-01T07:17:00.788561+00:00 | 97 | false | # Intuition
The problem requires modifying an array in two steps:
1. If two adjacent elements are equal, double the first one and set the second to zero.
2. Shift all zeroes to the end while maintaining the relative order of non-zero elements.
This hints at a **two-pass approach**—one for modifying the array and... | 3 | 0 | ['Array', 'Two Pointers', 'Simulation', 'Java'] | 0 |
apply-operations-to-an-array | EASY C++ CODE WITH GOOD/DETAILED EXPLANATION | easy-c-code-with-gooddetailed-explanatio-lstg | IntuitionWhen I first saw this problem, I recognized it had two distinct parts:
Apply the doubling operation on equal adjacent elements
Move all resulting zeroe | YoGeSh_P2004 | NORMAL | 2025-03-01T05:11:06.307795+00:00 | 2025-03-01T05:11:06.307795+00:00 | 122 | false | # Intuition
When I first saw this problem, I recognized it had two distinct parts:
1. Apply the doubling operation on equal adjacent elements
1. Move all resulting zeroes to the end while preserving the order of other elements
The natural approach is to handle these operations sequentially rather than trying to combin... | 3 | 0 | ['C++'] | 0 |
apply-operations-to-an-array | BruteForce Java Solution ✅✅✅ | bruteforce-java-solution-by-bharanidhara-xbt7 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | BHARANIdharankumaresan | NORMAL | 2025-03-01T04:06:13.493589+00:00 | 2025-03-01T04:06:13.493589+00:00 | 35 | false | ### ******Intuition******
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$... | 3 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | 100% Beat Simple Solution | 100-beat-simple-solution-by-viratkohli-vh9n | Complexity
Time complexity: O(N)
Space complexity: O(N)
Code | viratkohli_ | NORMAL | 2025-03-01T03:57:36.308161+00:00 | 2025-03-01T03:57:36.308161+00:00 | 95 | false | 
# Complexity
- Time complexity: O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(N)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```cpp []
class Solutio... | 3 | 0 | ['Array', 'Two Pointers', 'Simulation', 'C++'] | 0 |
apply-operations-to-an-array | "Applying Operations and Rearranging an Array of Non-Negative Integers" | applying-operations-and-rearranging-an-a-q66o | IntuitionThe problem requires us to sequentially apply operations on an array where we double the value of an element if it is equal to its neighbor and set the | ofc_tarunn | NORMAL | 2025-03-01T02:39:05.931990+00:00 | 2025-03-01T02:39:05.931990+00:00 | 30 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires us to sequentially apply operations on an array where we double the value of an element if it is equal to its neighbor and set the neighbor to zero. After processing all elements, we also need to shift all zeros to the ... | 3 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | Two pointers. 0 ms JS/TS. Beats 100.00% | two-pointers-0-ms-jsts-beats-10000-by-no-mi7p | ApproachTwo pointers.Complexity
Time complexity: O(n)
Space complexity: O(1)
Code | nodeforce | NORMAL | 2025-03-01T00:46:03.079638+00:00 | 2025-03-01T00:54:14.282732+00:00 | 143 | false | # Approach
Two pointers.

# Complexity
- Time complexity: $$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: $$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
... | 3 | 0 | ['Array', 'Two Pointers', 'Simulation', 'TypeScript', 'JavaScript'] | 0 |
apply-operations-to-an-array | Java Solution💪✨ | | Beats 100% 🚀🚀 | | Solution By Kanishka 🧠 🧠 | java-solution-beats-100-solution-by-kani-xe5f | IntuitionThe problem requires us to apply two operations:
If two adjacent elements are equal, double the first element and set the second element to zero.
Shift | kanishka21535 | NORMAL | 2025-02-13T05:27:14.784801+00:00 | 2025-02-13T05:27:14.784801+00:00 | 123 | false | # Intuition
The problem requires us to apply two operations:
1. If two adjacent elements are equal, double the first element and set the second element to zero.
2. Shift all non-zero elements to the left while maintaining their order, and fill the remaining positions with zeros.
To efficiently solve this, we process t... | 3 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | Easiest beginner friendly solution | easiest-beginner-friendly-solution-by-a_-ae0x | 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 | A_drishti1 | NORMAL | 2024-05-07T10:32:45.195985+00:00 | 2024-05-07T10:32:45.196018+00:00 | 149 | 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++'] | 0 |
apply-operations-to-an-array | 👏Beats 93.57% of users with Java || 1ms Easy & Simple Explained Solution 🔥💥 | beats-9357-of-users-with-java-1ms-easy-s-2o4g | Intuition\nCheck over the array if ith index and i+1th index are same then ith index element multiply by 2 and make i+1th inddex as a 0.\n\n# I Think This Can H | Rutvik_Jasani | NORMAL | 2024-03-12T07:58:45.701399+00:00 | 2024-03-12T07:58:45.701418+00:00 | 130 | false | # Intuition\nCheck over the array if ith index and i+1th index are same then ith index element multiply by 2 and make i+1th inddex as a 0.\n\n# I Think This Can Help You\n\n\n\n# Appr... | 3 | 0 | ['Array', 'Simulation', 'Java'] | 0 |
apply-operations-to-an-array | Python Solution (Beats 99.50%) || 41ms|| O(N) || Easy Solution | python-solution-beats-9950-41ms-on-easy-1favr | Complexity\n- Time complexity:\n O(N)\n# Code\n\nclass Solution:\n def applyOperations(self, nums: List[int]) -> List[int]:\n zeros=0\n i=0\ | varshith2134 | NORMAL | 2023-03-14T06:18:04.673775+00:00 | 2023-03-14T06:18:04.673819+00:00 | 857 | false | # Complexity\n- Time complexity:\n O(N)\n# Code\n```\nclass Solution:\n def applyOperations(self, nums: List[int]) -> List[int]:\n zeros=0\n i=0\n while(i<(len(nums)-1)):\n if(nums[i]==nums[i+1]):\n nums[i]*=2\n nums[i+1]=0\n i+=1\n ... | 3 | 0 | ['Python3'] | 1 |
apply-operations-to-an-array | 2 Approaches- choose yourself🤔🤔|| cpp solution | 2-approaches-choose-yourself-cpp-solutio-f1v4 | Intuition\n Describe your first thoughts on how to solve this problem. \nHere we have to do, if nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[ | Bhaskar_Agrawal | NORMAL | 2023-03-13T14:54:33.066347+00:00 | 2023-03-13T14:54:33.066392+00:00 | 932 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nHere we have to do, if nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Otherwise, you skip this operation. and then move zeroes to end. If you havent solved **move zeroes**(leetcode- 283) problem, u can solve ... | 3 | 0 | ['Array', 'Simulation', 'C++'] | 0 |
apply-operations-to-an-array | EASY SOLUTION IN C++ | easy-solution-in-c-by-chhayagupta900-6u5i | ```\nclass Solution {\npublic:\n vector applyOperations(vector& nums) {\n \n int j =0;\n for(int i =0;i<nums.size()-1;i++)\n {\n | chhayagupta900 | NORMAL | 2022-11-28T18:05:40.235808+00:00 | 2022-11-28T18:05:40.235850+00:00 | 269 | false | ```\nclass Solution {\npublic:\n vector<int> applyOperations(vector<int>& nums) {\n \n int j =0;\n for(int i =0;i<nums.size()-1;i++)\n {\n if (nums[i]==nums[i+1])\n {\n nums[i]=(nums[i]*2);\n nums[i+1]=0;\n }\n else \n ... | 3 | 0 | [] | 0 |
apply-operations-to-an-array | Python || Easy || 98.81% Faster || O(N) Solution | python-easy-9881-faster-on-solution-by-p-dwsg | \nclass Solution:\n def applyOperations(self, nums: List[int]) -> List[int]:\n for i in range(1,len(nums)):\n if nums[i-1]==nums[i]:\n | pulkit_uppal | NORMAL | 2022-11-08T20:11:36.876965+00:00 | 2022-11-08T20:11:36.877004+00:00 | 299 | false | ```\nclass Solution:\n def applyOperations(self, nums: List[int]) -> List[int]:\n for i in range(1,len(nums)):\n if nums[i-1]==nums[i]:\n nums[i-1]*=2\n nums[i]=0\n c,a=0,[]\n for i in nums:\n if i==0:\n c+=1\n con... | 3 | 0 | ['Python'] | 0 |
apply-operations-to-an-array | Easy JS solution explained | O(n) time and O(1) space | easy-js-solution-explained-on-time-and-o-vunc | Easy JS solution explained | O(n) time and O(1) space\nTC: O(n) and SC: O(1)\n\nvar applyOperations = function(nums) {\n// perform the operation on each array e | loid_forger | NORMAL | 2022-11-07T07:43:54.533669+00:00 | 2022-11-07T07:43:54.533718+00:00 | 332 | false | # Easy JS solution explained | O(n) time and O(1) space\n**TC: O(n) and SC: O(1)**\n```\nvar applyOperations = function(nums) {\n// perform the operation on each array element\n for(let i = 0; i < nums.length - 1; i++){\n if(nums[i] === nums[i + 1]){\n nums[i] *= 2;\n nums[i + 1] = 0;\n ... | 3 | 0 | ['JavaScript'] | 0 |
apply-operations-to-an-array | Python two pointers without using extra space | python-two-pointers-without-using-extra-wcx70 | \nclass Solution:\n def applyOperations(self, nums: List[int]) -> List[int]:\n \n for i in range(len(nums) - 1):\n if nums[i] == num | theReal007 | NORMAL | 2022-11-06T12:10:58.906325+00:00 | 2022-11-13T11:43:09.013947+00:00 | 241 | false | ```\nclass Solution:\n def applyOperations(self, nums: List[int]) -> List[int]:\n \n for i in range(len(nums) - 1):\n if nums[i] == nums[i+1]:\n nums[i] = nums[i] * 2\n nums[i+1] = 0\n \n l = 0\n \n for r in range(len(nums)):\n ... | 3 | 0 | ['Two Pointers', 'Python'] | 0 |
apply-operations-to-an-array | JAVA | Constant space | Easy ✅ | java-constant-space-easy-by-sourin_bruh-4pgn | Please Upvote :D\n\nclass Solution {\n public int[] applyOperations(int[] nums) {\n int n = nums.length;\n \n for (int i = 0; i < n - 1; | sourin_bruh | NORMAL | 2022-11-06T09:03:58.751123+00:00 | 2022-11-06T17:25:55.708021+00:00 | 660 | false | ### **Please Upvote** :D\n```\nclass Solution {\n public int[] applyOperations(int[] nums) {\n int n = nums.length;\n \n for (int i = 0; i < n - 1; i++) {\n if (nums[i] == nums[i + 1]) {\n nums[i] *= 2;\n nums[i + 1] = 0;\n }\n }\n ... | 3 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | cpp best solution | cpp-best-solution-by-rajan087-2ld6 | Intuition\nCpp best solution\n\n# Approach\nvector\n\n# Complexity\n- Time complexity:\n(o)n\n\n- Space complexity:\n(o)n\n\n# Code\n\nclass Solution {\npublic: | rajan087 | NORMAL | 2022-11-06T06:46:56.598572+00:00 | 2022-11-06T06:46:56.598610+00:00 | 14 | false | # Intuition\nCpp best solution\n\n# Approach\nvector\n\n# Complexity\n- Time complexity:\n(o)n\n\n- Space complexity:\n(o)n\n\n# Code\n```\nclass Solution {\npublic:\n vector<int> applyOperations(vector<int>& nums) {\n \n int res=0;\n \n for(int i=0;i<nums.size()-1;i++)\n {\n ... | 3 | 0 | ['C++'] | 1 |
apply-operations-to-an-array | Java Easy Solution | 100% faster | O(1) space | java-easy-solution-100-faster-o1-space-b-xfzd | \nclass Solution {\n public int[] applyOperations(int[] nums) {\n for (int i = 0; i < nums.length - 1; i++){\n if (nums[i] == nums[i + 1]){ | srujan_14 | NORMAL | 2022-11-06T04:03:30.377993+00:00 | 2022-11-06T04:26:57.710688+00:00 | 762 | false | ```\nclass Solution {\n public int[] applyOperations(int[] nums) {\n for (int i = 0; i < nums.length - 1; i++){\n if (nums[i] == nums[i + 1]){\n nums[i] *= 2;\n nums[i + 1] = 0;\n }\n }\n \n move(nums);\n return nums;\n }\n \n //m... | 3 | 1 | ['Java'] | 0 |
apply-operations-to-an-array | Python3, solved in place | python3-solved-in-place-by-silvia42-fem1 | Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution:\n def applyOperations(self, nums: List[int]) -> List[int]:\n | silvia42 | NORMAL | 2022-11-06T04:03:08.798000+00:00 | 2022-11-06T04:03:08.798033+00:00 | 645 | false | # Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution:\n def applyOperations(self, nums: List[int]) -> List[int]:\n zeros=0\n nums+=[0]\n for i in range(len(nums)-1):\n if nums[i]==0:\n zeros+=1\n elif nums[i]==num... | 3 | 0 | ['Python3'] | 0 |
apply-operations-to-an-array | Using swap function to move zeros at the end #simple java code#efficient swapping | using-swap-function-to-move-zeros-at-the-nxcc | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | harinimuruges04 | NORMAL | 2025-03-27T08:09:55.569468+00:00 | 2025-03-27T08:09:55.569468+00:00 | 26 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['Java'] | 1 |
apply-operations-to-an-array | Simple TS Solution | simple-ts-solution-by-nurzhansultanov-4xny | Code | NurzhanSultanov | NORMAL | 2025-03-03T05:11:37.967792+00:00 | 2025-03-03T05:11:37.967792+00:00 | 9 | false | # Code
```typescript []
function applyOperations(nums: number[]): number[] {
let result: number[] = [];
let numberOfZero = 0;
for (let i = 0; i < nums.length - 1; i++) {
if (nums[i] === nums[i + 1]) {
nums[i] = nums[i] * 2;
nums[i + 1] = 0;
if(nums[i] > 0){
... | 2 | 0 | ['TypeScript'] | 0 |
apply-operations-to-an-array | TWO POINTER APPROACH || O(N) Time Complexity || O(1) Space Complexity || BASIC ARRAY | two-pointer-approach-on-time-complexity-qooq3 | IntuitionApproachFirstly Declare two variable i and j where i starts from 0 and j from i+1 .
Then checking the conditions if nums[i]==nums[j] then just multipl | prakharpatel | NORMAL | 2025-03-01T21:23:49.956511+00:00 | 2025-03-01T21:23:49.956511+00:00 | 5 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->TWO POINTER APPROACH || Basic Array Solution || Using Move Zeroes to End (Another Leetcode Question*
# Approach
<!-- Describe your approach to solving the problem. -->
Firstly Declare two variable i and j where i starts from 0 and j from i+... | 2 | 0 | ['Array', 'Two Pointers', 'Simulation', 'C++'] | 0 |
apply-operations-to-an-array | 2460. Apply Operations to an Array in Python3 | 2460-apply-operations-to-an-array-in-pyt-wp7v | Code | Shivmishra75 | NORMAL | 2025-03-01T19:33:54.500946+00:00 | 2025-03-01T19:33:54.500946+00:00 | 24 | false |
# Code
```python3 []
class Solution:
def applyOperations(self, nums: List[int]) -> List[int]:
n = len(nums)
j = 0 # index of first zero
for i in range(n):
if i + 1 < n and nums[i] == nums[i + 1]: # check if should apply operation
nums[i] *= 2
num... | 2 | 0 | ['Python3'] | 1 |
apply-operations-to-an-array | Java ✅🤯 - Best Solution | java-best-solution-by-aimlc_22b1531167-fwho | IntuitionApproach
Iterate through the array, doubling adjacent equal numbers and setting the next one to zero.
Move all non-zero elements to the front while mai | aimlc_22b1531167 | NORMAL | 2025-03-01T19:10:20.891756+00:00 | 2025-03-01T19:10:20.891756+00:00 | 8 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. --> Modify the array by doubling adjacent equal elements and setting the next element to zero, then shift non-zero elements forward.
# Approach
<!-- Describe your approach to solving the problem. -->
1. Iterate through the array, doubling adja... | 2 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | "LeetCode 2460 | Apply Operations to an Array | Easy & Optimized Java Solution" | leetcode-2460-apply-operations-to-an-arr-z7jm | IntuitionThe problem requires us to perform two operations sequentially:Merge adjacent equal elements by doubling the first and setting the second to 0.
Shift a | kshitij_srivastava16 | NORMAL | 2025-03-01T15:43:31.114845+00:00 | 2025-03-01T15:43:31.114845+00:00 | 24 | false | # Intuition
The problem requires us to perform two operations sequentially:
Merge adjacent equal elements by doubling the first and setting the second to 0.
Shift all 0s to the end while maintaining the order of non-zero elements.
Since both operations are sequential, we can achieve the result efficiently by processi... | 2 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | Python Solution | python-solution-by-iloabachie-tzcu | Code | iloabachie | NORMAL | 2025-03-01T15:36:10.756658+00:00 | 2025-03-01T15:48:33.742653+00:00 | 37 | false | # Code
```python []
class Solution:
def applyOperations(self, nums: List[int]) -> List[int]:
for i in range(len(nums) - 1):
if nums[i] and nums[i] == nums[i + 1]:
nums[i] *= 2
nums[i + 1] = 0
return sorted(nums, key=lambda x: not x)
``` | 2 | 0 | ['Python3'] | 0 |
apply-operations-to-an-array | Simple solution for beginners | simple-solution-for-beginners-by-ai_prin-v6pc | IntuitionThe problem involves modifying an array based on specific rules:
If two adjacent numbers are the same, double the first one and set the second to zero. | ai_prince | NORMAL | 2025-03-01T14:58:46.907259+00:00 | 2025-03-01T14:58:46.907259+00:00 | 47 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem involves modifying an array based on specific rules:
1. If two adjacent numbers are the same, double the first one and set the second to zero.
2. After processing the array, shift all zeros to the end while maintaining the orde... | 2 | 0 | ['Python3'] | 0 |
apply-operations-to-an-array | 100% BEAT 🚀 || WITH APPROACH 😁 || BIGNNER FRIENDLY 😊 || EASY SOLN 🎯|| 2 LOOP SOLN ||💯🚀🎯🔥🔥 | 100-beat-with-approach-bignner-friendly-iwelp | Approach1 ) Initialize the result array:
Create a new array result of the same length as the input array nums. This will store the final result with all non-z | Dhruv-AFK4545 | NORMAL | 2025-03-01T13:34:38.349344+00:00 | 2025-03-01T13:34:38.349344+00:00 | 31 | false |
# Approach
<!-- Describe your approach to solving the problem. -->
1 ) Initialize the result array:
- > Create a new array result of the same length as the input array nums. This will store the final result with all non-zero values moved to the front and zeroes moved to the end.
2 ) First Pass: Apply the merge opera... | 2 | 0 | ['C++'] | 1 |
apply-operations-to-an-array | Easy C++ Solution || Beats 100% | easy-c-solution-beats-100-by-manish_code-gigo | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | manish_code_fun | NORMAL | 2025-03-01T13:23:35.212524+00:00 | 2025-03-01T13:23:35.212524+00:00 | 43 | false | 
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time com... | 2 | 0 | ['C++'] | 0 |
apply-operations-to-an-array | Simple CPP solution beats 100% | simple-cpp-solution-beats-100-by-abhinav-c2uk | Code | Abhinav_Bisht | NORMAL | 2025-03-01T11:59:51.498914+00:00 | 2025-03-01T12:11:22.577391+00:00 | 16 | false |
# Code
```cpp []
class Solution {
public:
vector<int> applyOperations(vector<int>& nums) {
int n = nums.size();
vector<int> ans(n,0);
int idx=0;
for(int i=0;i<n;i++){
if(i<n-1 && nums[i] == nums[i+1] && nums[i]!=0){
ans[idx++]=nums[i]*2;
... | 2 | 0 | ['C++'] | 0 |
apply-operations-to-an-array | O(1) Space || Single Pass || BEATS 100% || Single Loop | o1-space-single-pass-beats-100-single-lo-a6t8 | Fastest Code with Single LoopComplexity
Time complexity:
O(N)
Space complexity:
O(1)
Code | Gagan_70 | NORMAL | 2025-03-01T11:56:04.724267+00:00 | 2025-03-01T11:56:04.724267+00:00 | 5 | false | **Fastest Code with Single Loop**
# Complexity
- Time complexity:
O(N)
- Space complexity:
O(1)
# Code
```cpp []
class Solution {
public:
vector<int> applyOperations(vector<int>& nums) {
int j =0;
int i = 0;
int n = nums.size();
for(i;i<n-1;i++){
if(nums[i]==nums[... | 2 | 0 | ['Array', 'Two Pointers', 'C++'] | 1 |
apply-operations-to-an-array | ✅ 🎯 📌 Simple Solution || Pointers || Fastest Solution ✅ 🎯 📌 | simple-solution-pointers-fastest-solutio-i6j8 | Code | vvnpais | NORMAL | 2025-03-01T09:14:38.732867+00:00 | 2025-03-01T09:14:38.732867+00:00 | 22 | false | # Code
```python3 []
class Solution:
def applyOperations(self, nums: List[int]) -> List[int]:
for i in range(len(nums)-1):
if nums[i]==nums[i+1]: nums[i],nums[i+1]=nums[i]*2,0
z=0
for i in range(len(nums)):
if nums[i]==0: z+=1
else: nums[i-z]=nums[i]
... | 2 | 0 | ['Array', 'Two Pointers', 'Simulation', 'Python3'] | 0 |
apply-operations-to-an-array | simple py solution - beats 100% | simple-py-solution-beats-100-by-noam971-jal2 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | noam971 | NORMAL | 2025-03-01T08:59:31.675019+00:00 | 2025-03-01T08:59:31.675019+00:00 | 58 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['Python3'] | 0 |
apply-operations-to-an-array | Efficient And Easy Solution 😉😉💯💯Beats | efficient-and-easy-solution-beats-by-kum-y0fg | IntuitionThe problem requires modifying an array by doubling adjacent equal elements and setting the second one to zero, followed by shifting all zeroes to the | Kumar_s29 | NORMAL | 2025-03-01T08:30:27.285093+00:00 | 2025-03-01T08:30:27.285093+00:00 | 14 | false |
---
## **Intuition**
The problem requires modifying an array by doubling adjacent equal elements and setting the second one to zero, followed by shifting all zeroes to the end while maintaining the order of non-zero elements. The approach is similar to the **2048 game mechanics**.
---
## **Approach**
1. **Merg... | 2 | 0 | ['C++'] | 0 |
apply-operations-to-an-array | I Scored 100%—In the Weirdest Way Possible! | i-scored-100-in-the-weirdest-way-possibl-1d6t | IntuitionI thought to keep a counter of number of zeros possible in the resultant array and only pushed the non zero possible elements first and then pushed the | Shoaib09 | NORMAL | 2025-03-01T08:04:55.363357+00:00 | 2025-03-01T08:04:55.363357+00:00 | 7 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
I thought to keep a counter of number of zeros possible in the resultant array and only pushed the non zero possible elements first and then pushed the remaining 0's which are supposed to be at the end of the resultant array.
# Approach
<!... | 2 | 0 | ['C++'] | 0 |
apply-operations-to-an-array | ✅✅ Beats 100% || O(n) || Easy Solution | beats-100-on-easy-solution-by-karan_agga-1wqs | IntuitionThe problem requires modifying an array based on certain rules:
If two adjacent elements are equal, double the first and set the second to zero.
Move a | Karan_Aggarwal | NORMAL | 2025-03-01T07:46:21.826475+00:00 | 2025-03-01T07:46:21.826475+00:00 | 6 | false | ## Intuition
The problem requires modifying an array based on certain rules:
1. If two adjacent elements are equal, double the first and set the second to zero.
2. Move all nonzero elements to the left while maintaining relative order.
## Approach
- Iterate through the array once. If two adjacent elements are eq... | 2 | 0 | ['Array', 'Two Pointers', 'Simulation', 'C++'] | 0 |
apply-operations-to-an-array | ✅💥BEATS 100%✅💥 || 🔥EASY CODE🔥 || ✅💥EASY EXPLAINATION✅💥 || JAVA || C++ || PYTHON | beats-100-easy-code-easy-explaination-ja-5xku | IntuitionThe problem asks us to apply some operations on an array of integers. The goal is to iterate through the array and, whenever two adjacent elements are | chaitanyameshram_07 | NORMAL | 2025-03-01T06:54:59.400354+00:00 | 2025-03-01T06:54:59.400354+00:00 | 42 | false | # Intuition
The problem asks us to apply some operations on an array of integers. The goal is to iterate through the array and, whenever two adjacent elements are the same, combine them by multiplying the first element by 2 and setting the second one to 0. After that, we need to shift the non-zero elements to the left ... | 2 | 0 | ['Array', 'Math', 'Two Pointers', 'Simulation', 'Python', 'C++', 'Java'] | 0 |
apply-operations-to-an-array | 🔄 Apply Operations and Move Zeros | Java | C++ | python | Javascript | O(n) | apply-operations-and-move-zeros-java-c-p-368e | 🔍 Problem BreakdownWe need to modify the array in-place by following two rules:
1️⃣ Merge adjacent equal numbers: If nums[i] == nums[i+1], then double nums[i] a | koushiRai | NORMAL | 2025-03-01T06:02:28.185352+00:00 | 2025-03-01T06:02:28.185352+00:00 | 89 | false | # 🔍 Problem Breakdown
We need to modify the array in-place by following two rules:
1️⃣ Merge adjacent equal numbers: If nums[i] == nums[i+1], then double nums[i] and set nums[i+1] = 0.
2️⃣ Move all zeros to the end: Maintain the relative order of non-zero elements.
# 💡 Intuition
We can solve this problem in two simp... | 2 | 0 | ['Python', 'C++', 'Java', 'JavaScript'] | 0 |
apply-operations-to-an-array | One Pass Go Easy Solution !!! | one-pass-go-easy-solution-by-dipak__pati-jhjb | One Pass Solution !!!Complexity
Time complexity:
O(n)
Space complexity:
O(1)
Code | dipak__patil | NORMAL | 2025-03-01T05:08:58.348842+00:00 | 2025-03-01T05:08:58.348842+00:00 | 43 | false | # One Pass Solution !!!
# Complexity
- Time complexity:
O(n)
- Space complexity:
O(1)
# Code
```golang []
func applyOperations(nums []int) []int {
insertPos := 0
for i := 0; i < len(nums); i++ {
if i+1 < len(nums) && nums[i] == nums[i+1] {
nums[i] *= 2
nums[i+1] = 0
}
if nums[i] != 0 {
nums[insertPos... | 2 | 0 | ['Array', 'Go'] | 0 |
apply-operations-to-an-array | Apply Operations to an Array || Beats 100% || Easy Solution in C++ | apply-operations-to-an-array-beats-100-e-w9di | IntuitionThe question clearly states the requirement:
if(nums[i] == nums[i+1]) then doulbe nums[i] and set nums[i+1] as 0.
at the end, we need to move all 0s to | rajputsatvik12 | NORMAL | 2025-03-01T05:07:01.242633+00:00 | 2025-03-01T05:07:01.242633+00:00 | 9 | false | # Intuition
The question clearly states the requirement:
if(nums[i] == nums[i+1]) then doulbe nums[i] and set nums[i+1] as 0.
at the end, we need to move all 0s to the end of the array.
# Approach
<!-- Describe your approach to solving the problem. -->
Step 1: check for consecutive equal elements and apply the operati... | 2 | 0 | ['C++'] | 0 |
apply-operations-to-an-array | Easy code in Java | Must try | Beats 100% | easy-code-in-java-must-try-beats-100-by-9qy1v | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | NotAditya09 | NORMAL | 2025-03-01T04:57:47.173366+00:00 | 2025-03-01T04:57:47.173366+00:00 | 58 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | Easiest Solution with Intitution (Beats 100% solutions) | easiest-solution-with-intitution-beats-1-m8nh | Intuition
Traverse through array and apply operations as given in the question.
Count number of zeros present in array & shift digits in front.
Iterate from end | sakshidabral_ | NORMAL | 2025-03-01T04:34:31.188940+00:00 | 2025-03-01T04:34:31.188940+00:00 | 24 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1. Traverse through array and apply operations as given in the question.
2. Count number of zeros present in array & shift digits in front.
3. Iterate from end to fix the positioning of zeros.
<!-- Describe your approach to solving the pr... | 2 | 0 | ['Array', 'C++'] | 0 |
apply-operations-to-an-array | Simple solution | Runtime 0 ms | Beats 100.00% | simple-solution-runtime-0-ms-beats-10000-2rbn | IntuitionPerform the operation as given, ensuring merged values are stored while skipping zeros. After processing, append the remaining zeros to maintain array | arpita_sat | NORMAL | 2025-03-01T04:07:46.776357+00:00 | 2025-03-01T04:07:46.776357+00:00 | 26 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Perform the operation as given, ensuring merged values are stored while skipping zeros. After processing, append the remaining zeros to maintain array size.
# Approach
<!-- Describe your approach to solving the problem. -->
1. **Initializ... | 2 | 0 | ['C++'] | 0 |
apply-operations-to-an-array | JavaScript Solution || Using Array Iteration || Beats 100% Users || | javascript-solution-using-array-iteratio-mg4v | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Heisenberg_wc | NORMAL | 2025-03-01T03:42:29.821680+00:00 | 2025-03-01T03:42:29.821680+00:00 | 34 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['JavaScript'] | 0 |
apply-operations-to-an-array | 🔥😎6 Lines C++✅✅ | 6-lines-c-by-sapilol-56j3 | C++ | LeadingTheAbyss | NORMAL | 2025-03-01T03:41:37.264692+00:00 | 2025-03-01T03:41:37.264692+00:00 | 11 | false | # C++
```cpp
class Solution {
public:
vector<int> applyOperations(vector<int>& nums) {
for (int i = 0; i < nums.size() - 1; i++)
if (nums[i] == nums[i + 1]) nums[i] *= 2,nums[i + 1] = 0;
for (int i = 0; i < nums.size(); i++) {
if (count(nums.begin() + i, nums.end(), 0) == nums.... | 2 | 0 | ['C++'] | 0 |
apply-operations-to-an-array | CPP || 100% beats || easy to understand | cpp-100-beats-easy-to-understand-by-apoo-ntou | Complexity
Time complexity: O(N)
Space complexity: O(N)
Code | apoorvjain7222 | NORMAL | 2025-03-01T03:33:58.800765+00:00 | 2025-03-01T03:33:58.800765+00:00 | 20 | false | # Complexity
- Time complexity: O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(N)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution... | 2 | 0 | ['Array', 'Two Pointers', 'Simulation', 'C++'] | 0 |
apply-operations-to-an-array | Easy Beginner Friendly Solution 🔥 ✅ ⭐️ Simple Logic 💡 | easy-beginner-friendly-solution-simple-l-3a2r | Intuitionas per the question If nums[i] == nums[i + 1], we multiply nums[i] by 2 and set nums[i + 1] to 0. then we just moving the zeros to the end .ApproachIf | Muhammed_Razi | NORMAL | 2025-03-01T03:09:05.588446+00:00 | 2025-03-01T03:11:28.727336+00:00 | 40 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
as per the question If nums[i] == nums[i + 1], we multiply nums[i] by 2 and set nums[i + 1] to 0. then we just moving the zeros to the end .
# Approach
If it helps Please Upvote ⬆️ ⬆️ ⬆️
<!-- Describe your approach to solving the problem... | 2 | 0 | ['Array', 'Two Pointers', 'Simulation', 'JavaScript'] | 0 |
apply-operations-to-an-array | [Java][Two-Pointer] Beat 100% | javatwo-pointer-beat-100-by-kuan1025-6t23 | IntuitionThe problem requires merging adjacent equal elements and shifting non-zero values to the front while maintaining their order. A simple traversal can ac | kuan1025 | NORMAL | 2025-03-01T03:08:26.434772+00:00 | 2025-03-01T03:08:26.434772+00:00 | 58 | false | # Intuition
The problem requires merging adjacent equal elements and shifting non-zero values to the front while maintaining their order. A simple traversal can achieve this efficiently.
# Approach
- Iterate through the array and merge consecutive equal elements by doubling the first one and skipping the second.
- Sto... | 2 | 0 | ['Java'] | 0 |
apply-operations-to-an-array | My kotlin solution with time O(N) and space O(1) | my-kotlin-solution-with-time-on-and-spac-ps01 | The idea is to simulate the process. We can eliminate the shifting of zeros by clearing the existing values and assigning nonzero values to the front of nums du | hj-core | NORMAL | 2025-03-01T02:18:56.286705+00:00 | 2025-03-01T02:31:13.285954+00:00 | 77 | false | The idea is to simulate the process. We can eliminate the shifting of zeros by clearing the existing values and assigning nonzero values to the front of nums during the iteration.
Below are my implementations,
```kotlin []
class Solution {
// Complexity:
// Time O(N) and Space O(1) where N is the length of `nu... | 2 | 0 | ['Go', 'Kotlin'] | 1 |
apply-operations-to-an-array | Python one-liner (code golf) | cursed-python-one-liner-by-killer-whale-jjxg | You can also make everything one line: | killer-whale | NORMAL | 2025-03-01T02:17:47.631749+00:00 | 2025-03-01T02:52:01.429618+00:00 | 58 | false | ```python3
class Solution:
def applyOperations(self, nums: List[int]) -> List[int]:
return sorted(sum(((l:=len([*g]))//2*[k*2,0]+l%2*[k]for k,g in groupby(nums)),[]),key=not_)
```
You can also make everything one line:
```python3
class Solution:applyOperations=lambda _,n:sorted(sum(((l:=len([*g]))//2*[k*2,0... | 2 | 0 | ['Sorting', 'Python', 'Python3'] | 1 |
apply-operations-to-an-array | Optimized In-Place Array Transformation | Beats 💯% | Pseudo Code | optimized-in-place-array-transformation-pscdr | Intuition~ The problem requires us to perform two operations on the given array nums:
Merge adjacent equal elements: If nums[i] == nums[i+1], we double nums[i] | rajnandi006 | NORMAL | 2025-03-01T02:11:39.309619+00:00 | 2025-03-01T02:36:11.155890+00:00 | 10 | false | # Intuition
~ The problem requires us to perform two operations on the given array nums:
- Merge adjacent equal elements: If nums[i] == nums[i+1], we double nums[i] and set nums[i+1] to 0.
- Shift all non-zero elements to the left: Move all 0s to the end while maintaining the relative order of non-zero elements.
# App... | 2 | 0 | ['Array', 'Two Pointers', 'Simulation', 'C++'] | 0 |
apply-operations-to-an-array | Python | Simple One-Pass | O(n), O(1) | Beats 100% | python-simple-one-pass-on-o1-beats-100-b-12tj | CodeComplexity
Time complexity: O(n). Visits each index in nums, n total, and performs constant operations, so n overall.
Space complexity: O(1). Only variab | 2pillows | NORMAL | 2025-03-01T01:11:06.126749+00:00 | 2025-03-01T05:26:32.854089+00:00 | 302 | false | # Code
```python3 []
class Solution:
def applyOperations(self, nums: List[int]) -> List[int]:
n = len(nums)
j = 0 # index of first zero
for i in range(n):
if i + 1 < n and nums[i] == nums[i + 1]: # check if should apply operation
nums[i] *= 2
nums... | 2 | 0 | ['Two Pointers', 'Python3'] | 1 |
apply-operations-to-an-array | EasyPeezy | StraightForward | O(n) +O(1) | C++ | easypeezy-straightforward-on-o1-c-by-sav-19jf | Code | savetrees | NORMAL | 2025-03-01T01:04:50.249556+00:00 | 2025-03-01T01:04:50.249556+00:00 | 137 | false | # Code
```cpp []
/*
By :: savetrees
Used :: Optimal
*/
class Solution {
public:
vector<int> applyOperations(vector<int>& nums) {
int n=nums.size(),j=0;
for (int i=0;i<n;i++) {
if (i<n-1&&nums[i]==nums[i+1]) {
nums[i]*=2;
nums[i+1]=0;
}
... | 2 | 0 | ['C++'] | 0 |
group-sold-products-by-the-date | SIMPLE | Explanation | EASY | simple-explanation-easy-by-babasaheb256-rmgz | <<<< Please Press upvote Button !!!!!\n\nAlmost immediately detected, the only serious challange of this problem is how to aggregate the product names in one ce | babasaheb256 | NORMAL | 2022-06-11T18:53:54.166971+00:00 | 2022-06-20T06:57:19.674846+00:00 | 87,090 | false | **<<<< Please Press upvote Button !!!!!**\n\nAlmost immediately detected, the only serious challange of this problem is how to aggregate the product names in one cell. In MySql, this can be done using GROUP_CONCAT, in which you can also specify the sorting mechanism for the group concatenation (aggregation). The rest i... | 959 | 5 | ['MySQL'] | 40 |
group-sold-products-by-the-date | MySQL Order by Product name AND Sell date | mysql-order-by-product-name-and-sell-dat-nyy7 | In June 2024, I realized the first upvoted solution (by @babasaheb256), is an EXACT COPY word by word of my solution. That guy just copies from other people\'s | SubBuffer | NORMAL | 2020-06-17T23:03:29.421808+00:00 | 2024-07-12T22:34:13.891709+00:00 | 31,642 | false | ___In June 2024, I realized the first upvoted solution (by @babasaheb256), is an EXACT COPY word by word of my solution. That guy just copies from other people\'s solutions and adds a MEME to them! Check his profile for his other solutions. Dude WTF! Lol___\n\nPlease consider __Upvoting__ my solution to beat his ass an... | 222 | 1 | ['MySQL'] | 11 |
group-sold-products-by-the-date | MySQL Solution, CLEAN, FASTER than 92 % | mysql-solution-clean-faster-than-92-by-y-quxz | please UPVOTE \n\nSELECT \n\tsell_date,\n\t(COUNT(sell_date ) ) as num_sold ,\n\tGROUP_CONCAT(distinct product ORDER BY product) as products \nFROM \n\t(SELEC | YassineAmmani | NORMAL | 2022-08-28T23:56:52.089248+00:00 | 2022-08-28T23:56:52.089283+00:00 | 24,898 | false | * ***please UPVOTE ***\n```\nSELECT \n\tsell_date,\n\t(COUNT(sell_date ) ) as num_sold ,\n\tGROUP_CONCAT(distinct product ORDER BY product) as products \nFROM \n\t(SELECT DISTINCT sell_date,product FROM Activities) as Activities\nGROUP BY sell_date;\n```\n\n* ***please UPVOTE ***\n\n | 122 | 0 | ['MySQL'] | 2 |
group-sold-products-by-the-date | Pandas vs SQL | Elegant & Short | All 30 Days of Pandas solutions ✅ | pandas-vs-sql-elegant-short-all-30-days-evm7n | Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\nPython []\ndef categorize_products(activities: pd.DataFrame) -> pd.DataFrame:\n retu | Kyrylo-Ktl | NORMAL | 2023-08-04T14:49:28.526534+00:00 | 2023-08-06T17:18:22.099123+00:00 | 10,021 | false | # Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```Python []\ndef categorize_products(activities: pd.DataFrame) -> pd.DataFrame:\n return activities.groupby(\n \'sell_date\'\n )[\'product\'].agg([\n (\'num_sold\', \'nunique\'),\n (\'products\', lambda x: \',... | 109 | 0 | ['Python', 'Python3', 'MySQL', 'Pandas'] | 5 |
group-sold-products-by-the-date | ✅MySQL || Beginner level ||Easy to Understand||Simple-Short -Solution✅ | mysql-beginner-level-easy-to-understands-b2hu | Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome.\n========== | Anos | NORMAL | 2022-08-31T20:23:29.943936+00:00 | 2022-08-31T20:23:29.943975+00:00 | 8,195 | false | **Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome.***\n*====================================================================*\n\u2705 **MySQL Code :**\n```\nSELECT sell_date,\n\t\tCOUNT(DISTINCT(product)) AS num_sold, \n... | 55 | 0 | ['MySQL'] | 0 |
group-sold-products-by-the-date | All DBs, simple solution | all-dbs-simple-solution-by-yurokusa-btmw | Oracle\n\nselect to_char(a.sell_date, \'yyyy-mm-dd\') sell_date\n , count(a.product) num_sold\n , listagg(a.product, \',\') within group(order by a.produc | yurokusa | NORMAL | 2020-09-14T02:46:14.904948+00:00 | 2020-09-14T02:46:14.905007+00:00 | 7,930 | false | Oracle\n```\nselect to_char(a.sell_date, \'yyyy-mm-dd\') sell_date\n , count(a.product) num_sold\n , listagg(a.product, \',\') within group(order by a.product) products\nfrom (select distinct * from activities) a\ngroup by a.sell_date\norder by a.sell_date\n```\nMy SQL\n```\nselect sell_date\n\t, count(distinct p... | 51 | 0 | ['MySQL', 'Oracle'] | 9 |
group-sold-products-by-the-date | [Pandas] || My Approach with Clear Comments... | pandas-my-approach-with-clear-comments-b-dukz | \n\n# Code\n\nimport pandas as pd\n\ndef categorize_products(activities: pd.DataFrame) -> pd.DataFrame:\n # Group the activities by sell_date and collect the | sriganesh777 | NORMAL | 2023-08-22T18:01:47.581977+00:00 | 2023-08-22T18:01:47.582005+00:00 | 3,792 | false | \n\n# Code\n```\nimport pandas as pd\n\ndef categorize_products(activities: pd.DataFrame) -> pd.DataFrame:\n # Group the activities by sell_date and collect the unique products for each date\n grouped = activities.groupby(\'sell_date\')[\'product\'].agg([\'nunique\', lambda x: \',\'.join(sorted(set(x)))]).reset_i... | 29 | 0 | ['Pandas'] | 3 |
group-sold-products-by-the-date | MySQL | Simple n Concise query | mysql-simple-n-concise-query-by-raviteja-ws9v | Query\n\n# Write your MySQL query statement below\nSELECT sell_date,\n COUNT(DISTINCT(product), sell_date) AS num_sold, \n GROUP_CONCAT(DISTINCT pro | ravitejay | NORMAL | 2023-01-13T06:52:35.026553+00:00 | 2023-01-17T07:43:21.087761+00:00 | 5,630 | false | # Query\n```\n# Write your MySQL query statement below\nSELECT sell_date,\n COUNT(DISTINCT(product), sell_date) AS num_sold, \n GROUP_CONCAT(DISTINCT product ORDER BY product) AS products\nFROM Activities\nGROUP BY sell_date\n```\n\n\n\n*if the solution worked for you* ***please upvote*** | 25 | 0 | ['MySQL'] | 3 |
group-sold-products-by-the-date | SQL | Easy to Understand | Using GROUP_CONCAT | sql-easy-to-understand-using-group_conca-z60d | \nSELECT sell_date, \n count(DISTINCT product) as num_sold,\n GROUP_CONCAT(DISTINCT product ORDER BY product) AS products\nFROM Activities \nGROUP BY sell | nidhi_ranjan | NORMAL | 2022-06-28T11:46:50.637719+00:00 | 2022-06-28T11:46:50.637748+00:00 | 2,484 | false | ```\nSELECT sell_date, \n count(DISTINCT product) as num_sold,\n GROUP_CONCAT(DISTINCT product ORDER BY product) AS products\nFROM Activities \nGROUP BY sell_date \nORDER BY sell_date;\n```\nPlease upvote if you found this useful :) | 24 | 1 | ['MySQL'] | 2 |
group-sold-products-by-the-date | Easiest Solution ;) | easiest-solution-by-youssefgirgeis-yg06 | \nSELECT\n sell_date,\n COUNT(DISTINCT product) num_sold,\n GROUP_CONCAT(DISTINCT product) products\nFROM activities\nGROUP BY sell_date\nORDER BY sell | youssefgirgeis | NORMAL | 2021-06-10T04:48:51.201699+00:00 | 2021-06-10T04:48:51.201742+00:00 | 5,758 | false | ```\nSELECT\n sell_date,\n COUNT(DISTINCT product) num_sold,\n GROUP_CONCAT(DISTINCT product) products\nFROM activities\nGROUP BY sell_date\nORDER BY sell_date\n``` | 24 | 1 | [] | 4 |
group-sold-products-by-the-date | Postgre SQL Solution | postgre-sql-solution-by-swetha_murthy-44mo | \n# Approach\n1. We are given with only one table so no need to use JOINs here.\n2. We need to find the number of diff products sold for each date , this indica | Swetha_Murthy | NORMAL | 2024-04-02T02:59:27.900822+00:00 | 2024-04-02T02:59:27.900849+00:00 | 2,390 | false | \n# Approach\n1. We are given with only one table so no need to use JOINs here.\n2. We need to find the number of diff products sold for each date , this indicates we need to group the products by "date"\n3. The output should contain three columns: sell_date, num_sold (distinct count of products) and products\n4. ORDER... | 19 | 0 | ['PostgreSQL'] | 2 |
group-sold-products-by-the-date | faster than 83% of MySQL online submissions | faster-than-83-of-mysql-online-submissio-2xlw | <<<<upvote \n\n\tSELECT sell_date, COUNT( DISTINCT product ) AS num_sold , \n GROUP_CONCAT( DISTINCT product ORDER BY product ASC separator \',\' ) AS pro | RohiniK98 | NORMAL | 2022-10-13T02:50:31.211068+00:00 | 2022-10-13T02:50:31.211109+00:00 | 4,628 | false | **<<<<upvote **\n\n\tSELECT sell_date, COUNT( DISTINCT product ) AS num_sold , \n GROUP_CONCAT( DISTINCT product ORDER BY product ASC separator \',\' ) AS product \n FROM Activities GROUP BY sell_date ORDER BY sell_date ASC; | 15 | 0 | ['MySQL'] | 2 |
group-sold-products-by-the-date | ms sql solution with string_agg | ms-sql-solution-with-string_agg-by-user0-crgx | Please note that this solution with string_agg will work only from SQL Server 2017 and above and SQL Azure\n\nselect sell_date, count(product) as \'num_sold\', | user0763PD | NORMAL | 2022-06-10T07:56:39.780128+00:00 | 2022-06-10T07:56:39.780160+00:00 | 3,975 | false | Please note that this solution with `string_agg` will work only from SQL Server 2017 and above and SQL Azure\n```\nselect sell_date, count(product) as \'num_sold\', string_agg(product, \',\') as products\nfrom\n(\n select distinct *\n from Activities\n) t\ngroup by sell_date\n``` | 15 | 0 | ['MS SQL Server'] | 3 |
group-sold-products-by-the-date | SQL query with detailed explanation ||SQL | sql-query-with-detailed-explanation-sql-4ttrg | GROUPCONCAT() is used to concatenat data from multiple rows into one field\nstep 1: First we will count distinct products and name the column as num_sold\nstep | dinesh47 | NORMAL | 2022-05-06T07:10:01.958406+00:00 | 2022-07-20T18:06:36.165435+00:00 | 1,514 | false | ##### **GROUPCONCAT() is used to concatenat data from multiple rows into one field**\n***step 1*: First we will count distinct products and name the column as num_sold\n*step 2*: Next we use group concat to get the disctinct products and to display them in a column with a seperator(,) and order by products and name the... | 15 | 1 | ['MySQL'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.