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
valid-triangle-number
✅ C++ || Similar to 3Sum || Easy
c-similar-to-3sum-easy-by-bharatupadhyay-pop2
\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n int cou
BharatUpadhyay
NORMAL
2022-11-02T17:59:00.282337+00:00
2022-11-02T17:59:00.282361+00:00
565
false
```\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n int count = 0;\n for(int k = nums.size() - 1; k > 1; k--)\n {\n int j = k - 1;\n int i = 0;\n while(i < j)\n ...
4
0
['Two Pointers', 'C']
0
valid-triangle-number
Faster 3 Pointer solution | Dry run and explanation
faster-3-pointer-solution-dry-run-and-ex-cgpq
Please find the below explained and details dry run solution for the problem - (dry run at the below after the code)\n\nTheorem of triangle:\n\nLets first under
Shubham_Kurhade
NORMAL
2022-09-13T19:06:33.868583+00:00
2022-09-13T19:06:33.868628+00:00
565
false
Please find the below explained and details dry run solution for the problem - (dry run at the below after the code)\n\n**Theorem of triangle:**\n\nLets first understand the given condition - the property of triangle says that \'sum of the lengths of two sides of the triangle shall be greater than thrid side\' i.e `(a ...
4
0
['Two Pointers', 'Sorting', 'Binary Tree', 'C++', 'Java']
0
valid-triangle-number
Valid Triangle Number | Java Solution | Explanatory Comments
valid-triangle-number-java-solution-expl-zn83
\nclass Solution {\n public int triangleNumber(int[] nums) {\n int result = 0; // A var to keep the count of valid
azan_49
NORMAL
2021-07-16T16:02:52.261513+00:00
2021-07-16T16:02:52.261563+00:00
338
false
```\nclass Solution {\n public int triangleNumber(int[] nums) {\n int result = 0; // A var to keep the count of valid triangles\n \n if(nums.length < 3) // First check if there are atleast 3 numbers in the array or not\n ...
4
0
['Two Pointers', 'Java']
0
valid-triangle-number
Small and Simple C++ Solution 8 lines With Detailed Explanation
small-and-simple-c-solution-8-lines-with-cmvm
Let us assume there are 3 sides of a triangle named a ,b ,c \nand we are going to choose a,b,c in such an order, so that ac** \n(2). **b+c>a \n(3). c+
sanketmohta99
NORMAL
2021-07-16T08:05:59.447948+00:00
2021-07-16T11:23:14.313165+00:00
440
false
Let us assume there are 3 sides of a triangle named a ,b ,c \nand we are going to choose a,b,c in such an order, so that **a<b<c**\nNow we know condition to make a traingle is \n(1). **a+b>c** \n(2). **b+c>a** \n(3). **c+a>b** \nSince a<b<c , the inequalities (2) and (3) are always satisfied irrespective...
4
0
['C', 'Sorting', 'C++']
0
valid-triangle-number
C++ 2 approaches (O(n^2log(n) -> O(n^2))
c-2-approaches-on2logn-on2-by-mazhar_mik-bpit
More about Interview Questions : https://github.com/MAZHARMIK/Interview_DS_Algo\nFull July Challenge Solution : https://github.com/MAZHARMIK/Leetcode-July-Chall
mazhar_mik
NORMAL
2021-07-15T14:32:10.425815+00:00
2021-07-16T05:43:47.715283+00:00
117
false
More about Interview Questions : https://github.com/MAZHARMIK/Interview_DS_Algo\nFull July Challenge Solution : https://github.com/MAZHARMIK/Leetcode-July-Challenge-2021/blob/main/README.md\n\n```\n//Approach-1 (Using Binary Search)\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n int n ...
4
1
[]
0
valid-triangle-number
611 - Sort solution, Sort with Binary Search solution
611-sort-solution-sort-with-binary-searc-85mh
---\nAlgo\n\n- Core rule for making a triangle from sides s1, s2 and s3 is one of the following\n - s1 + s2 > s3\n - s2 + s3 > s1\n - s3 + s1 > s2\n - Tha
pgmreddy
NORMAL
2021-07-15T13:58:37.442985+00:00
2021-07-15T22:45:18.270522+00:00
146
false
---\n**Algo**\n\n- **Core rule** for making a triangle from sides `s1`, `s2` and `s3` is one of the following\n - s1 + s2 > s3\n - s2 + s3 > s1\n - s3 + s1 > s2\n - That means, `sum of 2 sides is greater than 3rd side`\n- **Sort solution 1**\n - By sorting we can go ahead to right side only like\n - i goes fr...
4
0
[]
0
valid-triangle-number
2 solutions -- brute force (n^3) and 2 pointer approach
2-solutions-brute-force-n3-and-2-pointer-9mwd
Solution 1\nGiven that we need to sum 2 numbers and the result must be greater than a 3rd number, i got the feeling that sorting the input first would help us a
dclif
NORMAL
2021-06-29T20:47:42.449187+00:00
2021-06-29T20:53:49.112586+00:00
465
false
**Solution 1**\nGiven that we need to sum 2 numbers and the result must be greater than a 3rd number, i got the feeling that sorting the input first would help us alot. This way we can have small values in the front and large ones on the back. \n\nIn a way you can sort of think of this as a 3sum problem where the quest...
4
0
['Two Pointers', 'Sorting', 'JavaScript']
0
valid-triangle-number
Swift: 2 pointers
swift-2-pointers-by-voxqhuy-guln
\nclass Solution {\n func triangleNumber(_ nums: [Int]) -> Int {\n let sorted = nums.sorted()\n let count = sorted.count\n var result =
voxqhuy
NORMAL
2020-09-21T05:05:49.761491+00:00
2020-09-21T05:05:49.761523+00:00
129
false
```\nclass Solution {\n func triangleNumber(_ nums: [Int]) -> Int {\n let sorted = nums.sorted()\n let count = sorted.count\n var result = 0\n \n for c in stride(from: count - 1, through: 2, by: -1) {\n var a = 0, b = c - 1\n while a < b {\n if ...
4
0
[]
1
valid-triangle-number
Java | Binary Search | Solution 2
java-binary-search-solution-2-by-yangl92-a4nz
The implementation of approach 2 in official solution.\n\n```\nclass Solution {\n public int triangleNumber(int[] nums) {\n \n Arrays.sort(nums);\n
yangl9203
NORMAL
2020-09-14T11:44:08.918876+00:00
2020-09-14T11:44:08.918919+00:00
746
false
The implementation of approach 2 in official solution.\n\n```\nclass Solution {\n public int triangleNumber(int[] nums) {\n \n Arrays.sort(nums);\n int res = 0;\n \n for (int i = 0; i < nums.length - 2; i++) {\n for (int j = i + 1; j < nums.length - 1; j++) {\n int sum = nums[i] + ...
4
0
['Binary Tree', 'Java']
0
valid-triangle-number
Easy Solution Using Binary Search and Sorting || C++ || Beat 100%
easy-solution-using-binary-search-and-so-aeq5
IntuitionSort the array to simplify the triangle inequality. After sorting, the condition a+b>c only needs to be checked for the largest side c since a≤b≤c. Thi
ratankumar10
NORMAL
2025-01-08T05:08:51.193523+00:00
2025-01-08T05:08:51.193523+00:00
411
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> ***Sort the array to simplify the triangle inequality. After sorting, the condition a+b>c only needs to be checked for the largest side c since a≤b≤c. This sets up the problem for efficient iteration and binary search.*** # Approach <!-- ...
3
0
['Array', 'Two Pointers', 'Binary Search', 'Greedy', 'Sorting', 'C++']
0
valid-triangle-number
Valid Triangle Number
valid-triangle-number-by-tejdekiwadiya-1zxi
Intuition\nTo form a valid triangle from three sides, the sum of any two sides must be greater than the third side. Specifically, for a triangle with sides a, b
tejdekiwadiya
NORMAL
2024-09-21T16:06:20.987438+00:00
2024-09-21T16:06:20.987455+00:00
486
false
# Intuition\nTo form a valid triangle from three sides, the sum of any two sides must be greater than the third side. Specifically, for a triangle with sides `a`, `b`, and `c` (sorted such that `a <= b <= c`), the condition `a + b > c` must hold. The task is to count how many such valid triples exist in the input array...
3
0
['Array', 'Two Pointers', 'Binary Search', 'Greedy', 'Sorting', 'Java']
0
valid-triangle-number
SIMPLE TWO-POINTER C++ SOLUTION
simple-two-pointer-c-solution-by-jeffrin-wt8i
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
Jeffrin2005
NORMAL
2024-07-23T16:14:50.898220+00:00
2024-07-23T16:14:50.898258+00:00
593
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: o(nlogn + n^2) => o(n^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:o(1)\n<!-- Add your space comp...
3
0
['C++']
0
valid-triangle-number
Two Pointer Approach || Sorting || Optimal Solution || 74% T.C || 88% S.C || CPP
two-pointer-approach-sorting-optimal-sol-8etg
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
Ganesh_ag10
NORMAL
2024-04-16T05:28:51.346588+00:00
2024-04-16T05:28:51.346613+00:00
367
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^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $...
3
0
['C++']
0
valid-triangle-number
✅Commented Binary Search Solution✅
commented-binary-search-solution-by-shiv-bw3d
Python Implementation\n\nclass Solution:\n def triangleNumber(self, nums: List[int]) -> int:\n \n """\n Triangle property: a + b > c (a,
shivamshinde123
NORMAL
2024-03-15T09:23:32.101273+00:00
2024-03-15T09:23:32.101305+00:00
434
false
# Python Implementation\n```\nclass Solution:\n def triangleNumber(self, nums: List[int]) -> int:\n \n """\n Triangle property: a + b > c (a, b, c --> sides of a triangle)\n \n So, in the solution, we first fix the value of \'c\' and then find a,b values such that they satify the \...
3
0
['Binary Search', 'Python3', 'JavaScript']
1
valid-triangle-number
Short & Clean Java Solution
short-clean-java-solution-by-himanshubho-gajf
\n# Complexity\n- Time complexity:\nO(n^2)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\n public int triangleNumber(int[] nums) {\n Arra
HimanshuBhoir
NORMAL
2022-12-14T13:48:11.376465+00:00
2022-12-14T13:48:11.376498+00:00
1,271
false
\n# Complexity\n- Time complexity:\nO(n^2)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n public int triangleNumber(int[] nums) {\n Arrays.sort(nums);\n int count = 0;\n for(int k=nums.length-1; k>1; k--){\n int i=0, j=k-1;\n while(i<j){\n if...
3
0
['Java']
0
valid-triangle-number
java solution
java-solution-by-janhvi__28-77o9
\nclass Solution {\n public int triangleNumber(int[] nums) {\n Arrays.sort(nums);\n int size = nums.length;\n int result = 0;\n f
Janhvi__28
NORMAL
2022-11-16T13:26:54.988838+00:00
2022-11-16T13:26:54.988876+00:00
599
false
```\nclass Solution {\n public int triangleNumber(int[] nums) {\n Arrays.sort(nums);\n int size = nums.length;\n int result = 0;\n for(int i=size-1;i>=0;i--){\n int start = 0;\n int end = i-1;\n while(start<end){\n if(nums[start]+nums[end] >...
3
0
['Java']
0
valid-triangle-number
[Python3] | binary-search
python3-binary-search-by-swapnilsingh421-9hl7
\nclass Solution:\n def triangleNumber(self, nums: List[int]) -> int:\n n=len(nums)\n ans=0\n nums.sort()\n for i in range(n):\n
swapnilsingh421
NORMAL
2022-10-16T09:21:47.945834+00:00
2022-10-16T09:21:47.945878+00:00
1,113
false
```\nclass Solution:\n def triangleNumber(self, nums: List[int]) -> int:\n n=len(nums)\n ans=0\n nums.sort()\n for i in range(n):\n for j in range(i+1,n):\n s2s=nums[i]+nums[j]\n ind=bisect.bisect_left(nums,s2s)\n ans+=max(0,ind-j-1)...
3
0
['Binary Tree', 'Python', 'Python3']
0
valid-triangle-number
Using binary search
using-binary-search-by-the_amazing_spide-ajxl
````\nclass Solution {\npublic:\n int triangleNumber(vector& nums) {\n int ans = 0;\n sort(nums.begin(), nums.end());\n for(int i = 0; i
the_amazing_spider_man___
NORMAL
2022-04-01T02:12:36.053892+00:00
2022-04-01T02:12:36.053941+00:00
327
false
````\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n int ans = 0;\n sort(nums.begin(), nums.end());\n for(int i = 0; i < nums.size(); i++) {\n for(int j = i+1; j < nums.size(); j++) {\n int sum = nums[i] + nums[j];\n int idx = lower...
3
0
['C', 'C++']
2
valid-triangle-number
✔️[C++] ||8 line Simple Code || Easy to Understand || TC: O( n^2 ) , SC: O( 1 )
c-8-line-simple-code-easy-to-understand-9k8fu
Please Upvote if it helps\u2B06\uFE0F\n\n\tint triangleNumber(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size(),triplets=0
anant_0059
NORMAL
2022-03-26T17:53:51.780962+00:00
2022-03-26T17:53:51.781002+00:00
331
false
#### *Please Upvote if it helps\u2B06\uFE0F*\n```\n\tint triangleNumber(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size(),triplets=0;\n for(int i=n-1;i>=0;--i){\n int l=0, r=i-1;\n while(l<r){\n if(nums[l]+nums[r]>nums[i]) triplets+=r-l,r...
3
0
['Two Pointers', 'C']
0
valid-triangle-number
C++ || Better = > Optimal || Clean Code
c-better-optimal-clean-code-by-jk20-7uci
1. Binary Search Solution \n\n###### Time Complexity : : O ( nn log n )\n###### Space Complexity : : O ( 1 ) \n\n\nclass Solution {\npublic:\n int triangle
jk20
NORMAL
2021-11-12T07:01:17.938335+00:00
2021-11-12T07:01:53.620985+00:00
476
false
## 1. Binary Search Solution \n\n###### Time Complexity : : O ( n*n log n )\n###### Space Complexity : : O ( 1 ) \n\n```\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n \n sort(nums.begin(),nums.end());\n int i,j;\n int n=nums.size();\n int c=0;\n for(i...
3
0
['C', 'Sorting', 'Binary Tree', 'C++']
0
valid-triangle-number
Very simple Two pointer| binary_search | easy-understanding
very-simple-two-pointer-binary_search-ea-2bgk
\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n \n sort(nums.begin(),nums.end());\n int ans =0;\n for(int
007shaswatkumar
NORMAL
2021-07-16T05:12:53.761502+00:00
2021-07-16T05:12:53.761546+00:00
275
false
```\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n \n sort(nums.begin(),nums.end());\n int ans =0;\n for(int i=0;i<nums.size();i++){\n \n for(int j=i+1;j<nums.size();j++){\n if(nums[i]!=0 && nums[j]!=0){\n int sum...
3
1
['Two Pointers', 'C', 'Sorting', 'Binary Tree']
1
valid-triangle-number
C++ Simple, 0ms
c-simple-0ms-by-apurv_1-kekd
\t\n\tint triangleNumber(vector& nums) {\n \n\t\tint count = 0;\n if(nums.size() < 3) return count;\n \n sort(nums.begin(), nums.end
apurv_1
NORMAL
2021-07-15T18:32:39.270360+00:00
2021-07-15T18:32:39.270400+00:00
183
false
\t\n\tint triangleNumber(vector<int>& nums) {\n \n\t\tint count = 0;\n if(nums.size() < 3) return count;\n \n sort(nums.begin(), nums.end());\n \n for(int i=2; i<nums.size() ; i++){\n int left = 0, right = i-1; //left pointer from 0, right pointer from 1(i-1)\n ...
3
0
['C']
0
valid-triangle-number
using efficient mthd to find number of triangles. in O(n^2) and O(1).. beats 96%
using-efficient-mthd-to-find-number-of-t-jz0x
\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n int n=nums.size();\n int count=0;\n sort(nums.begin(),nums.end()
rudraAbhi
NORMAL
2021-03-21T03:00:27.278537+00:00
2021-03-21T03:01:41.692903+00:00
357
false
```\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n int n=nums.size();\n int count=0;\n sort(nums.begin(),nums.end());\n for(int i=n-1;i>0;i--){\n \n int l=0;\n int r=i-1;\n \n while(l<r){\n ...
3
0
['Two Pointers', 'C++']
2
valid-triangle-number
Easy to Understand C++ solution
easy-to-understand-c-solution-by-tabover-t825
\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n \n int n = nums.size();\n int count = 0;\n \n sort
taboverspace
NORMAL
2021-03-10T14:24:02.336611+00:00
2021-03-10T14:24:56.774974+00:00
517
false
```\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n \n int n = nums.size();\n int count = 0;\n \n sort(nums.begin(),nums.end());\n \n for (int i = 0; i < n - 2; i++) {\n int k = i + 2;\n for (int j = i + 1; j < n - 1 && num...
3
0
['C', 'C++']
1
valid-triangle-number
Java 5 ms, faster than 99.04%
java-5-ms-faster-than-9904-by-sreenukami-xyqb
class Solution {\n \n public int triangleNumber(int[] A) {\n int n = A.length;\n Arrays.sort(A);\n int count = 0;\n for (int i
sreenukamireddy
NORMAL
2020-05-24T06:09:39.856633+00:00
2020-05-24T06:09:39.856684+00:00
213
false
class Solution {\n \n public int triangleNumber(int[] A) {\n int n = A.length;\n Arrays.sort(A);\n int count = 0;\n for (int i = n - 1; i > 1; i--) {\n int l = 0, r = i - 1;\n while (l < r) {\n if (A[l] + A[r] > A[i]) {\n count +=...
3
1
[]
1
valid-triangle-number
Two Solutions in Python 3 (Bisect and Linear Scan)
two-solutions-in-python-3-bisect-and-lin-iaxl
Bisect (Binary Search): ( O( n\xB2 log n ) ) (about 750 ms)\n\nclass Solution:\n def triangleNumber(self, T: List[int]) -> int:\n \tL, t, _ = len(T), 0, T
junaidmansuri
NORMAL
2019-08-09T11:33:22.927939+00:00
2019-09-26T08:34:42.087372+00:00
1,396
false
_Bisect (Binary Search):_ ( O( n\xB2 log n ) ) (about 750 ms)\n```\nclass Solution:\n def triangleNumber(self, T: List[int]) -> int:\n \tL, t, _ = len(T), 0, T.sort()\n \tfor i in range(L-2):\n \t\tk = i + 2\n \t\tfor j in range(i+1,L-1):\n \t\t\tM = T[i] + T[j] - 1\n \t\t\tif M < T[j]: continue\n ...
3
0
['Python', 'Python3']
0
valid-triangle-number
O(n^2) solution | Python3
on2-solution-python3-by-alpha2404-2ted
Please UpvoteCode
Alpha2404
NORMAL
2025-03-20T09:28:14.175368+00:00
2025-03-20T09:28:14.175368+00:00
78
false
# Please Upvote # Code ```python3 [] class Solution: def triangleNumber(self, nums: List[int]) -> int: nums.sort() result = 0 for i in range(len(nums)-1, 1, -1): left, right = 0, i - 1 while left < right: if nums[left] + nums[right] > nums[i]: ...
2
0
['Python3']
0
valid-triangle-number
Two Pointer Approach in Java| Beats 92%🔥
two-pointer-approach-in-java-beats-92-by-9d5y
IntuitionThe key observation is that a triangle can only be formed if the sum of any two sides is greater than the third side. By sorting the array, we can simp
karthick004
NORMAL
2025-02-17T07:22:03.532285+00:00
2025-02-17T07:22:03.532285+00:00
198
false
# Intuition The key observation is that a triangle can only be formed if the sum of any two sides is greater than the third side. By sorting the array, we can simplify the check: for any triplet (a,b,c) with 𝑎≤𝑏≤𝑐 , it is sufficient to ensure that a+b>c. # Approach 1.Sort the Array: Sorting the array allows us to u...
2
0
['Java']
0
valid-triangle-number
Valid Triangle Number + Complexity Analysis
valid-triangle-number-complexity-analysi-k67o
Code
naa7
NORMAL
2025-02-04T17:50:15.870932+00:00
2025-02-04T17:52:17.547405+00:00
239
false
# Code ```python3 [] """ Complexity Analysis: - Time Complexity: 1) BruteForce: O(n^3) 2) BinarySearch: O((n^2)*logn) 3) TwoPointers: O(n^2) - Space Complexity: O(1) """ class BruteForce: def find_triangle_number(self, nums): n = len(nums) triangle_number = 0 ...
2
0
['Array', 'Two Pointers', 'Binary Search', 'Greedy', 'Sorting', 'Python', 'Python3']
0
valid-triangle-number
👉🏻BEAT 94+% SOLUTION || FAST AND EASY TO UNDERSTAND || C++
beat-94-solution-fast-and-easy-to-unders-bmek
IntuitionApproachComplexity Time complexity: Space complexity: Code
Siddarth9911
NORMAL
2025-01-22T17:12:21.441796+00:00
2025-01-22T17:12:21.441796+00:00
235
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
['C++']
0
valid-triangle-number
Java || C++ Solution
java-c-solution-by-dsuryaprakash89-l7zv
IntuitionGiven that the array could be unsorted, we should first sort it to make the comparison easier. Once the array is sorted, we can use a two-pointer appro
dsuryaprakash89
NORMAL
2025-01-08T02:14:51.595911+00:00
2025-01-08T02:14:51.595911+00:00
168
false
# Intuition Given that the array could be unsorted, we should first sort it to make the comparison easier. Once the array is sorted, we can use a two-pointer approach to check for valid triangles. The idea is to fix one side of the triangle (let's call it nums[i]) and use two pointers to find pairs of sides that can ...
2
0
['Array', 'Two Pointers', 'Greedy', 'Sorting', 'C++', 'Java']
0
valid-triangle-number
[C++] TwoPointer O(n^2)
c-twopointer-on2-by-lshigami-zbvd
\n\n# Code\n\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n if(nums.size()<3) return 0;\n sort(nums.begin(),nums.end())
lshigami
NORMAL
2024-05-01T07:31:46.757726+00:00
2024-05-01T07:31:46.757773+00:00
519
false
\n\n# Code\n```\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n if(nums.size()<3) return 0;\n sort(nums.begin(),nums.end());\n int ans = 0;\n for (int i = 0; i < nums.size() - 2; i++) {\n int k = i + 2;\n for (int j = i + 1; j < nums.size() - 1...
2
0
['C++']
0
valid-triangle-number
Intuitive solution with sorting
intuitive-solution-with-sorting-by-dfale-0xzh
Intuition\n Describe your first thoughts on how to solve this problem. \nSort the array and then a two-pointer approach is used to iterate through possible comb
dfaleye
NORMAL
2023-12-02T19:47:35.549470+00:00
2023-12-02T19:47:35.549495+00:00
296
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSort the array and then a two-pointer approach is used to iterate through possible combinations efficiently\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nif nums[left] + nums[right] > nums[i], then all pairs with...
2
0
['Python3']
1
valid-triangle-number
Valid triangle solution💯✅
valid-triangle-solution-by-kaycu-8c79
Code\n\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar triangleNumber = function(nums) {\n // three pointers \n // 2 2 3 4 5\n nums.sort
kaycu
NORMAL
2023-09-23T21:39:42.516682+00:00
2023-09-23T21:39:42.516704+00:00
157
false
# Code\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar triangleNumber = function(nums) {\n // three pointers \n // 2 2 3 4 5\n nums.sort((a, b) => a - b)\n let output = 0\n\n for(let k in nums) {\n // get the indexes\n let i = 0;\n let j = k - 1\n\n while(i...
2
0
['JavaScript']
0
valid-triangle-number
Valid Triangle Number C++ solution
valid-triangle-number-c-solution-by-riss-pd0g
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
rissabh361
NORMAL
2023-09-07T05:14:57.304635+00:00
2023-09-07T05:14:57.304652+00:00
334
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
valid-triangle-number
Easy Java Code
easy-java-code-by-anjalii0811-d5ps
\n\nclass Solution {\n public int triangleNumber(int[] nums) {\n int n=nums.length;\n int count=0;\n Arrays.sort(nums);\n for(int
anjalii0811
NORMAL
2023-09-06T06:40:18.475313+00:00
2023-09-06T06:40:18.475336+00:00
753
false
\n```\nclass Solution {\n public int triangleNumber(int[] nums) {\n int n=nums.length;\n int count=0;\n Arrays.sort(nums);\n for(int i=0; i<n-2; i++)\n {\n for(int j=i+1; j<n-1; j++)\n {\n for(int k=j+1; k<n; k++)\n {\n ...
2
0
['Java']
0
valid-triangle-number
Java Solution | Using Two Pointers|
java-solution-using-two-pointers-by-s_j_-uxr6
Intuition\nFor right angled triangle, it should satisfy following 3 conditions (a,b and c are sides of triangle)\na+b>c\na+c>b\nb+c>a\n\nSuppose c>a+b then 2nd
S_J_322020
NORMAL
2023-07-20T12:13:31.087289+00:00
2023-07-20T12:13:31.087308+00:00
188
false
# Intuition\nFor right angled triangle, it should satisfy following 3 conditions (a,b and c are sides of triangle)\na+b>c\na+c>b\nb+c>a\n\nSuppose c>a+b then 2nd and 3rd condition is going to satisfy automatically so always keep the c at index with value greater than a and b\n\n# Approach\nSteps:\n1.Sort the array in i...
2
0
['Java']
0
valid-triangle-number
Triangle Statement, C++ ✅✅
triangle-statement-c-by-deepak_5910-4yq8
Approach\n Describe your approach to solving the problem. \nRecall the valid Triangle statement....!!!\n\nsum of two Lower sides > sum of Maximum side\nto Apply
Deepak_5910
NORMAL
2023-06-24T06:43:51.151182+00:00
2023-06-24T06:43:51.151216+00:00
598
false
# Approach\n<!-- Describe your approach to solving the problem. -->\nRecall the valid Triangle statement....!!!\n\n**sum of two Lower sides > sum of Maximum side**\nto Apply this statement sort the given array, now it becomes easy to compute all the triplets.\n\n\n\n# Complexity\n- Time complexity:O(N* N* log(N))\n<!--...
2
0
['Math', 'C++']
0
valid-triangle-number
two pointer solution beats 96% people
two-pointer-solution-beats-96-people-by-xoxpr
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
gouravsaroha
NORMAL
2023-03-05T13:14:26.301411+00:00
2023-03-05T13:14:26.301455+00:00
912
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
valid-triangle-number
Simple Easy C++ Solution ✔✔
simple-easy-c-solution-by-akanksha984-kgvv
Code\n\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n int cnt=0;\n sort(nums.begin(),nums.end());\n int n= nums.
akanksha984
NORMAL
2023-01-26T16:08:56.890699+00:00
2023-01-26T16:08:56.890753+00:00
1,722
false
## Code\n```\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n int cnt=0;\n sort(nums.begin(),nums.end());\n int n= nums.size();\n for (int k=n-1; k>=2; k--){\n int left=0; int right= k-1;\n while (left<right){\n if (nums[left]+num...
2
0
['Array', 'Two Pointers', 'Greedy', 'Sorting', 'C++']
1
valid-triangle-number
Simple Java solution
simple-java-solution-by-abstractconnoiss-q8cu
Code\n\nclass Solution {\n public int triangleNumber(int[] a) {\n Arrays.sort(a);\n int n=a.length;\n int count=0;\n for(int i=n-
abstractConnoisseurs
NORMAL
2023-01-25T13:15:34.907887+00:00
2023-01-25T13:15:34.907939+00:00
600
false
# Code\n```\nclass Solution {\n public int triangleNumber(int[] a) {\n Arrays.sort(a);\n int n=a.length;\n int count=0;\n for(int i=n-1;i>=1;i--){\n int left=0,right=i-1;\n while(left<right){\n if(a[left]+a[right]>a[i]){\n count+=rig...
2
0
['Array', 'Two Pointers', 'Binary Search', 'Greedy', 'Java']
0
valid-triangle-number
Java Solution with nested loop
java-solution-with-nested-loop-by-phanto-j2wn
Intuition\n Describe your first thoughts on how to solve this problem. \n- We know that the sum of any two sides should always be greater than the third side al
PhantomWraith
NORMAL
2022-12-24T09:25:22.937559+00:00
2022-12-24T09:26:35.057484+00:00
161
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- We know that the sum of any two sides should always be greater than the third side alone.\n- We need to sort from lowest to highest, then find 2 lower numbers on the left that can be greater than a higher number on the right.\n- If `num...
2
0
['Java']
0
valid-triangle-number
c++ || easy || binary search
c-easy-binary-search-by-bhupesh_singh01-2n4q
\nclass Solution {\npublic:\n int bsearch(vector<int>& nums,int i,int j,int val,int ans){\n if(i>j) return ans;\n int m=(i+j)/2;\n if(nu
bhupesh_singh01
NORMAL
2022-09-14T14:53:25.521233+00:00
2022-09-14T14:53:25.521273+00:00
211
false
```\nclass Solution {\npublic:\n int bsearch(vector<int>& nums,int i,int j,int val,int ans){\n if(i>j) return ans;\n int m=(i+j)/2;\n if(nums[m]==val) return bsearch(nums,i,m-1,val,m);\n else if(nums[m]<val) return bsearch(nums,m+1,j,val,ans);\n else return bsearch(nums,i,m-1,val,m...
2
0
['Binary Search']
0
valid-triangle-number
C++ | binary search approach
c-binary-search-approach-by-milochen-h4hr
Observation\nWhen a <= b <= c\nif a+b > c, then \n(1) a+c > b\n(2) b+c > a\nSo, we just need to find a<=b, and search maximum c s.t. a+b>c for all valid triplet
milochen
NORMAL
2022-06-23T16:11:35.482007+00:00
2022-06-23T16:11:35.482051+00:00
169
false
# Observation\nWhen a <= b <= c\nif a+b > c, then \n(1) a+c > b\n(2) b+c > a\nSo, we just need to find a<=b, and search maximum c s.t. a+b>c for all valid triplet. \n# Solution\n```C++\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n\t\n vector<int> &a = nums;\n int n = a.size();\...
2
0
['C', 'Binary Tree']
0
valid-triangle-number
Python | Very Simple | Binary Search with explanation
python-very-simple-binary-search-with-ex-xvo2
\nclass Solution(object):\n \'\'\'\n As we know inorder to check if a triangle is valid or not, if its sides are given:=>\n A triangle is a valid
__Asrar
NORMAL
2022-05-27T18:33:52.439641+00:00
2022-05-27T18:33:52.439685+00:00
985
false
```\nclass Solution(object):\n \'\'\'\n As we know inorder to check if a triangle is valid or not, if its sides are given:=>\n A triangle is a valid triangle, If and only If, the sum of any two sides of a triangle is \n greater than the third side. For Example, let A, B and C are three sides of a t...
2
0
['Two Pointers', 'Binary Tree', 'Python', 'Python3']
1
valid-triangle-number
✅ [Accepted] Solution for Swift
accepted-solution-for-swift-by-asahiocea-uvzm
swift\nclass Solution {\n func triangleNumber(_ nums: [Int]) -> Int {\n if nums.count < 3 { return 0 }\n let srt = nums.sorted()\n var v
AsahiOcean
NORMAL
2022-04-12T21:48:51.265348+00:00
2022-04-12T21:48:51.265390+00:00
750
false
```swift\nclass Solution {\n func triangleNumber(_ nums: [Int]) -> Int {\n if nums.count < 3 { return 0 }\n let srt = nums.sorted()\n var val = 0\n for i in (2..<srt.count).reversed() {\n var lhs = 0, rhs = i - 1\n while lhs < rhs {\n if srt[lhs] + srt...
2
0
['Swift']
0
valid-triangle-number
Python 2 Pointers O(n^2) Solution
python-2-pointers-on2-solution-by-zlax-pkui
\nclass Solution:\n def triangleNumber(self, nums: List[int]) -> int:\n nums.sort()\n count = 0\n \n for i in range(2, len(nums))
zlax
NORMAL
2021-10-02T19:33:50.465062+00:00
2021-10-02T19:33:50.465104+00:00
117
false
```\nclass Solution:\n def triangleNumber(self, nums: List[int]) -> int:\n nums.sort()\n count = 0\n \n for i in range(2, len(nums)):\n left, right = 0, i - 1\n while left < right:\n if nums[left] + nums[right] > nums[i]:\n count += ...
2
0
[]
0
valid-triangle-number
Java two-pointer approach
java-two-pointer-approach-by-irbr-ole4
\nclass Solution {\n public int triangleNumber(int[] nums) \n {\n int n = nums.length;\n if(n <= 2)\n return 0;\n \n
irbr
NORMAL
2021-09-11T03:30:40.828987+00:00
2021-09-11T03:30:40.829037+00:00
138
false
```\nclass Solution {\n public int triangleNumber(int[] nums) \n {\n int n = nums.length;\n if(n <= 2)\n return 0;\n \n Arrays.sort(nums);\n int total = 0;\n for(int i = n-1; i >= 2; i--)\n {\n int l = 0, r = i-1;\n \n wh...
2
0
[]
0
valid-triangle-number
[C++] Solution with sorting and binary search
c-solution-with-sorting-and-binary-searc-wr6j
Algorithm\n1. sort\n2. for every element search other two using binary search in array\n3. time complexity: O(n2)\n4. space Complexity: O(logn)\n\n\nclass Sol
rambabuy
NORMAL
2021-07-20T20:19:39.345347+00:00
2021-07-20T20:19:39.345374+00:00
183
false
Algorithm\n1. sort\n2. for every element search other two using binary search in array\n3. time complexity: O(n2)\n4. space Complexity: O(logn)\n\n```\nclass Solution {\npublic:\n \n //Sorting\n int triangleNumber(vector<int>& nums) {\n \n sort(nums.begin(), nums.end());\n int result = 0;\n ...
2
1
[]
0
valid-triangle-number
C++ solution || Binary Search approach
c-solution-binary-search-approach-by-rah-yj2i
\n\nclass Solution {\npublic:\n int triangleNumber(vector<int>& v) {\n sort(v.begin(),v.end());\n int g=0,n=v.size(),l,h;\n for(int i=n-
rahul2002m
NORMAL
2021-07-18T09:28:49.379585+00:00
2021-07-28T12:01:44.492068+00:00
175
false
```\n\nclass Solution {\npublic:\n int triangleNumber(vector<int>& v) {\n sort(v.begin(),v.end());\n int g=0,n=v.size(),l,h;\n for(int i=n-1;i>=0;i--){\n l=0;\n h=i-1;\n while(l<h){\n if(v[l]+v[h]>v[i]){\n g+=(h-l);\n ...
2
0
['C']
0
valid-triangle-number
Rust translated (28ms)
rust-translated-28ms-by-sugyan-w84g
rust\nimpl Solution {\n pub fn triangle_number(nums: Vec<i32>) -> i32 {\n let mut nums = nums.iter().filter(|&n| *n > 0).collect::<Vec<_>>();\n
sugyan
NORMAL
2021-07-15T14:24:34.709118+00:00
2021-07-15T14:24:34.709166+00:00
59
false
```rust\nimpl Solution {\n pub fn triangle_number(nums: Vec<i32>) -> i32 {\n let mut nums = nums.iter().filter(|&n| *n > 0).collect::<Vec<_>>();\n if nums.len() < 3 {\n return 0;\n }\n nums.sort_unstable();\n let mut answer = 0;\n for i in 0..nums.len() - 2 {\n ...
2
0
['Rust']
1
valid-triangle-number
Python O(N^2) solution
python-on2-solution-by-k3232908-7jzz
\nclass Solution:\n def triangleNumber(self, nums: List[int]) -> int:\n nums.sort()\n count=0\n for i in reversed(range(2,len(nums))):\n
k3232908
NORMAL
2021-07-15T13:43:20.920748+00:00
2021-07-15T13:45:27.181774+00:00
425
false
```\nclass Solution:\n def triangleNumber(self, nums: List[int]) -> int:\n nums.sort()\n count=0\n for i in reversed(range(2,len(nums))):\n r=i-1\n l=0\n while l<r:\n if(nums[r]+nums[l]>nums[i]):\n count+=r-l\n ...
2
0
['Python']
0
valid-triangle-number
C++ O(n^2) Time
c-on2-time-by-vartika_vr-39sa
Two pointer approach\n\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int count=0;\n
vartika_vr
NORMAL
2021-07-15T10:24:02.883570+00:00
2021-07-15T10:26:05.071868+00:00
290
false
Two pointer approach\n```\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int count=0;\n for(int i=nums.size()-1;i>=0;i--){\n int low= 0, high=i-1;\n while(low<=high){\n if(nums[low]+nums[high]>nums[i])...
2
0
['Two Pointers', 'C', 'C++']
0
valid-triangle-number
Valid Triangle || expalined || short code
valid-triangle-expalined-short-code-by-a-euod
guys if u find my answer helful please do upvote it motivates me to write quality answers thanks\n\nclass Solution {\npublic:\n int triangleNumber(vector<int
amit279
NORMAL
2021-07-15T07:31:02.456855+00:00
2021-07-15T07:36:58.121241+00:00
259
false
guys if u find my answer helful please do upvote it motivates me to write quality answers thanks\n```\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n int len = nums.size();\n // fistly sort the array\n sort(nums.begin(),nums.end());\n \n int ans = 0;\n ...
2
0
[]
1
valid-triangle-number
C++ Concise 100%
c-concise-100-by-anmolgera-nynk
\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n = nums.size();\n int ans =0;\n for
anmolgera
NORMAL
2021-03-20T00:13:29.299090+00:00
2021-03-20T00:13:29.299140+00:00
248
false
```\nclass Solution {\npublic:\n int triangleNumber(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n = nums.size();\n int ans =0;\n for(int i = n-1; i>=2; i--){\n \n int l =0;\n int r =i-1;\n while(l<r){\n \n if(nums[l]+nums[r]>nums[i]){\n ans+=r-l;\n ...
2
0
[]
0
valid-triangle-number
Python solution beats 99% (sort array and start from end)
python-solution-beats-99-sort-array-and-kze22
\nclass Solution(object):\n def triangleNumber(self, nums):\n """\n :type nums: List[int]\n :rtype: int\n """\n res = 0\n
yang135
NORMAL
2021-01-03T01:36:00.386421+00:00
2021-01-03T01:36:00.386462+00:00
191
false
```\nclass Solution(object):\n def triangleNumber(self, nums):\n """\n :type nums: List[int]\n :rtype: int\n """\n res = 0\n nums.sort()\n for i in range(len(nums)-1, -1, -1):\n cur = nums[i]\n left, right = 0, i-1\n while left < right...
2
0
[]
0
valid-triangle-number
SImple C++ using two pointers
simple-c-using-two-pointers-by-arpit-sat-06qw
\nint triangleNumber(vector<int>& nums) {\n\tif(nums.size()<3)\n\t\treturn 0;\n\tsort(nums.begin(),nums.end());\n\tint count=0;\n\tfor(int i=2;i<nums.size();i++
arpit-satnalika
NORMAL
2020-12-31T06:25:35.768106+00:00
2020-12-31T06:25:35.768153+00:00
192
false
```\nint triangleNumber(vector<int>& nums) {\n\tif(nums.size()<3)\n\t\treturn 0;\n\tsort(nums.begin(),nums.end());\n\tint count=0;\n\tfor(int i=2;i<nums.size();i++)\n\t{\n\t\tint left=0,right=i-1;\n\t\twhile(left<right)\n\t\t{\n\t\t\tif(nums[left]+nums[right]>nums[i])\n\t\t\t{\n\t\t\t\tcount=count+right-left;\n\t\t\t\t...
2
0
[]
0
destroy-sequential-targets
✅✅✅ C++ Solution with explanation || Using modulo & map
c-solution-with-explanation-using-modulo-n0x2
Up Vote if you like the solution\n\n/* \nVery simple approach is to just take the reminder of eanch element when divided by space.\nThen take the smallest eleme
kreakEmp
NORMAL
2022-10-29T16:01:40.165801+00:00
2023-07-15T17:14:52.034094+00:00
4,185
false
<b>Up Vote if you like the solution\n```\n/* \nVery simple approach is to just take the reminder of eanch element when divided by space.\nThen take the smallest element with having reminder same as that of maximum elements with same reminder.\n\n1. Count number of elements with same reminder, this can be achived by sim...
92
1
['C++']
11
destroy-sequential-targets
[Java/C++/Python] Count A[i] % space
javacpython-count-ai-space-by-lee215-cax4
Intuition\nThe elements with same remainder module by space,\ncan be destroied together.\n\n\n# Explanation\n1. Count the frequency of A[i] % space.\n2. The max
lee215
NORMAL
2022-10-29T16:55:37.657592+00:00
2022-10-29T17:02:25.914575+00:00
2,882
false
# **Intuition**\nThe elements with same remainder module by `space`,\ncan be destroied together.\n<br>\n\n# **Explanation**\n1. Count the frequency of `A[i] % space`.\n2. The maximum frequency `maxc` is the the maximum number of targets we can destroy.\n3. Find the minimum element A[i] that `A[i] % space = maxc`.\n<br>...
48
0
['C', 'Python']
5
destroy-sequential-targets
Explained approach // Basic Maths // % with map
explained-approach-basic-maths-with-map-t39vc
Intuition\nSo say you are destryoing j th index and you started from i th index\nthen *** nums[j] = nums[i] + c * space which can also be written as \nnums[j]-
jatindigra
NORMAL
2022-10-29T17:06:50.281140+00:00
2022-10-30T04:54:40.347882+00:00
1,078
false
# Intuition\nSo say you are destryoing j th index and you started from i th index\nthen *** nums[j] = nums[i] + c * space*** which can also be written as \n***nums[j]-nums[i] = c * space*** ?? right ??\nthis means the difference nums[j]-nums[i] will be divisible by space i.e, ***nums[j]-nums[i] % space = 0*** is TRUE ...
31
0
['Hash Table', 'Math', 'Ordered Map', 'Sorting', 'C++']
2
destroy-sequential-targets
Python O(N) solution with comments, easy-understanding
python-on-solution-with-comments-easy-un-7tln
\nclass Solution:\n #easy idea solution\n def destroyTargets(self, nums: List[int], space: int) -> int:\n dct = dict() \n mx = 0 # maximum o
StopFuture
NORMAL
2022-10-29T16:02:08.724195+00:00
2022-10-29T17:12:01.166550+00:00
1,858
false
```\nclass Solution:\n #easy idea solution\n def destroyTargets(self, nums: List[int], space: int) -> int:\n dct = dict() \n mx = 0 # maximum of destroyed targets\n \n for num in nums:\n x = num % space # if the numbers have the same remainder after division by space, \n ...
29
2
['Python']
8
destroy-sequential-targets
[Java/Python 3] Count the frequency of the remainder of modulo.
javapython-3-count-the-frequency-of-the-hzjb3
Q & A\n\nQ1: What does freqs.merge(n, 1, Integer::sum) mean in Java code?\nA1: freqs.merge(n, 1, Integer::sum) is simiar to freqs.put(n, freqs.getOrDefault(n, 0
rock
NORMAL
2022-10-29T16:01:15.470011+00:00
2022-10-31T16:58:02.795869+00:00
1,510
false
**Q & A**\n\nQ1: What does `freqs.merge(n, 1, Integer::sum)` mean in Java code?\nA1: `freqs.merge(n, 1, Integer::sum)` is simiar to `freqs.put(n, freqs.getOrDefault(n, 0) + 1)`, which increase the frequency (occurrence) of `n` by `1`; The difference between them is that `merge` return the increased frequency but `put` ...
21
1
['Java', 'Python3']
3
destroy-sequential-targets
✅ [Python/C++/Java/Rust] remainder equivalence classes (with detailed comments)
pythoncjavarust-remainder-equivalence-cl-g9h5
\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.\n*\nThis solution employs calculation of remainders to group numbers into equivalence classes. Time complexity
stanislav-iablokov
NORMAL
2022-10-29T16:00:57.331618+00:00
2022-10-29T18:46:52.878163+00:00
688
false
**\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n****\nThis solution employs calculation of remainders to group numbers into equivalence classes. Time complexity is logarithmic: **O(N\\*logN)**. Space complexity is linear: **O(N)**. \n\n**Comment**. Targets are numbers of the form `nums[i] + c * space`, namely, th...
18
3
[]
1
destroy-sequential-targets
Count Modulo
count-modulo-by-votrubac-0g65
All elements in the sequence have the same mod space.\n\nCount elements with the same modulo, and return the smallest element with the highest frequency modulo.
votrubac
NORMAL
2022-10-29T16:00:57.151828+00:00
2022-10-29T18:00:29.578994+00:00
1,386
false
All elements in the sequence have the same mod `space`.\n\nCount elements with the same modulo, and return the smallest element with the highest frequency modulo.\n\n**C++**\n```cpp\nint destroyTargets(vector<int>& nums, int space) {\n unordered_map<int, int> cnt;\n for (int n : nums)\n ++cnt[n % space];\n...
17
1
[]
6
destroy-sequential-targets
Explaining Why modulo solution Works
explaining-why-modulo-solution-works-by-51427
Given\nnums[i] can destroy all targets with values that can be represented as nums[i] + c * space\nc - Non-Negative integer.\nSpace - Constant.\nExplanation\nGi
venkatkri5h
NORMAL
2022-10-29T16:39:17.041944+00:00
2022-10-29T19:34:53.394137+00:00
625
false
**Given**\nnums[i] can destroy all targets with values that can be represented as nums[i] + c * space\nc - Non-Negative integer.\nSpace - Constant.\n**Explanation**\nGiven any number it will belong only to one series. \nFor example, \n```\nLets take space as 2. \nWhen space is 2, there can be two series. (space = Numbe...
16
0
[]
2
destroy-sequential-targets
HashMap
hashmap-by-vikad-frej
\nclass Solution\n{\n public int destroyTargets(int[] nums, int space)\n {\n int n = nums.length;\n HashMap<Integer,Integer> map = new HashM
vikad
NORMAL
2022-10-29T16:00:56.656587+00:00
2022-10-29T16:28:34.754713+00:00
679
false
```\nclass Solution\n{\n public int destroyTargets(int[] nums, int space)\n {\n int n = nums.length;\n HashMap<Integer,Integer> map = new HashMap<>();\n for(int num : nums)\n {\n num = num % space;\n map.put(num,map.getOrDefault(num,0)+1);\n }\n int ...
8
0
['Java']
0
destroy-sequential-targets
C++||Very Easy||Self explanatory Code
cvery-easyself-explanatory-code-by-baibh-jd9b
```\n\nclass Solution {\npublic:\n int destroyTargets(vector& nums, int space) {\n sort(nums.begin(),nums.end());\n unordered_mapmp; //for stori
baibhavkr143
NORMAL
2022-10-29T16:00:53.577789+00:00
2022-10-29T16:11:06.503563+00:00
945
false
```\n\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n sort(nums.begin(),nums.end());\n unordered_map<int,int>mp; //for storing min arr element with particular reminder\n unordered_map<int,int>freq; // for calculating freq of particular reminder\n \n ...
7
0
['C']
1
destroy-sequential-targets
java simple solution easy understanding
java-simple-solution-easy-understanding-gnceh
Approach: used remainder theorem (Dividend = Divisor * Quotient + Remainder)\nBecause only that target will be destroyed whose remainder is same with respect
deepakkdkk
NORMAL
2022-10-29T16:03:33.334907+00:00
2022-10-29T16:25:32.773977+00:00
1,138
false
Approach: used remainder theorem (Dividend = Divisor * Quotient + Remainder)\nBecause only that target will be destroyed whose remainder is same with respect to `space`\n```\nclass Solution {\n public int destroyTargets(int[] nums, int space) {\n \n Arrays.sort(nums); // purpost for sorting the ar...
5
0
['Sorting', 'Java']
2
destroy-sequential-targets
👩‍💻👨‍💻 Beginner friendly||⚡O(N) ||Python, C++, Java code 🚀🌟
beginner-friendlyon-python-c-java-code-b-6u3p
Intuition\n Describe your first thoughts on how to solve this problem. \nThe Most important line in the question is:\n\nSeeding the machine with some nums[i] al
Abhinav_Dixit
NORMAL
2023-07-14T20:32:02.121587+00:00
2023-07-15T07:06:17.224681+00:00
107
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe Most important line in the question is:\n\n`Seeding the machine with some nums[i] allows it to destroy all targets with values that can be represented as nums[i] + c * space, where c is any non-negative integer.`\n\nSo let us assume t...
4
0
['Python', 'C++', 'Java']
0
destroy-sequential-targets
c++ | 3 approaches
c-3-approaches-by-aaryak1369-53md
Solution 1: gives TLE\nTime Complexity: O(N^2)\nSpace Complexity: O(1)\n\nbrute force approach\ncheck nums[j]-nums[i]%space==0 for every jth index\n\nclass Solu
aaryak1369
NORMAL
2023-06-23T11:22:28.462902+00:00
2023-06-23T11:22:28.462925+00:00
205
false
# Solution 1: gives TLE\nTime Complexity: O(N^2)\nSpace Complexity: O(1)\n\nbrute force approach\ncheck nums[j]-nums[i]%space==0 for every jth index\n```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n sort(begin(nums),end(nums));\n int n=nums.size();\n int maxc...
4
0
['Hash Table', 'Math', 'Sorting', 'Counting', 'C++']
0
destroy-sequential-targets
Mod Map Solution👻
mod-map-solution-by-sarthak20574-fu35
Intuition\n\nnums[i]= all the elements that can be destroyed using ans as the seeding\n\nans + c * space = nums[i]\nnums[i] - ans = c * space\n\nsince c is a no
Sarthak20574
NORMAL
2022-11-13T18:21:43.669200+00:00
2022-11-13T18:21:43.669248+00:00
142
false
# Intuition\n\nnums[i]= all the elements that can be destroyed using ans as the seeding\n\nans + c * space = nums[i]\nnums[i] - ans = c * space\n\nsince c is a non negative integer so (nums[i] - ans) is divisible by space\n\n(nums[i] - ans) % space == 0\n\ntherefore, \nnums[i] % space - ans % space = 0\nnums[i] % space...
4
0
['Java']
0
destroy-sequential-targets
C++ || 2 different approaches || single pass / two passes || O(n)
c-2-different-approaches-single-pass-two-yo8i
Approach 1: single pass\n\nWe scan all of nums and while we do so we keep track for each rest class mod space how many numbers fall into and what\'s the smalles
heder
NORMAL
2022-10-30T14:24:55.087344+00:00
2022-10-30T14:29:42.836991+00:00
885
false
### Approach 1: single pass\n\nWe scan all of ```nums``` and while we do so we keep track for each rest class mod ```space``` how many numbers fall into and what\'s the smallest one we have seen so far.\n\n```cpp\n static int destroyTargets(const vector<int>& nums, int space) {\n unordered_map<int, pair<int, ...
4
0
['C']
0
destroy-sequential-targets
Short & Simple & Clean
short-simple-clean-by-neelmehta0086-tqib
\n\n1) store every remainder k%space in a map\n2) So choosing key of the map with max value (key\'s value will represent the number of element which could be de
neelmehta0086
NORMAL
2022-10-29T18:59:44.813806+00:00
2022-10-31T14:46:07.333450+00:00
249
false
![image](https://assets.leetcode.com/users/images/e8396de9-5341-40f9-ade0-fc4f51acdb6c_1667069978.8880672.jpeg)\n\n1) store every remainder k%space in a map\n2) So choosing key of the map with max value (key\'s value will represent the number of element which could be destroyed together if we choose this key)\n\n```\nc...
4
0
['Python']
1
destroy-sequential-targets
Easy C++ commented solution with intuition
easy-c-commented-solution-with-intuition-e8o5
Read question carefully, it formulates to (nums[j] - selected value) % space = 0 for max possible elements, so we count frequency of each remainder when divided
deleted_user
NORMAL
2022-10-29T16:02:19.045614+00:00
2022-10-29T16:10:05.643410+00:00
1,060
false
Read question carefully, it formulates to (nums[j] - selected value) % space = 0 for max possible elements, so we count frequency of each remainder when divided by space and find answer.\n\n```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n unordered_map<int, int> umap; //ma...
4
0
['C']
2
destroy-sequential-targets
Python | Greedy | Group | Example
python-greedy-group-example-by-yzhao156-41pj
\n\nclass Solution:\n def destroyTargets(self, nums: List[int], space: int) -> int:\n\t\t# example: nums = [3,7,8,1,1,5], space = 2\n groups = defaul
yzhao156
NORMAL
2022-10-29T16:01:28.138828+00:00
2022-10-29T16:20:13.117902+00:00
655
false
\n```\nclass Solution:\n def destroyTargets(self, nums: List[int], space: int) -> int:\n\t\t# example: nums = [3,7,8,1,1,5], space = 2\n groups = defaultdict(list)\n for num in nums:\n groups[num % space].append(num)\n \n # print(groups) # defaultdict(<class \'list\'>, {1: [3,...
4
0
['Python', 'Python3']
1
destroy-sequential-targets
[Python 3] Hash Table + Counting + Greedy - Easy to Understand
python-3-hash-table-counting-greedy-easy-ulpj
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
dolong2110
NORMAL
2023-06-10T11:38:55.820287+00:00
2023-06-10T11:38:55.820326+00:00
215
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...
3
0
['Array', 'Hash Table', 'Greedy', 'Counting', 'Python3']
1
destroy-sequential-targets
USING MAP || C++
using-map-c-by-ganeshkumawat8740-w4c1
SPACE COMPLEXITY IS O(SPACE)\n# Code\n\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n unordered_map<int,vector<int>
ganeshkumawat8740
NORMAL
2023-05-23T10:07:16.164133+00:00
2023-05-23T10:07:16.164181+00:00
216
false
SPACE COMPLEXITY IS O(SPACE)\n# Code\n```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n unordered_map<int,vector<int>> mp;\n int mx = 0, ans = 0;\n for(auto &i: nums){\n if(mp.count(i%space)==0){\n mp[i%space] = {1,i};\n }e...
3
0
['Array', 'Hash Table', 'Counting', 'C++']
0
destroy-sequential-targets
Java Solution Using Map
java-solution-using-map-by-nitwmanish-k2vw
\nclass Solution {\n public int destroyTargets(int[] nums, int space) {\n HashMap<Integer, Integer> map = new HashMap<>();\n for (int num : num
nitwmanish
NORMAL
2022-10-29T20:25:17.579153+00:00
2022-10-29T20:25:17.579178+00:00
59
false
```\nclass Solution {\n public int destroyTargets(int[] nums, int space) {\n HashMap<Integer, Integer> map = new HashMap<>();\n for (int num : nums){\n int mod = num % space;\n map.put(mod, map.getOrDefault(mod, 0) + 1);\n }\n int maxTargets = Collections.max(map.val...
3
0
['Java']
0
destroy-sequential-targets
JS Easy Solution
js-easy-solution-by-edwardfalcon-6g22
\n/**\n * @param {number[]} nums\n * @param {number} space\n * @return {number}\n */\nvar destroyTargets = function (nums, space) {\n nums.sort((a, b) => a - b
edwardfalcon
NORMAL
2022-10-29T17:18:16.707132+00:00
2022-10-29T17:18:16.707177+00:00
150
false
```\n/**\n * @param {number[]} nums\n * @param {number} space\n * @return {number}\n */\nvar destroyTargets = function (nums, space) {\n nums.sort((a, b) => a - b);\n const count = {};\n for (let num of nums) {\n const remainder = num % space;\n if (!count[remainder]) {\n count[remainder] = 0;\n }\n ...
3
0
['Hash Table', 'JavaScript']
0
destroy-sequential-targets
Video Explanation (With Intuition of every step)
video-explanation-with-intuition-of-ever-ztsg
https://www.youtube.com/watch?v=CFuCarnHoNM
codingmohan
NORMAL
2022-10-29T16:40:22.983611+00:00
2022-10-29T16:40:22.983653+00:00
29
false
https://www.youtube.com/watch?v=CFuCarnHoNM
3
0
[]
0
destroy-sequential-targets
C++ | Cleanest Code | Count modulo
c-cleanest-code-count-modulo-by-geekybit-npm0
\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n map<long long int,vector<long long int>> mp;\n for(int i=0;i
GeekyBits
NORMAL
2022-10-29T16:07:26.739025+00:00
2022-10-29T16:07:26.739062+00:00
165
false
```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n map<long long int,vector<long long int>> mp;\n for(int i=0;i<nums.size();i++){\n long long int diff=nums[i]%space;\n mp[diff].push_back(nums[i]);\n }\n long long int mx=-1e18;\n ...
3
0
[]
0
destroy-sequential-targets
Simple,Using Map Memory Limit Error explained
simpleusing-map-memory-limit-error-expla-vb72
Intuition\n Describe your first thoughts on how to solve this problem. \nA target can be destroyed if it is of type nums[i] + fk. so,we classify the numbers bas
SAIVARUN_GAJULA
NORMAL
2023-03-23T20:35:36.270436+00:00
2023-03-23T20:37:30.411900+00:00
33
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nA target can be destroyed if it is of type nums[i] + f*k. so,we classify the numbers based on the remainder they give when divided by k. \n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe keep track of the numbers g...
2
0
['Array', 'Counting', 'C++']
0
destroy-sequential-targets
Easy C++ Solution with hashmap
easy-c-solution-with-hashmap-by-bobo_lu-szin
\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n unordered_map<int, int> m;\n int res = INT_MAX;\n int
bobo_lu
NORMAL
2022-11-13T14:36:31.708524+00:00
2023-10-30T05:51:15.168665+00:00
421
false
```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n unordered_map<int, int> m;\n int res = INT_MAX;\n int maxcount = 0;\n \n // count the numbers with same reminder and find max count\n for (int n: nums) {\n maxcount = max(maxcoun...
2
0
['C++']
0
destroy-sequential-targets
Hash by Remainder
hash-by-remainder-by-ayushy_78-kpim
Intuition\nTo find such a number we group all numbers by their remainder and then we find the remainder with max frequency and afterwords we can find the minimu
SelfHelp
NORMAL
2022-11-10T08:30:46.245017+00:00
2022-11-10T08:30:46.245060+00:00
55
false
# Intuition\nTo find such a number we group all numbers by their remainder and then we find the remainder with max frequency and afterwords we can find the minimum number with remainder and max frequency.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nWe add all numbers to `rems` fa...
2
0
['Array', 'Hash Table', 'Math', 'C++']
0
destroy-sequential-targets
Python (Simple Maths)
python-simple-maths-by-rnotappl-5z5k
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
2022-11-08T17:58:27.204790+00:00
2022-11-08T17:58:27.204833+00:00
129
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']
0
destroy-sequential-targets
✅Best Solution in C++ || HashMap✅
best-solution-in-c-hashmap-by-adish_21-8blb
Code\nPlease Upvote if u liked my Solution\uD83D\uDE42\n\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n vector<int>
aDish_21
NORMAL
2022-10-30T19:08:09.774756+00:00
2022-10-30T19:08:09.774781+00:00
215
false
# Code\n**Please Upvote if u liked my Solution**\uD83D\uDE42\n```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n vector<int> vec;\n unordered_map<int,int> mp;\n int maxi=INT_MIN,count=0,ans=0;\n for(auto it:nums)\n vec.push_back(it%space);\n ...
2
0
['Hash Table', 'C++']
0
destroy-sequential-targets
Python | Three Lines | Mod Counter w/explanation
python-three-lines-mod-counter-wexplanat-pe0j
Intuition\nConsider two integers m and n. If m and n are in the same congruence class mod k (i.e., m % k == n % k), they must have the forms m = ak + r and n =
on_danse_encore_on_rit_encore
NORMAL
2022-10-30T14:38:46.613600+00:00
2022-10-31T03:41:04.864756+00:00
39
false
# Intuition\nConsider two integers *m* and *n*. If *m* and *n* are in the same congruence class mod *k* (i.e., ```m % k == n % k```), they must have the forms $$m = ak + r$$ and $$n = bk + r$$. Their difference is therefore $$m - n = ak - bk = (a-b)k$$, a multiple of the modulus *k*.\n\nSince our machine destroys targe...
2
0
['Python3']
1
destroy-sequential-targets
JAVA | HashMap | Clean and Simple ✅
java-hashmap-clean-and-simple-by-sourin_-q9pl
Please Upvote :D\nI don\'t know why but I this problem kinda sucks to me.\n\nclass Solution {\n public int destroyTargets(int[] nums, int space) {\n M
sourin_bruh
NORMAL
2022-10-29T19:01:00.062538+00:00
2022-10-29T19:01:00.062576+00:00
178
false
### **Please Upvote** :D\nI don\'t know why but I this problem kinda sucks to me.\n```\nclass Solution {\n public int destroyTargets(int[] nums, int space) {\n Map<Integer, Integer> map = new HashMap<>();\n\n for (int i : nums) {\n int rem = i % space;\n map.put(rem, map.getOrDefa...
2
0
['Java']
0
destroy-sequential-targets
✅✅✅ Detailed explanation C++ solution
detailed-explanation-c-solution-by-kpk13-sm3q
Since we can jump from a nmber a to a number b only by satisfying b=a + c * space, it can be concluded that both b and a have the same remainder when divided by
kpk13
NORMAL
2022-10-29T17:02:51.823874+00:00
2022-10-29T17:02:51.823930+00:00
537
false
Since we can jump from a nmber a to a number b only by satisfying b=a + c * space, it can be concluded that both b and a have the same remainder when divided by space. It is first very intuitive to create a vector of size space in order to have all the remainders as indices in the vector, However, that can exceed memor...
2
0
['C', 'C++']
0
destroy-sequential-targets
C++ with notes and detailed explanation
c-with-notes-and-detailed-explanation-by-tutz
First Intuition\nMy first intuition was find all targets for each nums. As we know targets = nums[i] + c * space which can be written as nums[j] == (nums[j] - n
lucayan0506
NORMAL
2022-10-29T16:31:42.560277+00:00
2022-10-29T17:04:44.215450+00:00
278
false
# First Intuition\nMy first intuition was find all targets for each `nums`. As we know `targets = nums[i] + c * space` which can be written as `nums[j] == (nums[j] - nums[i]) % space` to check if a `nums[j]` is a target `nums[i]` (remember that `c` can\'t be negative which means that `nums[j]` must be greater than `num...
2
0
['C++']
0
destroy-sequential-targets
C++ | map | easy understanding
c-map-easy-understanding-by-pratham7711-ib8c
We can mod all elements by space and the smallest element of the most occuring remainder will be the answer.\n\n\nclass Solution {\npublic:\n int destroyTarg
pratham7711
NORMAL
2022-10-29T16:06:09.939703+00:00
2022-10-29T16:06:09.939753+00:00
171
false
We can mod all elements by space and the smallest element of the most occuring remainder will be the answer.\n\n```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n map<int,pair<int,int>> mp;\n \n for(auto it : nums)\n {\n mp[it%space].first++;\...
2
0
['C++']
0
destroy-sequential-targets
Simple C++ Solution
simple-c-solution-by-shishankrawt93774-t0lw
\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n sort(nums.begin(), nums.end());\n map<int, vector<int> > mp;
shishankrawt93774
NORMAL
2022-10-29T16:04:48.895337+00:00
2022-10-29T16:04:48.895364+00:00
141
false
```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n sort(nums.begin(), nums.end());\n map<int, vector<int> > mp;\n for(int i = 0; i<nums.size(); i++){\n mp[(nums[i]%space)].push_back(nums[i]);\n }\n int mx = 0, mxval = -1;\n for(a...
2
0
['Sorting', 'C++']
0
destroy-sequential-targets
[C++] Hash-map solution with comments | 7 lines O(N)
c-hash-map-solution-with-comments-7-line-glpc
```\nclass Solution {\npublic:\n int destroyTargets(vector& nums, int space) {\n unordered_map freq;\n vector cnt = nums;\n int best = I
t747
NORMAL
2022-10-29T16:00:29.917336+00:00
2022-10-29T16:00:47.061183+00:00
330
false
```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n unordered_map<int, int> freq;\n vector<int> cnt = nums;\n int best = INT_MAX, mx = 0;\n for(auto &i : cnt) i %= space; // we would have to seed i%space in order to access this element\n for(auto i...
2
0
[]
0
destroy-sequential-targets
No Sorting!!! With Explanation!!!
no-sorting-with-explanation-by-jordon-x-h22gt
IntuitionApproachFind most frequent number from reduction nums[i] % space then do another pass to find minimum of those frequent numbersComplexity Time complexi
Jordon-x-Matter
NORMAL
2025-03-31T19:37:56.659970+00:00
2025-03-31T19:37:56.659970+00:00
17
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> A number added by a multiple of space equals another number. Reducing the number by space until it can no longer be reduced. nums: 1, 4, 8, 6; space = 2; -> after reduction, nums: 1, 2, 2, 2. Which operation does this? Modulo Operator. # ...
1
0
['Array', 'Hash Table', 'C++']
1
destroy-sequential-targets
[Python] O(n), O(n) - using remainders (multiples of space)
python-on-on-using-remainders-multiples-vx6dt
Intuition\n Describe your first thoughts on how to solve this problem. \nSame logic from: 1010. Pairs of Songs With Total Durations Divisible by 60\n# Approach\
leeeeeeeeetcode
NORMAL
2023-10-05T20:40:25.724234+00:00
2023-10-05T20:40:25.724254+00:00
2
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSame logic from: 1010. Pairs of Songs With Total Durations Divisible by 60\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFinding complements using remainders\n# Complexity\n- Time complexity:\n<!-- Add your time co...
1
0
['Python3']
0
destroy-sequential-targets
Simple Linear solution O(N) || C++
simple-linear-solution-on-c-by-rkkumar42-ucjt
Complexity\n- Time complexity: O(NLogN)\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
rkkumar421
NORMAL
2023-06-23T08:15:55.476962+00:00
2023-11-23T16:31:15.657302+00:00
16
false
# Complexity\n- Time complexity: O(NLogN)\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 int destroyTargets(vector<int>& nums, int space) {\n int ans = 0,mxl = 0;\n so...
1
0
['Hash Table', 'C++']
1
destroy-sequential-targets
using hash map to store all modulos
using-hash-map-to-store-all-modulos-by-u-rfs4
\n\n# Complexity\n- Time complexity:\no(N)\n\n- Space complexity:\n- o(N)\n Add your space complexity here, e.g. O(n) \n\n# Code\n\nclass Solution {\npublic:\n
user3699Tu
NORMAL
2023-05-29T10:17:13.619675+00:00
2023-05-29T10:17:13.619713+00:00
20
false
\n\n# Complexity\n- Time complexity:\no(N)\n\n- Space complexity:\n- o(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n unordered_map<int,int>m;\n \n for(auto e:nums)\n {\n m[e%sp...
1
0
['C++']
0
destroy-sequential-targets
Kotlin (sort + map)
kotlin-sort-map-by-c4tdog-5gha
Code\n\nclass Solution {\n fun destroyTargets(a: IntArray, s: Int): Int {\n a.sort()\n var m = mutableMapOf<Int, Int>()\n for (i in 0..a
c4tdog
NORMAL
2022-11-27T06:31:44.072086+00:00
2022-11-27T06:31:44.072135+00:00
25
false
# Code\n```\nclass Solution {\n fun destroyTargets(a: IntArray, s: Int): Int {\n a.sort()\n var m = mutableMapOf<Int, Int>()\n for (i in 0..a.size - 1) {\n var mod = a[i] % s\n m[mod] = (m[mod] ?: 0) + 1\n }\n var k = 0\n var maxValue = 0\n for (...
1
0
['Hash Table', 'Sorting', 'Kotlin']
0
destroy-sequential-targets
Java Solution
java-solution-by-prince077-mi2q
\npublic int destroyTargets(int[] nums, int space) {\n int val = Integer.MIN_VALUE;\n int num = Integer.MAX_VALUE;\n HashMap<Integer,Intege
prince077
NORMAL
2022-10-30T12:39:33.222840+00:00
2022-10-30T12:39:33.222872+00:00
33
false
```\npublic int destroyTargets(int[] nums, int space) {\n int val = Integer.MIN_VALUE;\n int num = Integer.MAX_VALUE;\n HashMap<Integer,Integer> hm = new HashMap<>();\n for(int a : nums){\n hm.put(a%space,hm.getOrDefault(a%space,0)+1);\n }\n for(int a : nums){\n if(...
1
0
[]
0
destroy-sequential-targets
✅✅✅ Python Solution using HashMap and Modulo with explanation
python-solution-using-hashmap-and-modulo-8izm
Problem:\nWe need to find an element in the given list nums[i] where maximum number of elements in the array could be represented as nums[i]+c * space .\n\n# In
gpavanik
NORMAL
2022-10-29T23:07:00.375853+00:00
2022-10-29T23:51:35.079263+00:00
294
false
# **Problem:**\nWe need to find an element in the given list nums[i] where maximum number of elements in the array could be represented as nums[i]+c * space .\n\n# **Intuition and Solution Explanation :** \n\n* The modulo of (nums[i] + c * space ) with space i.e., (nums[i] + c * space )%space will be equal to module of...
1
0
['Python']
0