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-make-all-array-elements-equal-to-zero
[Python3] prefix sum
python3-prefix-sum-by-ye15-j7ty
\n\nclass Solution:\n def checkArray(self, nums: List[int], k: int) -> bool:\n for i, x in enumerate(nums): \n if i >= k: nums[i] += nums[i
ye15
NORMAL
2023-07-09T04:07:06.096203+00:00
2023-07-09T04:07:06.096221+00:00
3,157
false
\n```\nclass Solution:\n def checkArray(self, nums: List[int], k: int) -> bool:\n for i, x in enumerate(nums): \n if i >= k: nums[i] += nums[i-k]\n if i and nums[i-1] > nums[i]: return False \n return all(nums[~i] == nums[-1] for i in range(k))\n```
10
3
['C', 'Java', 'Python3']
3
apply-operations-to-make-all-array-elements-equal-to-zero
✌️2 Approaches || 1.Prefix Sum Range Update || 2.Segment Tree ||
2-approaches-1prefix-sum-range-update-2s-fe3i
DO UPVOTE if you find it useful!!\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 spac
JainWinn
NORMAL
2023-07-09T09:11:30.616140+00:00
2023-07-09T09:11:30.616163+00:00
608
false
### DO UPVOTE if you find it useful!!\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. $$O(n)$$ -->\n\n# Code : Prefix Sum\n```\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k){\n...
6
0
['Segment Tree', 'Prefix Sum', 'C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
using queue | simple c++ | O(n)
using-queue-simple-c-on-by-satenderrkuma-pq5m
Intuition\nmaking all element 0 while moving from left(from 0 to n-k) because there is only one way to make leftmost element zero which is decrement the first w
satenderrkumar11
NORMAL
2023-07-09T04:09:56.178959+00:00
2023-07-09T17:12:54.292808+00:00
1,776
false
# Intuition\nmaking all element 0 while moving from left`(from 0 to n-k)` because there is only one way to make leftmost element zero which is decrement the first window.\n\n# Approach\n- we will use a queue of size `k` and var `d` to keep track `no of decrements` on index `i` from previous windows. \n- where `q.front...
6
0
['Queue', 'C++']
2
apply-operations-to-make-all-array-elements-equal-to-zero
[Python3] Sweep Line (Range Addition), Clean & Concise
python3-sweep-line-range-addition-clean-fbi8x
Approach\nThink about the problem reversely.\n\n1. We start from an array arr with a same length as nums and all elements being 0.\n2. Now, we scan each element
xil899
NORMAL
2023-07-09T04:03:34.726837+00:00
2023-07-09T04:12:22.029418+00:00
660
false
# Approach\nThink about the problem **reversely**.\n\n1. We start from an array `arr` with a same length as `nums` and all elements being 0.\n2. Now, we scan each element from left to right, using the "Range Addition" way ([LC 370. Range Addition](https://leetcode.com/problems/range-addition/)).\n3. If the value of cur...
6
0
['Python3']
1
apply-operations-to-make-all-array-elements-equal-to-zero
C++ SLIDING WINDOW SOLUTION
c-sliding-window-solution-by-arpiii_7474-mybb
Code\n\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n=nums.size();\n int sum=0;\n if(k==1) return true
arpiii_7474
NORMAL
2023-07-10T04:36:32.555431+00:00
2023-07-10T04:36:32.555463+00:00
354
false
# Code\n```\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n=nums.size();\n int sum=0;\n if(k==1) return true;\n for(int i=0;i<n;i++){\n if(i>=k) sum-=nums[i-k];\n nums[i]-=sum;\n sum+=nums[i];\n if(nums[i]<0) ret...
5
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
[Python3] +1/-1 trick
python3-1-1-trick-by-awice-o4iu
We can encode subarrays [w, w, ..., w] of length K via two events: an event at position i of weight +w, and an event at position i + K of weight -w.\n\nMaintain
awice
NORMAL
2023-07-09T06:12:45.240395+00:00
2023-07-09T06:12:45.240418+00:00
765
false
We can encode subarrays `[w, w, ..., w]` of length `K` via two events: an event at position `i` of weight `+w`, and an event at position `i + K` of weight `-w`.\n\nMaintain a `brush` weight that will paint infinitely to the right, eg. `brush = 2` will write `[2, 2, 2, ...]` forever.\n\nNow for example, when `brush = 2`...
5
0
['Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Difference Array | O(n) TC and SC | Simple Approach
difference-array-on-tc-and-sc-simple-app-97e3
Code\n\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> diff(n+1, 0);\n \n
roboto7o32oo3
NORMAL
2023-07-09T04:06:52.900335+00:00
2023-07-09T04:06:52.900362+00:00
1,109
false
# Code\n```\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> diff(n+1, 0);\n \n diff[0] += nums[0];\n diff[k] -= nums[0];\n \n for(int i=1; i<n; i++) {\n diff[i] += diff[i-1];\n \n ...
5
0
['C++']
1
apply-operations-to-make-all-array-elements-equal-to-zero
✅Simple C++ Solution🔥|| Sliding Window
simple-c-solution-sliding-window-by-i_an-9cvv
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
i_anurag_mishra
NORMAL
2023-07-09T04:04:17.936034+00:00
2023-07-09T04:05:48.603220+00:00
1,531
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)$$ --...
5
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Easiest solution | Intuition explained | O(N) Faster than 100% | C++ | Java
easiest-solution-intuition-explained-on-6wabr
Intuition\n Describe your first thoughts on how to solve this problem. \nDon\'t think that you want to do something on the range, think that you just want to ma
budhirajamadhav
NORMAL
2023-07-10T02:33:09.052189+00:00
2023-07-10T02:33:09.052212+00:00
445
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDon\'t think that you want to do something on the range, think that you just want to make the current element 0. Ofcourse it will take `nums[i]` operations to make `nums[i] = 0`. But is your current `nums[i]` same as the original `nums[i]...
4
0
['Prefix Sum', 'C++', 'Java']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Explained using - vector & priority queue || Simple & easy to understand solution
explained-using-vector-priority-queue-si-39b5
\n# Approach\nBasically, here the catch is - that we consider that it possible to do this operation. So first elements need to be subtracted from first k elemen
kreakEmp
NORMAL
2023-07-09T08:47:49.911522+00:00
2023-07-09T08:47:49.911545+00:00
2,265
false
\n# Approach\nBasically, here the catch is - that we consider that it possible to do this operation. So first elements need to be subtracted from first k elements, while doing so when ever then element is not zero then add it to your subtraction value and keep subtracting. After k elements the subtraction need to reduc...
4
2
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
C++ || Easy Solution || Best Approach || 🔥🔥
c-easy-solution-best-approach-by-abhi_pa-8u9v
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
abhi_pandit_18
NORMAL
2023-07-09T04:05:34.267696+00:00
2023-07-09T04:05:34.267716+00:00
679
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
4
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Java | O(n) | beats 100% | Sliding window | visual model
java-on-beats-100-sliding-window-visual-k6dc3
Intuition\n Describe your first thoughts on how to solve this problem. \nThis question reminds me of this visual model\n\n\nA certain number of lego bars (lengt
slayzzzzz
NORMAL
2023-07-10T04:35:39.088183+00:00
2023-07-10T15:31:28.851685+00:00
474
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis question reminds me of this visual model\n![Screenshot 2023-07-09 at 8.50.09 PM.png](https://assets.leetcode.com/users/images/bdb18ebc-676d-495a-9d0f-ec8d264e21cc_1688961035.5830061.png)\n\nA certain number of lego bars (length of `k...
3
0
['Java']
1
apply-operations-to-make-all-array-elements-equal-to-zero
C++ BruteForce Solution Got Accepted 🤯
c-bruteforce-solution-got-accepted-by-ka-ii1v
\nclass Solution {\npublic:\n bool checkArray(vector<int>& arr, int k) {\n if (arr.back() > arr.front()) {\n reverse(arr.begin(), arr.end()
kamalkish0r
NORMAL
2023-07-09T08:57:55.371218+00:00
2023-07-09T09:48:16.606634+00:00
1,212
false
```\nclass Solution {\npublic:\n bool checkArray(vector<int>& arr, int k) {\n if (arr.back() > arr.front()) {\n reverse(arr.begin(), arr.end());\n }\n int n = arr.size();\n for (int i = 0; i + k <= n; ) {\n int mn = INT_MAX;\n for (int j = i; j - i + 1 <= ...
3
0
['C']
1
apply-operations-to-make-all-array-elements-equal-to-zero
Zero the Array in O(n) Efficiently
zero-the-array-in-on-efficiently-by-snig-y9ec
IntuitionThe problem requires us to determine if we can make all elements in the arraynumsequal to zero by repeatedly selecting a contiguous subarray of sizekan
Nyx_owl
NORMAL
2025-02-23T06:59:16.502506+00:00
2025-02-23T07:01:39.495604+00:00
289
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> The problem requires us to determine if we can make all elements in the array `nums` equal to zero by repeatedly selecting a contiguous subarray of size `k` and decrementing all its elements by 1. A **brute-force** approach where we decr...
2
0
['Prefix Sum', 'Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
C++ || EASY || Beats 99% || Simple Solution ||
c-easy-beats-99-simple-solution-by-vansh-07to
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
vanshsuneja_
NORMAL
2023-07-15T16:16:01.835906+00:00
2023-07-15T16:16:01.835948+00:00
223
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Python (Simple Maths)
python-simple-maths-by-rnotappl-70dm
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
rnotappl
NORMAL
2023-07-09T19:34:53.373302+00:00
2023-07-09T19:34:53.373321+00:00
171
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
['Python3']
1
apply-operations-to-make-all-array-elements-equal-to-zero
Python3 Solution
python3-solution-by-motaharozzaman1996-55k4
\n\nclass Solution:\n def checkArray(self, nums: List[int], k: int) -> bool:\n curr=0\n for i,a in enumerate(nums):\n if curr>a:\n
Motaharozzaman1996
NORMAL
2023-07-09T19:29:09.413203+00:00
2023-07-09T19:29:09.413223+00:00
282
false
\n```\nclass Solution:\n def checkArray(self, nums: List[int], k: int) -> bool:\n curr=0\n for i,a in enumerate(nums):\n if curr>a:\n return False\n\n nums[i],curr=a-curr,a\n if i>=k-1:\n curr-=nums[i-k+1]\n\n return curr==0 ...
2
0
['Python', 'Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
[Python3] Solve System of Equations
python3-solve-system-of-equations-by-awi-qtgp
Let\'s say we add a subarray of weight B_i at positions [i, i+1, ..., i+K-1]. This means:\n\n\nA_0 = B_0\\\nA_1 = B_0 + B_1\\\n...,\\\nA_{K-1} = B_0 + ... + B_
awice
NORMAL
2023-07-09T06:25:29.430389+00:00
2023-07-09T06:27:08.176248+00:00
1,001
false
Let\'s say we add a subarray of weight $$B_i$$ at positions $$[i, i+1, ..., i+K-1]$$. This means:\n\n$$\nA_0 = B_0\\\\\nA_1 = B_0 + B_1\\\\\n...,\\\\\nA_{K-1} = B_0 + ... + B_{K-1}\\\\\nA_K = B_1 + ... + B_K\\\\\nA_{K+1} = B_2 + ... + B_{K+1}\\\\\n...\n$$\n\nWe can solve these equations for B. Let P be the prefix sum...
2
0
['Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Prefix Sum
prefix-sum-by-littlehobo-wpog
Intuition\n Describe your first thoughts on how to solve this problem. \nEach element at ith index can update elements till i+k-1 index elements ahead(as at eac
littlehobo
NORMAL
2023-07-09T04:57:29.627214+00:00
2023-07-09T05:00:53.084102+00:00
632
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nEach element at ith index can update elements till i+k-1 index elements ahead(as at each index i we make its element 0, so don\'t need to worry about previous elements) of it so we can use prefix sum.\n\n# Approach\n<!-- Describe your app...
2
0
['C++']
1
apply-operations-to-make-all-array-elements-equal-to-zero
Python || greedy || O(n)
python-greedy-on-by-hanna9221-v5rr
h = the least number we need so far..\narr[i] = the number needed to subtract from h at index i.\n2. At index i, first we subtract arr[i] from h, then compare n
hanna9221
NORMAL
2023-07-09T04:43:58.137032+00:00
2023-07-09T04:43:58.137055+00:00
1,211
false
1. `h` = the least number we need so far..\n`arr[i]` = the number needed to subtract from `h` at index `i`.\n2. At index `i`, first we subtract `arr[i]` from `h`, then compare `n=nums[i]` with `h`.\nIf `n > h`, save `n-h` in `arr[i+k]` and raise `h` to `n`;\nIf `n < h`, contradiction occurs, so we return `False`.\nIf `...
2
0
['Python3']
1
apply-operations-to-make-all-array-elements-equal-to-zero
Video Explanation (2 Approaches - Range Query and Prefix sum)
video-explanation-2-approaches-range-que-9qd8
Explanation\n\nClick here for the video\n\n# Code\n\ntypedef long long int ll;\n\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n
codingmohan
NORMAL
2023-07-09T04:29:08.392012+00:00
2023-07-09T04:29:08.392029+00:00
274
false
# Explanation\n\n[Click here for the video](https://youtu.be/uPNVi4IG7NI)\n\n# Code\n```\ntypedef long long int ll;\n\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n = nums.size();\n \n vector<ll> arr(n, 0);\n ll prefix_sum = 0;\n \n for (int...
2
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Apply Operations to Make All Array Elements Equal to Zero
apply-operations-to-make-all-array-eleme-y6u9
Intuition\nThe code aims to determine whether it is possible to make all elements of the array nums equal to 0 by repeatedly applying the operation of reducing
shashankiitm27
NORMAL
2024-08-30T02:13:01.166578+00:00
2024-08-30T02:13:01.166612+00:00
24
false
# Intuition\nThe code aims to determine whether it is possible to make all elements of the array nums equal to 0 by repeatedly applying the operation of reducing all elements of a subarray of size k by 1.\n\nThe main idea behind this approach is to simulate the effect of the operations using a temp array. This array he...
1
0
['Array', 'Prefix Sum', 'C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
O(n) Time Beats 100%
on-time-beats-100-by-hakkiot-t4y8
Proof\n\n\n# Approach\n Describe your approach to solving the problem. \nFor first element , you have to apply operations a[0] times and next k-1 elements will
hakkiot
NORMAL
2024-01-22T10:51:36.558538+00:00
2024-01-23T03:41:41.298925+00:00
358
false
# Proof\n![Screenshot from 2024-01-22 15-50-19.png](https://assets.leetcode.com/users/images/d8cf4340-ce55-4194-b72a-1b27372b2724_1705920678.1404316.png)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFor first element , you have to apply operations $$a[0]$$ times and next $$k-1$$ elements will...
1
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Apply Operations to Make All Array Elements Equal to Zero | Java | Easy to Understand | O(n*k)
apply-operations-to-make-all-array-eleme-mvg3
\n\n# Code\n\nclass Solution {\n public boolean checkArray(int[] nums, int k) {\n int n=nums.length;\n for(int i=0;i<n;i++){\n if(i>
Paridhicodes
NORMAL
2023-08-10T20:21:30.253599+00:00
2023-08-10T20:21:30.253642+00:00
210
false
\n\n# Code\n```\nclass Solution {\n public boolean checkArray(int[] nums, int k) {\n int n=nums.length;\n for(int i=0;i<n;i++){\n if(i>n-k && nums[i]!=0){\n return false;\n }\n\n if(nums[i]==0)continue;\n\n int dec=nums[i];\n\n for(i...
1
0
['Array', 'Java']
0
apply-operations-to-make-all-array-elements-equal-to-zero
C++ Prefix sum
c-prefix-sum-by-ankit_6776-4x9k
Approach\nPefix sum. \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 complexi
ankit_6776
NORMAL
2023-07-22T04:52:45.644696+00:00
2023-07-22T04:52:45.644713+00:00
60
false
# Approach\nPefix sum. \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. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n=nums.size(...
1
0
['Prefix Sum', 'C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
[Python] Keep tracking the operation count that makes each element zero
python-keep-tracking-the-operation-count-0v4d
The problem asks to make the entrie array zero. However, every operation is apply on a subarray with length k.\n\nAn intuitive way is substract each element in
wangw1025
NORMAL
2023-07-19T21:22:57.852355+00:00
2023-07-19T21:22:57.852386+00:00
74
false
The problem asks to make the entrie array zero. However, every operation is apply on a subarray with length k.\n\nAn intuitive way is substract each element in a subarray with the value that makes the first element zero. Next, we move to the second element, if the value of the second element is still possitive, we appl...
1
0
['Array', 'Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Operations Solution
operations-solution-by-dair68-cdby
Approach 1 - Double Loops\n Describe your approach to solving the problem. \n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nNote t
dair68
NORMAL
2023-07-15T09:10:21.495251+00:00
2023-07-15T09:10:21.495280+00:00
41
false
# Approach 1 - Double Loops\n<!-- Describe your approach to solving the problem. -->\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nNote that the order in which subarrays receive operations does not matter. All that matters is which subarrays are chosen and how many times they rece...
1
0
['Queue', 'C++', 'Java', 'Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Greedy Using sliding window and deque
greedy-using-sliding-window-and-deque-by-w42e
Intuition\n Describe your first thoughts on how to solve this problem. \nFor each window of size k ,the minimum element in that window should be greater than th
user3220K
NORMAL
2023-07-10T17:19:12.807194+00:00
2023-07-10T17:20:35.079193+00:00
112
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor each window of size k ,the minimum element in that window should be greater than the first element. Also in the last element of next window add first element of current window.\nInstead of substracting in current window I am changing ...
1
0
['Greedy', 'Sliding Window', 'C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Easy C++ Solution
easy-c-solution-by-lakshya_12-nj07
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
lakshya_12
NORMAL
2023-07-10T08:45:06.269899+00:00
2023-07-10T08:45:06.269923+00:00
127
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
0
['Sliding Window', 'C++']
1
apply-operations-to-make-all-array-elements-equal-to-zero
Rust Prefix Sum
rust-prefix-sum-by-xiaoping3418-lp7t
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
xiaoping3418
NORMAL
2023-07-09T19:50:39.931486+00:00
2023-07-09T19:50:39.931514+00:00
24
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$...
1
0
['Rust']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Sweep line
sweep-line-by-darv-mx80
Code\n\nclass Solution {\n bool checkArray(List<int> nums, int k) {\n final sweep = List.filled(nums.length, 0);\n int prev_sweep_sum = 0;\n for (int
darv
NORMAL
2023-07-09T19:19:39.663999+00:00
2023-07-09T19:19:39.664018+00:00
67
false
# Code\n```\nclass Solution {\n bool checkArray(List<int> nums, int k) {\n final sweep = List.filled(nums.length, 0);\n int prev_sweep_sum = 0;\n for (int i = 0; i < nums.length; i++) {\n sweep[i] += prev_sweep_sum;\n\n if (nums[i] + sweep[i] != 0) {\n if (nums.length - i < k) return false;\n...
1
0
['Dart']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Simple Answer | Good for Beginners | C++ | Java | ♥🚀
simple-answer-good-for-beginners-c-java-7xup2
C++\n\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n = nums.size(), s = 0,j = 0;\n deque<pair<int, int>> q;\n
adityabahl
NORMAL
2023-07-09T15:27:21.966795+00:00
2023-07-09T15:27:21.966824+00:00
464
false
C++\n```\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n = nums.size(), s = 0,j = 0;\n deque<pair<int, int>> q;\n for (int i = 0; i < n; ++i) {\n while (!q.empty() && i - q.front().first >= k) {\n s -= q.front().second;\n ...
1
0
['C', 'Java']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Swift | Sliding window approach explained
swift-sliding-window-approach-explained-nheat
Intuition\n- If there is a winning set of operations, then the order in which these operations are performed does not matter.\n- The first and last numbers have
VladimirTheLeet
NORMAL
2023-07-09T06:12:30.440441+00:00
2023-07-09T07:19:44.684715+00:00
145
false
# Intuition\n- If there is a winning set of operations, then the order in which these operations are performed does not matter.\n- The first and last numbers have only one variant of valid subarray that affects them.\n- More generally, the same can be said for the first and last non-zero nums.\n- We can reduce nums to ...
1
0
['Swift', 'Sliding Window']
0
apply-operations-to-make-all-array-elements-equal-to-zero
C++ Simple Greedy Two pointers
c-simple-greedy-two-pointers-by-harshils-m57c
Code\n\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n=nums.size();\n int i=0, j=n-1;\n while(i <= j){\
HarshilSad007
NORMAL
2023-07-09T04:44:49.184307+00:00
2023-07-09T04:44:49.184336+00:00
543
false
# Code\n```\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n=nums.size();\n int i=0, j=n-1;\n while(i <= j){\n while(i<=j && nums[i]==0) i++;\n while(i<=j && nums[j]==0) j--;\n if(i>j) return true;\n if(j-i < k-1) return...
1
0
['Two Pointers', 'Greedy', 'C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Using queue approach | C++ solution
using-queue-approach-c-solution-by-gl01-vhs0
Intuition\nThe very first & simple intuition is to store the position up to which deletions are being made and update the delete sum with nums array to ensure t
gl01
NORMAL
2023-07-09T04:35:40.313967+00:00
2023-07-09T04:35:40.313985+00:00
403
false
# Intuition\nThe very first & simple intuition is to store the position up to which deletions are being made and update the delete sum with `nums` array to ensure the elements become zero.\n\n# Approach\nI used a `queue` to store deleted elements and a vector `del` to keep track of their positions. Starting from index ...
1
0
['Queue', 'C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Exactly same q from codeforces
exactly-same-q-from-codeforces-by-heho12-j68z
\nclass Solution {\n public boolean checkArray(int[] nums, int k) {\n int n = nums.length;\n for (int i = 0; i < n - k + 1; i++) {\n
heho123
NORMAL
2023-07-09T04:07:32.935590+00:00
2023-07-09T04:07:32.935615+00:00
493
false
```\nclass Solution {\n public boolean checkArray(int[] nums, int k) {\n int n = nums.length;\n for (int i = 0; i < n - k + 1; i++) {\n if (nums[i] > 0) {\n int min = nums[i];\n for (int j = i; j < i + k; j++) {\n nums[j] -= min;\n ...
1
1
[]
2
apply-operations-to-make-all-array-elements-equal-to-zero
Prefix Sum
prefix-sum-by-awakenx-s6nf
Code
AwakenX
NORMAL
2025-04-09T12:59:40.053472+00:00
2025-04-09T12:59:40.053472+00:00
2
false
# Code ```cpp [] class Solution { public: bool checkArray(vector<int>& nums, int k) { int n = nums.size(); vector<int> prefix(n + 1); prefix[0] = -1 * nums[0]; prefix[k] = nums[0]; for(int i = 1; i < n; i++) { prefix[i] += prefix[i - 1]; int...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Running Difference Array Technique | Java Code
running-difference-array-technique-java-cds55
CodeComplexity Analysis Time complexity: O(n) Space complexity: O(n) Do Upvote ⬆️⬆️⬆️.Keep Hustling,Keep Coding!!!
Rahul_Me_Gupta
NORMAL
2025-03-18T15:16:48.320011+00:00
2025-03-18T15:16:48.320011+00:00
10
false
# Code ```java [] class Solution { public static boolean check(int[] nums,int start,int end) { for(int i=start;i<=end;i++){ if(nums[i]!=0){ return false; } } return true; } public static void print(int[] nums){ for(int it:nums){ ...
0
0
['Array', 'Hash Table', 'Math', 'Prefix Sum', 'C++', 'Java']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Reverse of Line Sweep
reverse-of-line-sweep-by-lilongxue-rbhw
IntuitionIt can be solved by using the reverse of line sweep.ApproachSee code.Complexity Time complexity: O(n) Space complexity: O(n) Code
lilongxue
NORMAL
2025-03-18T04:21:20.620793+00:00
2025-03-18T04:21:20.620793+00:00
3
false
# Intuition It can be solved by using the reverse of line sweep. # Approach See code. # Complexity - Time complexity: O(n) - Space complexity: O(n) # Code ```javascript [] /** * @param {number[]} nums * @param {number} k * @return {boolean} */ var checkArray = function(nums, k) { const len = nums.length con...
0
0
['JavaScript']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Greedy + Sliding Window || C++|| O(N) Time Complexity
greedy-sliding-window-c-on-time-complexi-vs4w
IntuitionTo make the entire array zero using the given operation, we need to apply a greedy approach while keeping track of the accumulated decrement effect. Si
Shiva1906
NORMAL
2025-03-07T17:08:00.219079+00:00
2025-03-07T17:08:00.219079+00:00
6
false
# Intuition To make the entire array zero using the given operation, we need to apply a **greedy** approach while keeping track of the accumulated decrement effect. Since we can only modify `k` consecutive elements at a time, we must ensure that at every index `i`, the remaining value in `nums[i]` is sufficient to be r...
0
0
['Array', 'Greedy', 'Sliding Window', 'Prefix Sum', 'C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
python
python-by-mykono-g1w9
Code
Mykono
NORMAL
2025-03-07T08:52:24.705891+00:00
2025-03-07T08:52:24.705891+00:00
3
false
# Code ```python3 [] class Solution: def checkArray(self, nums: List[int], k: int) -> bool: cur = 0 for i, num in enumerate(nums): if cur > num: return False # num - cur is ops required after cur ops # and i's contribution to cur nums[i...
0
0
['Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Easy Python Solution
easy-python-solution-by-vidhyarthisunav-rnoz
Code
vidhyarthisunav
NORMAL
2025-02-10T21:48:47.788312+00:00
2025-02-10T21:48:47.788312+00:00
22
false
# Code ```python3 [] class Solution: def checkArray(self, nums: List[int], k: int) -> bool: n = len(nums) diff = [0] * (n + 1) curr = 0 for i in range(n): curr += diff[i] nums[i] += curr if nums[i] < 0: return False ...
0
0
['Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Java difference array + sliding window beats 63%
java-difference-array-sliding-window-bea-ci27
IntuitionApproachComplexity Time complexity: O(n) Space complexity: O(n) Code
siyang_yin
NORMAL
2025-02-06T22:11:10.130138+00:00
2025-02-06T22:11:10.130138+00:00
13
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: $$O(n)$$ <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: $$O(n)$$ <!-- Add your space complexity here, e.g. $$O(...
0
0
['Sliding Window', 'Java']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Py Solution Leverage Prefix Sums Linear Pass O(N) T,S Solution
py-solution-leverage-prefix-sums-linear-in99t
Intuition and ApproachSee problem titleComplexityN=len(input) Time complexity: O(N) Space complexity: O(N) ( Explicit ) O(1) ( Implicit ) Code
2018hsridhar
NORMAL
2025-01-09T20:29:58.335825+00:00
2025-01-09T20:29:58.335825+00:00
27
false
# Intuition and Approach See problem title # Complexity $$N = len(input)$$ - Time complexity: $$O(N)$$ - Space complexity: $$O(N)$$ ( Explicit ) $$O(1)$$ ( Implicit ) # Code ```python3 [] ''' URL := https://leetcode.com/problems/apply-operations-to-make-all-array-elements-equal-to-zero/description/ 2772. Apply Oper...
0
0
['Array', 'Prefix Sum', 'Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Detailed Explanation - Prefix Sum + Sliding Window 🔥
detailed-explanation-prefix-sum-sliding-rnk8a
IntuitionInspired by the post:https://leetcode.com/problems/apply-operations-to-make-all-array-elements-equal-to-zero/solutions/3743200/easiest-solution-intuiti
saiphaniram98
NORMAL
2024-12-14T03:58:24.139123+00:00
2024-12-14T03:59:25.242627+00:00
36
false
# Intuition\n\nInspired by the post:\n\nhttps://leetcode.com/problems/apply-operations-to-make-all-array-elements-equal-to-zero/solutions/3743200/easiest-solution-intuition-explained-o-n-faster-than-100-c-java/\n\nEvery element is impacted by deletions on previous `(k-1)` elements which when put together forms the wind...
0
0
['Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Sliding window with hashtable
sliding-window-with-hashtable-by-shayank-2k31
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
shayankhan1156
NORMAL
2024-12-01T05:14:38.675016+00:00
2024-12-01T05:14:38.675043+00:00
11
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. $$O...
0
0
['Hash Table', 'Sliding Window', 'C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
[Python] Inverted line sweep (2-liner)
python-inverted-line-sweep-2-liner-by-ds-ihj9
Approach\nWe may use the line sweep technique in reverse:\n\n1. Restore the array of value deltas\n2. Check that this array is valid:\n 2.a First k elements
dsapelnikov
NORMAL
2024-11-09T22:38:12.169844+00:00
2024-11-09T22:49:34.326468+00:00
12
false
# Approach\nWe may use the line sweep technique in reverse:\n\n1. Restore the array of value deltas\n2. Check that this array is valid:\n 2.a First k elements of this array >= 0\n 2.b The sum of every k-spaced subarray == 0\n\n# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```p...
0
0
['Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
[C++] Beats 100% | EASY TO UNDERSTAND INTUITIVE SOLUTION
c-beats-100-easy-to-understand-intuitive-3uja
Intuition\nThe first element in nums needs exactly nums[i] operations and it can appear in only one window i.e. the window starting with itself so all the eleme
ahbar
NORMAL
2024-10-19T13:53:44.749386+00:00
2024-10-19T13:53:44.749421+00:00
4
false
# Intuition\nThe first element in nums needs exactly nums[i] operations and it can appear in only one window i.e. the window starting with itself so all the elements after it within the windows will also get reduced by nums[0], use the same logic for nums[1] and so on..\n\n# Approach\nkeep track of number of operations...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Easy C++ Solution
easy-c-solution-by-himanshuackerman-j7fv
Code\ncpp []\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n = nums.size();\n for(int i = 0; i < nums.size() -
himanshuackerman
NORMAL
2024-09-06T17:46:24.057405+00:00
2024-09-06T17:46:24.057433+00:00
9
false
# Code\n```cpp []\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n = nums.size();\n for(int i = 0; i < nums.size() - k + 1; i++){\n if(nums[i] > 0){\n int mini = nums[i];\n for(int j = i; j < i + k; j++){\n nums...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
halwa || aao aur kha lo ||
halwa-aao-aur-kha-lo-by-rajan_singh5639-7f5i
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
rajan_singh5639
NORMAL
2024-08-30T21:59:50.695775+00:00
2024-08-30T21:59:50.695813+00:00
6
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
halwa || aao aur kha lo ||
halwa-aao-aur-kha-lo-by-rajan_singh5639-ms2p
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
rajan_singh5639
NORMAL
2024-08-30T21:59:48.308815+00:00
2024-08-30T21:59:48.308839+00:00
1
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
khud samz sakte ho aram sss
khud-samz-sakte-ho-aram-sss-by-rajan_sin-6ht0
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
rajan_singh5639
NORMAL
2024-08-30T21:07:54.300951+00:00
2024-08-30T21:07:54.300979+00:00
4
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Simple Prefix Sum C++✅✅|Easy Solution
simple-prefix-sum-ceasy-solution-by-jaye-g45r
\n\n# Code\n\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> pre(n, 0);\n\n
Jayesh_06
NORMAL
2024-08-16T08:21:34.446245+00:00
2024-08-16T08:21:34.446269+00:00
7
false
\n\n# Code\n```\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> pre(n, 0);\n\n for (int i = 0; i < n; i++) {\n (i > 0) ? pre[i] += pre[i - 1] : 0;\n nums[i] -= pre[i];\n if (nums[i] < 0) {\n ...
0
0
['Array', 'Prefix Sum', 'C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Sliding window with subtraction.
sliding-window-with-subtraction-by-sav20-t6q6
Approach\nIn the loop, I look for the first non-"0" first.\nThis value is used as the "subtractor" in a loop of length "k".\nIf there is a number smaller than t
sav20011962
NORMAL
2024-07-15T08:25:01.923392+00:00
2024-07-15T08:25:01.923427+00:00
2
false
# Approach\nIn the loop, I look for the first non-"0" first.\nThis value is used as the "subtractor" in a loop of length "k".\nIf there is a number smaller than the "subtractor" in this loop, no conversion is possible.\n# Complexity\nimage.\n![image.png](https://assets.leetcode.com/users/images/3cc3f905-0079-46dd-b780-...
0
0
['Kotlin']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Simple Approach but can be optimized more
simple-approach-but-can-be-optimized-mor-rn3c
Intuition\n1)Trying out 5-6 test cases you will find out the pattern that we need to decrement a particular value nums[i], nums[i] times then only that will bec
Hardy1
NORMAL
2024-07-03T14:18:23.007132+00:00
2024-07-03T14:18:23.007172+00:00
14
false
# Intuition\n1)Trying out 5-6 test cases you will find out the pattern that we need to decrement a particular value nums[i], nums[i] times then only that will become zero.\n\n# Approach\n1) Approach is similar to prefix sum.\n2) First we need to check how many times we need to decrement a particular element.\n3) We nee...
0
0
['Array', 'Prefix Sum', 'C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
O(nLogk) using segment tree and lazy propogation
onlogk-using-segment-tree-and-lazy-propo-cowv
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
leethard
NORMAL
2024-06-25T13:27:40.371209+00:00
2024-06-25T13:27:40.371232+00:00
10
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Simple python3 solution | Prefix Sum + Hash Table
simple-python3-solution-prefix-sum-hash-os8e7
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. O(n) \n\n# Co
tigprog
NORMAL
2024-06-24T20:31:27.037568+00:00
2024-06-24T20:33:54.915150+00:00
45
false
# 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. $$O(n)$$ -->\n\n# Code\n``` python3 []\nclass Solution:\n def checkArray(self, nums: List[int], k: int) -> bool:\n n = len(nums)\n\n ...
0
0
['Hash Table', 'Greedy', 'Sliding Window', 'Prefix Sum', 'Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Java brute force
java-brute-force-by-ihatealgothrim-60t0
Intuition\n- Do the actual decrease operation over nums start from beginning with length of k, say indices (i, j) inclusive, repeat this process until the end o
IHateAlgothrim
NORMAL
2024-06-13T13:32:13.579410+00:00
2024-06-13T13:32:13.579442+00:00
20
false
# Intuition\n- Do the actual decrease operation over ```nums``` start from beginning with length of ```k```, say indices ```(i, j)``` inclusive, repeat this process until the end of ```nums```\n- Each time when decreasing, ```nums[i]``` MUST always less or equals to the one on the right i.e. ```nums[i+1], nums[i+2], nu...
0
0
['Java']
0
apply-operations-to-make-all-array-elements-equal-to-zero
scala ugly nonFP solution. cleaner nonFP or FP produce MLE
scala-ugly-nonfp-solution-cleaner-nonfp-q30il
scala\nobject Solution {\n import collection.immutable.Queue\n def checkArray(nums: Array[Int], k: Int): Boolean =\n def forall(lo:Int, hi:Int): Boolean =\
vititov
NORMAL
2024-06-08T16:11:53.097986+00:00
2024-06-08T16:14:17.688778+00:00
1
false
```scala\nobject Solution {\n import collection.immutable.Queue\n def checkArray(nums: Array[Int], k: Int): Boolean =\n def forall(lo:Int, hi:Int): Boolean =\n if(hi<=lo) true else nums(hi)==nums(lo) && forall(lo,hi-1)\n def dec(lo:Int, hi:Int): Unit = if(hi>=lo) { nums(hi)-=nums(lo); dec(lo,hi-1) }\n d...
0
0
['Scala']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Greedy 10 lines code c++
greedy-10-lines-code-c-by-vishal_reddy_k-bk25
Intuition\n Describe your first thoughts on how to solve this problem. \nGreedy and simple. go from first element and check the conditions\n\n# Approach\n Descr
VISHAL_REDDY_K
NORMAL
2024-06-08T11:57:50.905902+00:00
2024-06-08T11:57:50.905932+00:00
6
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGreedy and simple. go from first element and check the conditions\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Cpp code||Brute method||traversing all the possible subarrays from left to right and making them 0.
cpp-codebrute-methodtraversing-all-the-p-uliz
Intuition\nwe have to make all the possible k element subarrays to 0;\nso starting from the very left of nums we\'ll try to turn each of the subarray into 0 whi
yashashvi-J
NORMAL
2024-06-08T09:57:19.921767+00:00
2024-06-08T09:57:19.921797+00:00
9
false
# Intuition\nwe have to make all the possible k element subarrays to 0;\nso starting from the very left of nums we\'ll try to turn each of the subarray into 0 while moving right \nfor instance,if a[0]>0 then we have to subtract a certain number(temp=a[0]) from all k elements following it.\n\n\neg.[2,2,3,1,1,0] and k=3\...
0
0
['Array', 'C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Beats 100% 97%. In-place prefix sum.
beats-100-97-in-place-prefix-sum-by-tyle-imjz
Approach\nKeep prefix sum of how much we have currently decreased an element. If it is negative then return False. Decrease element to 0, and store how much we
tyler__
NORMAL
2024-06-06T04:12:43.671272+00:00
2024-06-06T04:12:43.671307+00:00
17
false
# Approach\nKeep prefix sum of how much we have currently decreased an element. If it is negative then return False. Decrease element to 0, and store how much we decreased the element. \n\nWe can\'t decrease the last k-1 elements any farther.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1) extra ...
0
0
['Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
O(n) solution using a single pass on the array
on-solution-using-a-single-pass-on-the-a-2ygu
Intuition\nWe start from the left hand side of the array, and we know that for every extrimity, we have no choice but to remove a[0] times the array, that will
magic_yoni
NORMAL
2024-06-04T07:52:23.387184+00:00
2024-06-04T07:52:23.387215+00:00
13
false
# Intuition\nWe start from the left hand side of the array, and we know that for every extrimity, we have no choice but to remove a[0] times the array, that will impact the next k elements. We keep track of the next k elements to know what has been removed already. \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space ...
0
0
['Python']
0
apply-operations-to-make-all-array-elements-equal-to-zero
One of the best solution
one-of-the-best-solution-by-risabhuchiha-4vk7
\n\nclass Solution {\n public boolean checkArray(int[] nums, int k) {\n if(k==1)return true;\n Deque<Integer>dq=new ArrayDeque<>();\n int nd=0;\n
risabhuchiha
NORMAL
2024-06-01T20:11:11.457524+00:00
2024-06-01T20:11:11.457545+00:00
22
false
\n```\nclass Solution {\n public boolean checkArray(int[] nums, int k) {\n if(k==1)return true;\n Deque<Integer>dq=new ArrayDeque<>();\n int nd=0;\n for(int i=0;i<nums.length;i++){\n if(i>=k){\n nd-=dq.pollFirst();\n }\n if(nums[i]<nd)return false;\n int nx=nums[i]-nd...
0
0
['Java']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Hard Intution and observation | | C++
hard-intution-and-observation-c-by-arbaz-bmyp
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
Arbaz_nitp
NORMAL
2024-05-20T10:13:17.995010+00:00
2024-05-20T10:13:17.995041+00:00
14
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
c++ most easiest approach
c-most-easiest-approach-by-bhavanabadava-ockt
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
bhavanabadavath29
NORMAL
2024-05-17T06:07:52.457884+00:00
2024-05-17T06:07:52.457918+00:00
12
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Ruby O(N) time and O(k) space with explanation
ruby-on-time-and-ok-space-with-explanati-d749
Intuition\n\nBy going from left to right, the leftmost element (a0) always has to be reduced to 0. That means the leftmost element and its group have to be redu
rmuntani
NORMAL
2024-04-26T18:21:51.509717+00:00
2024-04-26T18:21:51.509736+00:00
2
false
# Intuition\n\nBy going from left to right, the leftmost element (a0) always has to be reduced to 0. That means the leftmost element and its group have to be reduced by the remaining leftmost (a0). Example:\n\n[7,9,10,11,14] with k = 2 - after reducing the leftmost element and its group, we will get [0,2,10,11,14].\n\n...
0
0
['Ruby']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Deque
deque-by-macrohard-o5gn
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
macrohard
NORMAL
2024-02-15T07:05:58.329337+00:00
2024-02-15T07:05:58.329385+00:00
7
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Java']
0
apply-operations-to-make-all-array-elements-equal-to-zero
An anology of a stack of pancakes
an-anology-of-a-stack-of-pancakes-by-alc-e132
Intuition\n Describe your first thoughts on how to solve this problem. \nImagine the nums as a stack of even pancakes of length k, say, [1, 2, 2, 1] (k=3).\nWhe
alchenerd
NORMAL
2024-02-11T07:27:35.159371+00:00
2024-02-11T07:27:35.159404+00:00
10
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nImagine the `nums` as a stack of even pancakes of length `k`, say, [1, 2, 2, 1] (k=3).\nWhen we nudge the rightmost pancake to its left, `nums` becomes [2, 2, 2, 0].\nThis is same as taking `nums[3]` and adding it to `nums[0]`.\nIf `nums`...
0
0
['Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Prefix Sum approach~~C++~~Cpp~~O(n) time~~Beats 90%+
prefix-sum-approachccppon-timebeats-90-b-3gwt
Intuition\nAt first it looks like that we have to check a sorted list but it was almost similar to that.\n\n# Approach\nwe have to check a sorted list but wiht
Abdullah-Ishfaq
NORMAL
2024-01-26T13:30:49.854118+00:00
2024-01-26T14:34:41.773269+00:00
14
false
## Intuition\nAt first it looks like that we have to check a sorted list but it was almost similar to that.\n\n# Approach\nwe have to check a sorted list but wiht some ristrictions,\nin case we want list with 0 elements we should take first k elements than i+1 till k+1 and so on but we have to substract difference betw...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
91.26% Beats | No special algo - just a single loop 🔥🔥🔥
9126-beats-no-special-algo-just-a-single-gerb
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
SyedSohaib
NORMAL
2024-01-23T01:40:43.483368+00:00
2024-01-23T01:40:43.483391+00:00
17
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Python Explained Sliding Window
python-explained-sliding-window-by-dinar-wy4b
Python\nclass Solution:\n def checkArray(self, nums: List[int], k: int) -> bool:\n if k == 1:\n return True\n q = deque([0] * k)\n
dinar
NORMAL
2024-01-10T19:33:01.244564+00:00
2024-01-10T19:33:01.244597+00:00
11
false
```Python\nclass Solution:\n def checkArray(self, nums: List[int], k: int) -> bool:\n if k == 1:\n return True\n q = deque([0] * k)\n s = 0\n for n in nums:\n left = q.popleft()\n s -= left\n if n < s:\n return False\n ...
0
0
['Python']
0
apply-operations-to-make-all-array-elements-equal-to-zero
similar to line sweep tc:O(N) space:O(1)
similar-to-line-sweep-tcon-spaceo1-by-ut-d7ev
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
cute_utkarshi
NORMAL
2024-01-09T17:13:34.818771+00:00
2024-01-09T17:13:34.818801+00:00
4
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(1)\n<!-- Add your space complexity here, e.g. $$O...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
O(n) time, O(k) mem
on-time-ok-mem-by-harkness-w8x8
Intuition\nThe first elememt needs to become 0, so at some point we need to pick first k elements and subtract nums[0] from all of them. Assume this operation h
harkness
NORMAL
2024-01-05T00:01:31.276780+00:00
2024-01-05T00:01:31.276812+00:00
10
false
# Intuition\nThe first elememt needs to become 0, so at some point we need to pick first k elements and subtract nums[0] from all of them. Assume this operation happens after another operation on another window of k. Then these 2 operations can be swapped in order, and resulting array is the same. So we can perform the...
0
0
['Queue', 'Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
java solution very important question
java-solution-very-important-question-by-unq5
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
trivedi_cs1
NORMAL
2023-12-24T13:54:44.156962+00:00
2023-12-24T13:54:44.156992+00:00
31
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Java']
0
apply-operations-to-make-all-array-elements-equal-to-zero
C++, O(n) time, very beginner friendly, with comments
c-on-time-very-beginner-friendly-with-co-wyb5
Intuition\nIf I organized the data such that I had, for each element, only the influence from the previous k - 1 elements; then this problem would be easily sol
adamcesco
NORMAL
2023-11-20T00:42:35.163102+00:00
2023-11-20T00:42:35.163124+00:00
11
false
# Intuition\nIf I organized the data such that I had, for each element, only the influence from the previous k - 1 elements; then this problem would be easily solved.\n\n# Approach\n1. Have a queue, where the front element always holds the influence of the element at i - (k - 1). This queue represents our influence win...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Intuitive solution
intuitive-solution-by-crusher95574-b1xh
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
Crusher95574
NORMAL
2023-10-28T17:19:51.560684+00:00
2023-10-28T17:19:51.560702+00:00
14
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Java']
0
apply-operations-to-make-all-array-elements-equal-to-zero
C# O(n)
c-on-by-tt_nk-ae9a
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
tt_nk
NORMAL
2023-10-15T10:17:28.150000+00:00
2023-10-15T10:17:28.150026+00:00
9
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C#']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Prefix Sum Approach, optiminal Solution
prefix-sum-approach-optiminal-solution-b-1blf
Intuition\n Describe your first thoughts on how to solve this problem. \nFor the first A[i] > 0,\nwe need to select the array A[i],A[i+1]..A[i+k-1]\nand decreas
Shree_Govind_Jee
NORMAL
2023-10-12T16:01:33.651846+00:00
2023-10-12T16:01:33.651868+00:00
66
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor the first `A[i] > 0`,\nwe need to select the array `A[i],A[i+1]..A[i+k-1]`\nand decrease all these elements by `A[i]`.\n\n\n# Approach\nThe subarray deleted starting at `A[i]`,\nwill affect the `A[i+1], A[i+2], ...A[i+k-1]`.\n\nSo we ...
0
0
['Array', 'Prefix Sum', 'Java']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Python Line Sweep/Greedy O(n)
python-line-sweepgreedy-on-by-tannerr12-2dng
Greedily remove from the leftmost element which should than make a new leftmost element. for example [2,2,3,1,1,0] k = 3 the only way to get to at postion 0 is
Tannerr12
NORMAL
2023-09-27T23:00:57.252370+00:00
2023-09-27T23:00:57.252389+00:00
4
false
Greedily remove from the leftmost element which should than make a new leftmost element. for example [2,2,3,1,1,0] k = 3 the only way to get to at postion 0 is to subtract 2,2,3 and we can greedily subtract 2 from this whole array making [0,0,1,1,1,0] since we dont want to manually go through and update these elements ...
0
0
['Greedy']
0
apply-operations-to-make-all-array-elements-equal-to-zero
O(n) solution
on-solution-by-user9062q-3s9m
Intuition\n Describe your first thoughts on how to solve this problem. \nFirst, instead of trying to make the array zero. try to build the array from all zeros.
user9062q
NORMAL
2023-09-17T07:36:10.101667+00:00
2023-09-17T07:36:10.101686+00:00
11
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst, instead of trying to make the array zero. try to build the array from all zeros. \n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nbase cases are trivial.\nfor this we are gonna take a index i and every k-l...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
not easy solution
not-easy-solution-by-tharunbandi007-9za3
Intuition\n Describe your first thoughts on how to solve this problem. \nno explanation , not easy solution \n\n# Approach\n Describe your approach to solving t
tharunbandi007
NORMAL
2023-09-15T12:53:25.132370+00:00
2023-09-15T12:53:25.132421+00:00
14
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nno explanation , not easy solution \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nprefix sum \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n- Space complexity...
0
0
['Greedy', 'Prefix Sum', 'C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Sliding Window | Array | Java | O(N) | Video Tutorial
sliding-window-array-java-on-video-tutor-n1pi
Approach\n Describe your approach to solving the problem. \n Apply Operation from one end (here from start) \n At ith index , choose K size subarray and decreas
21stCenturyLegend
NORMAL
2023-09-01T13:20:06.143482+00:00
2023-09-01T13:20:06.143509+00:00
20
false
# Approach\n<!-- Describe your approach to solving the problem. -->\n* Apply Operation from one end (here from start) \n* At ith index , choose K size subarray and decrease the all elements by ith index value. \n\n# Video Tutorial (For all)\nhttps://youtu.be/uAqmYIwCudY\n\n# Complexity\n- Time complexity: O(N)\n<!-- Ad...
0
0
['Java']
0
apply-operations-to-make-all-array-elements-equal-to-zero
simple one iteration solution without sliding window Python 3
simple-one-iteration-solution-without-sl-sdgb
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
throwawayleetcoder19843
NORMAL
2023-08-17T03:36:47.687697+00:00
2023-08-17T03:36:47.687716+00:00
24
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Python3']
1
apply-operations-to-make-all-array-elements-equal-to-zero
simple one iteration solution without sliding window Python 3
simple-one-iteration-solution-without-sl-g4gi
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
throwawayleetcoder19843
NORMAL
2023-08-17T03:36:46.965109+00:00
2023-08-17T03:36:46.965126+00:00
23
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
[C++] O(n) space, O(k) time. Beats 99.93%
c-on-space-ok-time-beats-9993-by-luizcor-d5fc
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
LuizCordeiro
NORMAL
2023-07-31T19:18:46.170902+00:00
2023-07-31T19:18:46.170926+00:00
16
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
JavaScript brute force spaghetti O(kn) time
javascript-brute-force-spaghetti-okn-tim-5fm2
\n/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar checkArray = function(nums, k) {\n const len = nums.length;\n if (len =
el_rookie
NORMAL
2023-07-29T23:59:57.603600+00:00
2023-07-29T23:59:57.603619+00:00
24
false
```\n/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar checkArray = function(nums, k) {\n const len = nums.length;\n if (len === 1) return true;\n let max = -Infinity;\n for (let i = 0; i < len; i++) {\n if (i <= len - k) {\n if (nums[i] === 0) continue;\n const curre...
0
0
['JavaScript']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Simple C++ Solution
simple-c-solution-by-asrawat2001-gse9
Code\n\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int curr=0;\n if(k==1){\n return true;\n }\n
asrawat2001
NORMAL
2023-07-29T07:05:18.545958+00:00
2023-07-29T07:05:18.545977+00:00
11
false
# Code\n```\nclass Solution {\npublic:\n bool checkArray(vector<int>& nums, int k) {\n int curr=0;\n if(k==1){\n return true;\n }\n int n=nums.size();\n for(int i=0;i<k;i++){\n if(nums[i]<nums[0]){\n return false;\n }\n }\n ...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
C++ time: O(N) space: O(1) with explanation
c-time-on-space-o1-with-explanation-by-s-v6vu
Intuition\n1) Slide the window from left to right, keeping track of the accumulated decrease value of the k - 1 previous windows (dec).\n2) i is the left side o
skoparov
NORMAL
2023-07-22T09:44:46.572639+00:00
2023-07-22T09:44:46.572661+00:00
21
false
# Intuition\n1) Slide the window from left to right, keeping track of the accumulated decrease value of the k - 1 previous windows (`dec`).\n2) `i` is the *left* side of the window, hense this is the last chance of decrease the current element to 0 (since all other windows containing `nums[i]` have already been process...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
EASY Solution
easy-solution-by-mishra__ji20-rm3y
\n\nclass Solution {\npublic:\n bool check(vector<int> &nums,int k)\n {\n if(nums.size()==1 || k==1)\n return 1;\n queue<int>q;\n
mishra__ji20
NORMAL
2023-07-21T19:30:40.295856+00:00
2023-07-21T19:30:40.295879+00:00
13
false
\n```\nclass Solution {\npublic:\n bool check(vector<int> &nums,int k)\n {\n if(nums.size()==1 || k==1)\n return 1;\n queue<int>q;\n int sum=0;\n for(int i=0;i<nums.size();i++)\n {\n if(nums.size()-1==i)\n {\n if(sum!=nums[i])\n ...
0
0
['Queue']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Best explanation so far
best-explanation-so-far-by-sk_games-xs2q
If you on my level of IQ, you probably find this helpful. All solutions for this problems which people mention (Prefix Sub/Queue, Backtrack tracking) are based
sk_games
NORMAL
2023-07-20T22:22:53.844612+00:00
2023-08-05T06:43:20.374671+00:00
63
false
If you on my level of IQ, you probably find this helpful. All solutions for this problems which people mention (Prefix Sub/Queue, Backtrack tracking) are based on the next idea. \n\n\nStarting at some index and moving to the right: \n- When you see any number(let\'s say N) greater than 0, **the only one way where solut...
0
0
['C++', 'Java', 'Python3']
0
apply-operations-to-make-all-array-elements-equal-to-zero
NEW CONCEPT | SLIDING WINDOW + IMPACT PRESERVE | LEARN NEW TODAY❤️‍🔥
new-concept-sliding-window-impact-preser-yhpi
Intuition # Approach\n// used the approach to start from each window of size k and then subtracting each element from the starting element of each window \n// i
MihirKathpal
NORMAL
2023-07-19T06:16:08.618069+00:00
2023-07-19T06:16:08.618088+00:00
21
false
# Intuition # Approach\n// used the approach to start from each window of size k and then subtracting each element from the starting element of each window \n// if any element is negative then return false\n// but this O(n*k-1) times and this create time limit excedded\n// to make it optimal ---> I tried this approach\...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Sliding Window Protocol + Prefix Sum || Commented Code
sliding-window-protocol-prefix-sum-comme-xyky
Code\n\nclass Solution {\npublic:\n\n // prefix sum + sliding window\n bool checkArray(vector<int>& nums, int k) {\n int n = nums.size();\n\n
om_golhani
NORMAL
2023-07-19T05:50:01.658012+00:00
2023-07-19T05:50:01.658040+00:00
18
false
# Code\n```\nclass Solution {\npublic:\n\n // prefix sum + sliding window\n bool checkArray(vector<int>& nums, int k) {\n int n = nums.size();\n\n // temp = value that is to be decreased from the current element and next k-1 elements to make \n // current element 0.\n int temp = 0;\n ...
0
0
['C++']
0
apply-operations-to-make-all-array-elements-equal-to-zero
Array | prefixsum
array-prefixsum-by-rahulkumarhavitmsi-ziha
\n# Code\n\nclass Solution {\n public boolean checkArray(int[] nums, int k) {\n int len = nums.length;\n long[] arr = new long[len];\n l
rahulkumarhavitmsi
NORMAL
2023-07-17T17:39:50.529872+00:00
2023-07-17T17:39:50.529892+00:00
40
false
\n# Code\n```\nclass Solution {\n public boolean checkArray(int[] nums, int k) {\n int len = nums.length;\n long[] arr = new long[len];\n long prefixSum = 0;\n for (int j = 0; j < len; j++) {\n prefixSum += arr[j];\n nums[j] += prefixSum;\n if (nums[j] < 0...
0
0
['Java']
0
find-target-indices-after-sorting-array
Java O(N) single-loop count
java-on-single-loop-count-by-singyeh-hby5
One iteration to count less than target, and equal target. Build output based on the first index at lessthan.\n\n\nclass Solution {\n public List<Integer> ta
singyeh
NORMAL
2021-11-28T04:14:24.059568+00:00
2021-11-28T04:14:24.059599+00:00
13,339
false
One iteration to count less than `target`, and equal `target`. Build output based on the first index at `lessthan`.\n\n```\nclass Solution {\n public List<Integer> targetIndices(int[] nums, int target) {\n int count = 0, lessthan = 0;\n for (int n : nums) {\n if (n == target) count++;\n ...
312
1
[]
28
find-target-indices-after-sorting-array
Python O(N) Easy and Fast
python-on-easy-and-fast-by-true-detectiv-tv2y
Just count the number of elements that are less than and equal to target and create a list out of those.\n\n\nclass Solution:\n def targetIndices(self, nums,
true-detective
NORMAL
2021-11-29T20:14:42.915520+00:00
2022-10-29T04:41:41.179571+00:00
5,777
false
Just count the number of elements that are less than and equal to target and create a list out of those.\n\n```\nclass Solution:\n def targetIndices(self, nums, target):\n lt_count = eq_count = 0\n for n in nums:\n if n < target:\n lt_count += 1\n elif n == target:\...
108
1
[]
14
find-target-indices-after-sorting-array
C++ O(N) Time Counting Sort
c-on-time-counting-sort-by-lzl124631x-0gu2
\n\nSee my latest update in repo LeetCode\n\n## Solution 1. Sorting\n\ncpp\n// OJ: https://leetcode.com/contest/weekly-contest-269/problems/find-target-indices-
lzl124631x
NORMAL
2021-11-28T04:00:45.402909+00:00
2021-11-28T04:00:45.402941+00:00
9,078
false
\n\nSee my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Sorting\n\n```cpp\n// OJ: https://leetcode.com/contest/weekly-contest-269/problems/find-target-indices-after-sorting-array/\n// Author: github.com/lzl124631x\n// Time: O(NlogN)\n// Space: O(1) extra space\nclass Soluti...
97
1
[]
13
find-target-indices-after-sorting-array
✅Concise/Simple | Beats 100% | Explained Both O(n) & O(nlogn)
concisesimple-beats-100-explained-both-o-4070
1st Method [Sorting]:\nCode:\n\npublic List<Integer> targetIndices(int[] nums, int target) { \n Arrays.sort(nums);\n\t ArrayList<Integer> ans =
rohan_21s
NORMAL
2021-11-28T13:23:22.507070+00:00
2022-01-21T19:17:13.828677+00:00
6,745
false
# **1st Method [Sorting]:**\n**Code:**\n```\npublic List<Integer> targetIndices(int[] nums, int target) { \n Arrays.sort(nums);\n\t ArrayList<Integer> ans = new ArrayList<Integer>();\n\t\t \n for(int i=0;i<nums.length;i++){\n if(nums[i] == target) ans.add(i);\n }\n retur...
85
3
['Counting Sort', 'Java']
9
find-target-indices-after-sorting-array
4 different Ways | Binary Search | Counting Sort | Time Complexities Explained
4-different-ways-binary-search-counting-zgxwf
Approach 1: This approach is naive as it\'s the one that comes to mind at first. Sort the array. Traverse it and find the valid indexes,such that nums[index] ==
deadline_savvy
NORMAL
2021-12-01T18:28:35.452825+00:00
2021-12-01T18:32:01.918270+00:00
6,437
false
**Approach 1**: This approach is naive as it\'s the one that comes to mind at first. Sort the array. Traverse it and find the valid indexes,such that `nums[index] == target`. \nTime Complexity: `O(Nlog N + N) ~ O(NLogN)`\n```\nclass Solution {\npublic:\n vector<int> targetIndices(vector<int>& nums, int target) {\n ...
71
1
['Sorting', 'Binary Tree', 'Counting Sort']
4
find-target-indices-after-sorting-array
Count Smaller and Equal
count-smaller-and-equal-by-votrubac-9fd8
We do not need to sort the array - we can just count elements smaller than the target.\n\nThe first index of the target (in the sorted array) will be smaller, t
votrubac
NORMAL
2021-11-28T22:29:01.036776+00:00
2021-11-29T01:27:48.462238+00:00
4,966
false
We do not need to sort the array - we can just count elements `smaller` than the target.\n\nThe first index of the target (in the sorted array) will be `smaller`, then `smaller + 1`, and so on - depending on how many times the target appears in the array.\n\n**C++**\n```cpp\nvector<int> targetIndices(vector<int>& nums,...
58
3
['C']
9