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
destroy-sequential-targets
C++ || Using unordered_map || modulo
c-using-unordered_map-modulo-by-bharat_b-0sij
\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n \n unordered_map<int,int>mp,mp1;\n \n sort(num
bharat_bardiya
NORMAL
2022-10-29T17:50:46.069191+00:00
2022-10-29T18:11:10.299808+00:00
44
false
```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n \n unordered_map<int,int>mp,mp1;\n \n sort(nums.begin(), nums.end());\n \n for(int x : nums){\n if(mp.find(x%space)==mp.end()){\n mp1[x%space] = x;\n }\...
1
0
['C']
0
destroy-sequential-targets
C++ simple Code with explanation(Hashing)
c-simple-code-with-explanationhashing-by-qx8j
Take two map and store the modular in first map with its frequency and after that check what is the frequency of the maximum modulo from the first map\nusing th
awesoME_15
NORMAL
2022-10-29T16:56:54.885380+00:00
2022-10-29T16:56:54.885416+00:00
18
false
Take two map and store the modular in first map with its frequency and after that check what is the frequency of the maximum modulo from the first map\nusing the second map.Check the corresponding modulo with the minimum value and return the ans.\n\n**C++ code** :\n\n int destroyTargets(vector<int>& nums, int space)...
1
0
['C']
0
destroy-sequential-targets
Java || Easy to understand || Clean code
java-easy-to-understand-clean-code-by-ag-u06b
\nclass Solution {\n \n // nums[i] + c * space = nums[j] ==> remainder + quotient * divisor = dividend,\n\t// you had to find the remainder \n // sort
agarwalaarrav
NORMAL
2022-10-29T16:32:52.667158+00:00
2022-10-29T17:20:07.691055+00:00
258
false
```\nclass Solution {\n \n // nums[i] + c * space = nums[j] ==> remainder + quotient * divisor = dividend,\n\t// you had to find the remainder \n // sort the array, so to find first minimum occurence\n public int destroyTargets(int[] nums, int space) {\n int n = nums.length;\n Arrays.sort( num...
1
0
[]
0
destroy-sequential-targets
[C++] | A.P | O(nlogn) time | O(n) space
c-ap-onlogn-time-on-space-by-muheshkumar-e8d2
Intuition\n Notice that the term nums[i] + c * space represents a general term of an A.P(Arithmetic Progression) with first element as nums[i] and common differ
muheshkumar
NORMAL
2022-10-29T16:24:13.589101+00:00
2022-10-29T16:24:13.589143+00:00
456
false
**Intuition**\n* Notice that the term nums[i] + c * space represents a general term of an A.P(Arithmetic Progression) with first element as nums[i] and common difference as space\n* Now, the problem just reduces to finding the first term of the longest A.P(not necessarily consecutive terms) which is present in the give...
1
0
['C++']
0
destroy-sequential-targets
Short & Concise | C++
short-concise-c-by-tusharbhart-53mp
\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n unordered_map<int, int> m;\n for(int i : nums) m[i % space]+
TusharBhart
NORMAL
2022-10-29T16:09:48.076067+00:00
2022-10-29T16:09:48.076115+00:00
392
false
```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n unordered_map<int, int> m;\n for(int i : nums) m[i % space]++;\n \n vector<pair<int, int>> v;\n for(auto i : m) v.push_back({i.second, i.first});\n \n sort(v.begin(), v.end(), greate...
1
0
['Math', 'Sorting', 'C++']
0
destroy-sequential-targets
C++ map | Three line solution
c-map-three-line-solution-by-__abcd-utav
\nclass Solution {\npublic:\n int destroyTargets(vector<int>& arr, int space,int mn = INT_MAX,int mx = -1,map<int,int>mp = {}) {\n for(auto ele:ar
__Abcd__
NORMAL
2022-10-29T16:06:46.873556+00:00
2022-10-29T16:06:46.873595+00:00
103
false
```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& arr, int space,int mn = INT_MAX,int mx = -1,map<int,int>mp = {}) {\n for(auto ele:arr)mp[ele%space]++,mx = max(mx,mp[ele%space]);\n for(auto ele:arr)if(mp[ele%space] == mx) mn = min(mn,ele);\n return(mn); \n...
1
0
[]
2
destroy-sequential-targets
Java using reminder
java-using-reminder-by-mi1-qxr1
\nclass Solution {\npublic int destroyTargets(int[] nums, int space) {\n Map<Integer, List<Integer>> map = new HashMap<>();\n int ans = Integer.MA
mi1
NORMAL
2022-10-29T16:03:01.155320+00:00
2022-10-29T16:03:01.155361+00:00
72
false
```\nclass Solution {\npublic int destroyTargets(int[] nums, int space) {\n Map<Integer, List<Integer>> map = new HashMap<>();\n int ans = Integer.MAX_VALUE;\n for (int num : nums) {\n map.putIfAbsent(num % space, new ArrayList<>());\n map.get(num % space).add(num);\n }...
1
0
[]
0
destroy-sequential-targets
Two Hashmaps
two-hashmaps-by-wanderer_00-c8u8
Sort the array in non decreasing order. Count the frequency of (target MOD space) using a hashmap. If the key is absent, map it to the target in another hashmap
WandereR_00
NORMAL
2022-10-29T16:03:00.509979+00:00
2022-10-29T16:03:00.510021+00:00
289
false
Sort the array in non decreasing order. Count the frequency of `(target MOD space)` using a hashmap. If the key is absent, map it to the target in another hashmap (This is the smallest seed value)\n```\nclass Solution\n{\n public int destroyTargets(int[] nums, int space)\n {\n Arrays.sort(nums);\n M...
1
0
['Java']
0
destroy-sequential-targets
Simple Java Solution
simple-java-solution-by-sakshikishore-7pcu
Code
sakshikishore
NORMAL
2025-03-21T10:02:32.580259+00:00
2025-03-21T10:02:32.580259+00:00
4
false
# Code ```java [] class Solution { public int destroyTargets(int[] nums, int space) { Arrays.sort(nums); int max=0; HashMap<Integer,Integer> h=new HashMap<Integer,Integer>(); for(int i=0;i<nums.length;i++) { int p=nums[i]%space; if(!h.containsKey(p)) ...
0
0
['Java']
0
destroy-sequential-targets
(72ms) HashMap<Int, Pair<Int, Int>>()
72ms-hashmapint-pairint-int-by-sav200119-zjmv
ApproachHashMap<Int, Pair<Int, Int>>()ComplexityCode
sav20011962
NORMAL
2025-02-14T08:43:47.979195+00:00
2025-02-14T08:43:47.979195+00:00
3
false
# Approach HashMap<Int, Pair<Int, Int>>() # Complexity ![image.png](https://assets.leetcode.com/users/images/097b4f3f-d934-4b8a-84c6-e0b53cb7f30a_1739522606.7031102.png) # Code ```kotlin [] class Solution { fun destroyTargets(nums: IntArray, space: Int): Int { val map = HashMap<Int, Pair<Int, Int>>() ...
0
0
['Kotlin']
0
destroy-sequential-targets
2453. Destroy Sequential Targets
2453-destroy-sequential-targets-by-g8xd0-d8be
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-18T15:54:40.359181+00:00
2025-01-18T15:54:40.359181+00:00
7
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 `...
0
0
['C++']
0
destroy-sequential-targets
Python Code
python-code-by-amirmazaheri-9tuk
IntuitionApproachGet the remainer of each num with space, and keep a list per remainder. Return the minimum of the longest list.Complexity Time complexity: O(n
amirmazaheri
NORMAL
2024-12-29T23:14:03.801038+00:00
2024-12-29T23:14:03.801038+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Hash by space modulation -- Python code # Approach <!-- Describe your approach to solving the problem. --> Get the remainer of each num with space, and keep a list per remainder. Return the minimum of the longest list. # Complexity - Time...
0
0
['Python']
0
destroy-sequential-targets
hashmap
hashmap-by-kai_xd-dft3
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
Kai_XD
NORMAL
2024-10-27T06:22:40.234245+00:00
2024-10-27T06:22:40.234284+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
['Python3']
0
destroy-sequential-targets
Java simple solution. (hashmap)
java-simple-solution-hashmap-by-meatymon-a82a
Intuition \n\n\nSince the distance is in multiples of space, we can mod every number by space to group them together.\n\nIf nums = [1,3,5,2,4,6] and space = 2\n
meatymonken
NORMAL
2024-10-02T16:29:36.083962+00:00
2024-10-02T16:38:30.279163+00:00
6
false
# Intuition \n\n\nSince the distance is in multiples of `space`, we can mod every number by `space` to group them together.\n\nIf nums = `[1,3,5,2,4,6]` and space = 2\nthe resulting modulus by 2 is `[1,1,1,0,0,0]`.\n\nIf we were to pick `1`, three targets goes down. and if we were to pick `0` also three targets goes do...
0
0
['Java']
0
destroy-sequential-targets
C++ GRANDMASTER LEGENDARY SOLUTION EASY TO UNDERSTAND FOR ALL :)
c-grandmaster-legendary-solution-easy-to-y6cl
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
Half-Dimension
NORMAL
2024-10-01T14:04:50.362962+00:00
2024-10-01T14:04:50.362987+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
destroy-sequential-targets
C++ | Counting n Sorting
c-counting-n-sorting-by-kena7-7ygu
\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) \n {\n sort(nums.begin(),nums.end());\n unordered_map<int,int
kenA7
NORMAL
2024-09-11T14:34:08.535997+00:00
2024-09-11T14:34:08.536031+00:00
1
false
```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) \n {\n sort(nums.begin(),nums.end());\n unordered_map<int,int>m;\n for(auto &x:nums)\n m[x%space]++;\n int mx=-1,res=-1;\n for(auto &x:nums)\n {\n int r=x%space;\n ...
0
0
[]
0
destroy-sequential-targets
Common Logic
common-logic-by-shaanpatel9889-sthi
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
shaanpatel9889
NORMAL
2024-08-06T11:38:40.377598+00:00
2024-08-06T11:38:40.377627+00:00
5
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
destroy-sequential-targets
Destroy Sequential Targets | Sorting | MOD | Easy C++
destroy-sequential-targets-sorting-mod-e-eyav
\n# 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) \
JeetuGupta
NORMAL
2024-08-01T19:21:48.410989+00:00
2024-08-01T19:21:48.411020+00:00
1
false
\n# 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 sort(nums.begin(), nums...
0
0
['C++']
0
destroy-sequential-targets
JAVA
java-by-manu-bharadwaj-bn-mtfa
Code\n\nclass Solution {\n public int destroyTargets(int[] nums, int space) {\n int n = nums.length;\n HashMap<Integer, Integer> map = new Hash
Manu-Bharadwaj-BN
NORMAL
2024-07-17T12:22:13.603174+00:00
2024-07-17T12:22:13.603197+00:00
1
false
# Code\n```\nclass Solution {\n public int destroyTargets(int[] nums, int space) {\n int n = nums.length;\n HashMap<Integer, Integer> map = new HashMap<>();\n for (int num : nums) {\n num = num % space;\n map.put(num, map.getOrDefault(num, 0) + 1);\n }\n int m...
0
0
['Java']
0
destroy-sequential-targets
O(n) time complexity | C++ | Clean code
on-time-complexity-c-clean-code-by-prana-d26v
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires us to determine the minimum value of nums[i] such that when used t
pranay_battu
NORMAL
2024-06-30T07:38:12.671178+00:00
2024-06-30T07:38:12.671209+00:00
7
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires us to determine the minimum value of `nums[i]` such that when used to seed the machine, it destroys the maximum number of targets. My initial thought was to consider the remainders when each element in `nums` is divid...
0
0
['Hash Table', 'Math', 'C++']
0
destroy-sequential-targets
HINDI Solution.
hindi-solution-by-aman_kr_1810-5msz
\n# Approach\nAgar tumhe english solutions samajhne me issue ho raha hai to isko padho samajh jaaoge.\n\n\n\n# Code\n\n// Acha conceptual question hai.\n/*\n
aman_kr_1810
NORMAL
2024-06-16T12:39:44.676917+00:00
2024-06-16T12:39:44.676940+00:00
4
false
\n# Approach\n**Agar tumhe english solutions samajhne me issue ho raha hai to isko padho samajh jaaoge.**\n\n\n\n# Code\n```\n// Acha conceptual question hai.\n/*\n Question mein bol kya raha hai :-\n Koi ek value daal denge gun me aur wo khud ko aur space ke saath apne saare multiple ko delete kar dege.\n Hum...
0
0
['Array', 'Hash Table', 'Sorting', 'Counting', 'C++']
0
destroy-sequential-targets
Mod by space - Java - O(N) | O(Space)
mod-by-space-java-on-ospace-by-wangcai20-i5ey
Intuition\n Describe your first thoughts on how to solve this problem. \nCount the result of each numbers % space. The highest count is the one we want to feed
wangcai20
NORMAL
2024-05-08T18:45:11.688598+00:00
2024-05-08T19:43:50.822928+00:00
11
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCount the result of each `numbers % space`. The highest count is the one we want to feed to machine cause it destroys the most. Pay attention to corner cases that there might be multiple same highest count, need to pick the smallest among...
0
0
['Java']
0
destroy-sequential-targets
C++ | O(N)
c-on-by-shubhamchandra01-8u8e
Intuition\n Describe your first thoughts on how to solve this problem. \n\nWe are tempted to try remainder / mod operation on each number.\n\nIf two numbers sha
shubhamchandra01
NORMAL
2024-04-17T17:08:13.056834+00:00
2024-04-17T17:08:13.056866+00:00
2
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nWe are tempted to try remainder / mod operation on each number.\n\nIf two numbers share the same remainder when divided by `space`, bigger no. will always be `small + k * space`\n\n```\n// a and b share same remainder r\n\na = r + q1 * ...
0
0
['C++']
0
destroy-sequential-targets
C++
c-by-preetsahil289-idnt
\n# Approach\n(b-a)%space=0\n\n# Complexity\n- Time complexity:\n- best and average case =>O(2*nums.size())\n\n- Space complexity:\nO(n)\n\n# Code\n\nclass Solu
preetsahil289
NORMAL
2024-04-06T10:55:10.072765+00:00
2024-04-06T10:55:10.072783+00:00
0
false
\n# Approach\n(b-a)%space=0\n\n# Complexity\n- Time complexity:\n- best and average case =>O(2*nums.size())\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n\n\n int destroyTargets(vector<int>& nums, int space) {\n unordered_map<int,int> mpp;\n int high=0;\n for(int i=0;i<...
0
0
['C++']
0
destroy-sequential-targets
21ms beats 100% Rust Solution
21ms-beats-100-rust-solution-by-esmail_2-fz9y
Code\n\nuse::std::collections::HashMap;\n\nimpl Solution {\n pub fn destroy_targets(nums: Vec<i32>, space: i32) -> i32 {\n let mut map: HashMap<i32, (
Esmail_2
NORMAL
2024-04-03T19:40:04.919957+00:00
2024-04-03T19:40:04.919996+00:00
3
false
# Code\n```\nuse::std::collections::HashMap;\n\nimpl Solution {\n pub fn destroy_targets(nums: Vec<i32>, space: i32) -> i32 {\n let mut map: HashMap<i32, (i32, i32)> = HashMap::new();\n let (mut res, mut size): (i32, i32) = (0, 0);\n for value in nums.into_iter() {\n map.entry(value %...
0
0
['Rust']
0
destroy-sequential-targets
Simple python3 solution | Sorting + Greedy + Hash Map
simple-python3-solution-sorting-greedy-h-n8nx
Complexity\n- Time complexity: O(n \cdot \log(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.
tigprog
NORMAL
2024-03-27T11:47:29.527256+00:00
2024-03-27T11:47:29.527287+00:00
7
false
# Complexity\n- Time complexity: $$O(n \\cdot \\log(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 destroyTargets(self, nums: List[int], space: int) -> int:\n ...
0
0
['Hash Table', 'Greedy', 'Sorting', 'Counting', 'Python3']
0
destroy-sequential-targets
100% results of space and time beat!
100-results-of-space-and-time-beat-by-ki-oojy
Approach\n- Keep count of all the elements\' modulo results\n- get the max values of the counted results\n- Filter through the number vector and find the minimu
kirubelmidru
NORMAL
2024-03-24T08:27:00.555892+00:00
2024-03-24T08:27:00.555925+00:00
6
false
# Approach\n- Keep count of all the elements\' modulo results\n- get the max values of the counted results\n- Filter through the number vector and find the minimum element that is part of the maximum modulo result\n\n# Complexity\n- Time complexity:\nO(n)\n- Space complexity:\nO(n)\n\n# Code\n```\nuse std::collections:...
0
0
['Array', 'Hash Table', 'Counting', 'Rust']
0
destroy-sequential-targets
ok ^^
ok-by-andrii_khlevniuk-m9ag
\nint destroyTargets(vector<int>& n, int s)\n{\n\tunordered_map<int,int> N,m;\n\tint iM{INT_MAX};\n\tfor(const auto & n : n)\n\t{\n\t\t++N[n%s];\n\t\tm[n%s] = m
andrii_khlevniuk
NORMAL
2024-02-06T15:32:33.200914+00:00
2024-02-06T15:32:33.200947+00:00
1
false
```\nint destroyTargets(vector<int>& n, int s)\n{\n\tunordered_map<int,int> N,m;\n\tint iM{INT_MAX};\n\tfor(const auto & n : n)\n\t{\n\t\t++N[n%s];\n\t\tm[n%s] = m.count(n%s) ? min(m[n%s],n) : n;\n\n\t\tif(N[n%s]>N[iM%s])\n\t\t\tiM = m[n%s];\n\t\telse if(N[n%s]==N[iM%s])\n\t\t\tiM = min(iM, m[n%s]);\n\t}\n\treturn iM;\...
0
0
['C', 'C++']
0
destroy-sequential-targets
Beats 88.95% of users with Python3
beats-8895-of-users-with-python3-by-st20-x9ny
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
st20080675
NORMAL
2024-02-05T02:55:49.800843+00:00
2024-02-05T02:55:49.800872+00:00
5
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
destroy-sequential-targets
cpp easy explanation
cpp-easy-explanation-by-abhi_bittu2525-qq9r
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_bittu2525
NORMAL
2024-01-18T13:07:13.805317+00:00
2024-01-18T13:07:13.805350+00:00
2
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
destroy-sequential-targets
scala solution
scala-solution-by-vititov-108q
\n\nobject Solution {\n def destroyTargets(nums: Array[Int], space: Int): Int = {\n lazy val list = nums.toList.map(x => x -> x % space).groupMap(_._2)(_._1
vititov
NORMAL
2024-01-08T16:08:15.306170+00:00
2024-01-08T16:08:15.306201+00:00
7
false
\n```\nobject Solution {\n def destroyTargets(nums: Array[Int], space: Int): Int = {\n lazy val list = nums.toList.map(x => x -> x % space).groupMap(_._2)(_._1).values.toList\n lazy val mxSize = list.maxBy(_.size).size\n list.filter(_.size == mxSize).flatten.min\n }\n}\n```
0
0
['Scala']
0
destroy-sequential-targets
Easy C++ Solution | Sorting
easy-c-solution-sorting-by-sakshamchhimw-rpto
Intuition\nThis problem demands the following equation to be satisfied\n$\frac{(nums[i]-nums[j])}{space} \in Integer$.\n\n> Proof\n\n\because \frac{(nums[i]-num
sakshamchhimwal2410
NORMAL
2024-01-07T11:03:57.902341+00:00
2024-01-07T11:03:57.902375+00:00
4
false
# Intuition\nThis problem demands the following equation to be satisfied\n$\\frac{(nums[i]-nums[j])}{space} \\in Integer$.\n\n> Proof\n$$\n\\because \\frac{(nums[i]-nums[j])}{space} \\in Integer \\\\\n\\implies (\\space nums[i]-nums[j]\\space )\\%space = 0 \\\\\n\\implies (\\space nums[i]\\%space - nums[j]\\%space \\sp...
0
0
['C++']
0
destroy-sequential-targets
O(n) Common Reminder Approach
on-common-reminder-approach-by-abhishekm-j8os
Intuition\nIf, nums[j]%space = nums[i]%space\nThen, nums[j] = nums[i] + c * space,\n\n Describe your first thoughts on how to solve this problem. \n\n# Approach
abhishekmen
NORMAL
2024-01-03T04:43:56.674579+00:00
2024-01-03T04:43:56.674615+00:00
2
false
# Intuition\nIf, nums[j]%space = nums[i]%space\nThen, nums[j] = nums[i] + c * space,\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nunordered_map<int,pair<int, int>> mp;\n\n- mp.first = nums[i]%space\n- mp.second.first = no.of nums[i] \n - whose nums[i]%space=mp.first\n- mp.sec...
0
0
['C++']
0
destroy-sequential-targets
Python, use a Counter (almost always)
python-use-a-counter-almost-always-by-ma-lnkq
Intuition\n Describe your first thoughts on how to solve this problem. \nAs the hint suggests, the first step is to calculate for all nums[i] the value nums[i]
markalavin
NORMAL
2024-01-01T14:12:30.607612+00:00
2024-01-01T14:12:30.607644+00:00
5
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs the hint suggests, the first step is to calculate for all ```nums[i]``` the value ```nums[i] % space```; let\'s refer to this as ```mod_num[i]```. It turns out that ```nums``` that go into the same "kill group" (the subset of ```nums`...
0
0
['Python3']
0
destroy-sequential-targets
C++ Easy Solution
c-easy-solution-by-md_aziz_ali-4u7q
Code\n\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n int ans = 0;\n int count = 0;\n unordered_map<i
Md_Aziz_Ali
NORMAL
2023-12-20T09:33:22.394621+00:00
2023-12-20T09:33:22.394682+00:00
2
false
# Code\n```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n int ans = 0;\n int count = 0;\n unordered_map<int,pair<int,int>> mp;\n for(int i = 0;i < nums.size();i++) {\n int k = nums[i]%space;\n if(mp[k].first == 0) \n ...
0
0
['Hash Table', 'C++']
0
destroy-sequential-targets
Python | HashMap Solution| O(n)
python-hashmap-solution-on-by-pandeypriy-1377
Intuition\n Describe your first thoughts on how to solve this problem. \nKeeping track of remainders is the key to this problem.\n\n# Approach\n Describe your a
pandeypriyesh184
NORMAL
2023-12-17T02:06:40.512685+00:00
2023-12-17T02:06:40.512702+00:00
7
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nKeeping track of remainders is the key to this problem.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nProblem can be divided into following cases:\n1. len(nums) == 1: only 1 value then return it as seed value\n2....
0
0
['Hash Table', 'Python3']
0
destroy-sequential-targets
Destroy Sequential Targets
destroy-sequential-targets-by-ananytomar-s0bz
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
ananytomar01
NORMAL
2023-12-04T18:56:37.900602+00:00
2023-12-04T18:56:37.900629+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
destroy-sequential-targets
Count maximum frequency of (nums[i] % space) || INTUITION Explained
count-maximum-frequency-of-numsi-space-i-w0zl
Intuition\n\nIf we select nums[i] as a seed, \nthan all nums[index] will get destroyed given\n"nums[index] = nums[i] + c * space"\non performing "modulo space"
coder_rastogi_21
NORMAL
2023-12-02T11:29:38.281084+00:00
2023-12-02T11:29:38.281107+00:00
2
false
# Intuition\n```\nIf we select nums[i] as a seed, \nthan all nums[index] will get destroyed given\n"nums[index] = nums[i] + c * space"\non performing "modulo space" on both sides\nnums[index] % space = (nums[i] + c * space) % space\nnums[index] % space = nums[i] % space\nThus, they both have same remainders.\n//-------...
0
0
['Hash Table', 'C++']
0
destroy-sequential-targets
Clever
clever-by-user3043sb-dzqg
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
user3043SB
NORMAL
2023-11-29T08:19:11.804370+00:00
2023-11-29T08:19:11.804398+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
['Java']
0
destroy-sequential-targets
O(n) time complexity solution
on-time-complexity-solution-by-tus_tus-fych
Intuition\n Describe your first thoughts on how to solve this problem. \n\nWe need to find the remainder of each value with space.\n\nNow, we need to find that
Tus_Tus
NORMAL
2023-11-23T16:32:02.898786+00:00
2023-11-23T16:32:02.898815+00:00
2
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nWe need to find the remainder of each value with space.\n\nNow, we need to find that minimum number whose remainder\'s frequency is maximum . \n\n# Code\n```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int spac...
0
0
['C++']
0
destroy-sequential-targets
One Pass O(n) C# Solution
one-pass-on-c-solution-by-mark0960-xlf2
Intuition\nWe will need to use modulo (%) to determine whict targets get destroyed in the same seed.\n\n# Approach\n1. Dictionary<modulo, (min, count)> will sto
Mark0960
NORMAL
2023-10-21T09:46:25.035792+00:00
2023-10-21T09:46:25.035819+00:00
7
false
# Intuition\nWe will need to use modulo (%) to determine whict targets get destroyed in the same seed.\n\n# Approach\n1. `Dictionary<modulo, (min, count)>` will store each modulo and its occurrences and minimum num.\n2. Iterate nums and get modulo of each num.\n3. Update count and minimum num per modulo in the Dictiona...
0
0
['C#']
0
destroy-sequential-targets
Ruby solution using Modulo
ruby-solution-using-modulo-by-ksodha93-t6vh
Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n) -> O(nlogn) because sorting\n\n- Space complexity:\n Add your space complexity
ksodha93
NORMAL
2023-10-02T20:10:00.979991+00:00
2023-10-02T20:10:00.980017+00:00
2
false
# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n) -> O(nlogn) because sorting\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n# Code\n```\n# @param {Integer[]} nums\n# @param {Integer} space\n# @return {Integer}\ndef destroy_targets(num...
0
0
['Ruby']
0
destroy-sequential-targets
Brute to best : A smooth shift towards best solution - Explanation with full Intuition.
brute-to-best-a-smooth-shift-towards-bes-zt77
2453. Destroy Sequential Targets\n\n## Brute Force Approach :-\n- So try to use every ele as seed and keep count of how many ele has been destroied with that se
hiimvikash
NORMAL
2023-09-19T19:13:39.533866+00:00
2023-09-19T19:13:39.533898+00:00
11
false
# [2453. Destroy Sequential Targets](https://leetcode.com/problems/destroy-sequential-targets/description/)\n\n## Brute Force Approach :-\n- So try to use every ele as seed and keep count of how many ele has been destroied with that seed and keep track of ur minimum seed which destroied maximum ele in nums[].\n![image....
0
0
['Java']
0
destroy-sequential-targets
Python beats 100% using hashmap and modulos
python-beats-100-using-hashmap-and-modul-dcxz
Intuition\n Describe your first thoughts on how to solve this problem. \nIt all boils down to see what is the modulo of space that appears the most time.\n\n# A
poss03
NORMAL
2023-09-18T08:29:58.954573+00:00
2023-09-18T08:29:58.954600+00:00
4
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt all boils down to see what is the modulo of `space` that appears the most time.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFor each number, compute the modulo of it, and update the dictionary, then you know...
0
0
['Python3']
0
destroy-sequential-targets
Python Solution Using modulo in O(n) and O(n)
python-solution-using-modulo-in-on-and-o-mdi1
Code\n\nclass Solution:\n def destroyTargets(self, nums: List[int], space: int) -> int:\n d={}\n for item in nums:\n r=item%space\n
ng2203
NORMAL
2023-09-06T17:13:34.921152+00:00
2023-09-06T17:13:34.921172+00:00
2
false
# Code\n```\nclass Solution:\n def destroyTargets(self, nums: List[int], space: int) -> int:\n d={}\n for item in nums:\n r=item%space\n if(r in d):\n d[r]+=1\n else:\n d[r]=1\n ans=nums[0]\n c=d[ans%space]\n for item i...
0
0
['Python3']
0
destroy-sequential-targets
✅✅C++ Simple solution || Unordered_map || Explanation || O(n).
c-simple-solution-unordered_map-explanat-xm8r
EXPLANATION\nAt first we created an unordered_map.\nWe traverse in the given vector nums.\nWe checked if the mod of that number with space is in map or not, the
praegag
NORMAL
2023-09-03T06:53:12.398686+00:00
2023-09-03T06:53:12.398713+00:00
6
false
# EXPLANATION\nAt first we created an unordered_map.\nWe traverse in the given vector **nums**.\nWe checked if the mod of that number with **space** is in map or not, then we insert in it, or if present then we update it with **increased count and min number, as a pair**.\nSet **s=-1 and ans=INT_MAX.**\nAfter this we t...
0
0
['Array', 'Hash Table', 'Counting', 'C++']
0
destroy-sequential-targets
Easy || Based on remainder intuition
easy-based-on-remainder-intuition-by-g_k-5qlq
Intuition\nstore the remainder of every number when divided by space.\nThe highest number of same remainder will be our answer.\nfor handelling the stiuations w
g_ky
NORMAL
2023-08-31T17:54:20.392810+00:00
2023-08-31T17:54:20.392839+00:00
4
false
# Intuition\nstore the remainder of every number when divided by space.\nThe highest number of same remainder will be our answer.\nfor handelling the stiuations where there is more than one highest then store all those in a set.\n\n\n\n# Complexity\n- Time complexity:\no(n)\n\n- Space complexity:\no(n)\n# Code\n```\ncl...
0
0
['Ordered Map', 'C++']
0
destroy-sequential-targets
Easiest cpp code :) Best from rest
easiest-cpp-code-best-from-rest-by-sanya-uf5j
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
sanyam46
NORMAL
2023-08-26T17:55:20.887917+00:00
2023-08-26T17:55:20.887948+00:00
2
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
destroy-sequential-targets
Easy to Understand Python Solution
easy-to-understand-python-solution-by-sr-g6wi
Intuition\n Describe your first thoughts on how to solve this problem. \nYou can destroy all targets $x$ with seed $y$ with $x \equiv y \left(\mod \text{space}\
srihariv
NORMAL
2023-08-17T01:59:30.427825+00:00
2023-08-17T01:59:30.427848+00:00
2
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nYou can destroy all targets $x$ with seed $y$ with $x \\equiv y \\left(\\mod \\text{space}\\right)$ i.e. with the same modulus.\n\n\n# Complexity\n- Time complexity:\n$$O(n)$$ - Two passes of the list (could be done in one pass too if nee...
0
0
['Python3']
0
destroy-sequential-targets
c++ solution using sort and map
c-solution-using-sort-and-map-by-tiandin-m194
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
tiandingz
NORMAL
2023-08-10T22:12:42.568920+00:00
2023-08-10T22:15:23.428933+00:00
3
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
destroy-sequential-targets
C++ hashing O(n)
c-hashing-on-by-gagapoopoo-y9o9
```\nclass Solution {\npublic:\n int destroyTargets(vector& nums, int space) {\n \n unordered_map,greater\>> ourmap;\n int n=nums.size()
Gagapoopoo
NORMAL
2023-08-02T19:23:03.073139+00:00
2023-08-02T19:23:03.073159+00:00
2
false
```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) {\n \n unordered_map<int,priority_queue<int,vector<int>,greater<int>>> ourmap;\n int n=nums.size();\n for(int i=0;i<n;i++){\n int rem=nums[i]%space;\n ourmap[rem].push(nums[i]);\n ...
0
0
[]
0
destroy-sequential-targets
:: Kotlin :: Sorting Solution
kotlin-sorting-solution-by-znxkznxk1030-t1t0
\nclass Solution {\n fun destroyTargets(nums: IntArray, space: Int): Int {\n val modulo = HashMap<Int, Int>()\n var mod = 0\n\n for (num
znxkznxk1030
NORMAL
2023-08-02T08:09:19.539924+00:00
2023-08-02T08:09:19.539944+00:00
2
false
```\nclass Solution {\n fun destroyTargets(nums: IntArray, space: Int): Int {\n val modulo = HashMap<Int, Int>()\n var mod = 0\n\n for (num in nums) {\n val m = num % space\n modulo.put(m, modulo.getOrDefault(m, 0) + 1)\n }\n\n var max = modulo.values.max()!!\...
0
0
['Kotlin']
0
destroy-sequential-targets
C++ Short | O(N)/O(N) time/space
c-short-onon-timespace-by-skoparov-tzha
All numbers that can be destroyed with a seed share the common modulo. We just need to count them and keep the minimum value for them as well as the overall max
skoparov
NORMAL
2023-07-31T14:47:50.567330+00:00
2023-07-31T14:47:50.567361+00:00
4
false
All numbers that can be destroyed with a seed share the common modulo. We just need to count them and keep the minimum value for them as well as the overall max count/min value.\n```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) \n { \n int maxCnt{ 0 };\n int minVa...
0
0
['C++']
0
destroy-sequential-targets
C++ | Easy to understand approach
c-easy-to-understand-approach-by-khanhtc-ygiv
Intuition\n Describe your first thoughts on how to solve this problem. \nSince num = seed + c * space, numbers will be marked as destroied targets by the same s
khanhtc
NORMAL
2023-07-25T09:30:34.965446+00:00
2023-07-25T09:30:34.965464+00:00
4
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince `num = seed + c * space`, numbers will be marked as destroied targets by the same seed if `num % space` is the same ( = seed ).\n\nWe will count those numbers and return the smallest one as the answer.\n\n# Approach\n<!-- Describe y...
0
0
['Array', 'Hash Table', 'C++']
0
destroy-sequential-targets
C++ Solution using Hashmap and Sorting
c-solution-using-hashmap-and-sorting-by-s81ha
Intuition\n Describe your first thoughts on how to solve this problem. \nCan approach the problem statement with a Mathematical equation and then try to hash th
deaththunder333
NORMAL
2023-07-21T12:17:38.779985+00:00
2023-07-21T12:17:38.780008+00:00
6
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCan approach the problem statement with a Mathematical equation and then try to hash the maxiumum frequency of the desired answer.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIf any number x is representable in...
0
0
['Hash Table', 'Sorting', 'C++']
0
destroy-sequential-targets
🔥🔥Destroy Sequential Targets 🔥🔥With Comments🔥🔥 Easy Approach 🔥🔥 Simple & Fast
destroy-sequential-targets-with-comments-5pzq
\n\n# Code\n\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) \n {\n int ans = INT_MAX;\n int mx = INT_MIN;\n
_sinister_
NORMAL
2023-07-21T06:39:31.160503+00:00
2023-07-21T06:39:31.160533+00:00
3
false
\n\n# Code\n```\nclass Solution {\npublic:\n int destroyTargets(vector<int>& nums, int space) \n {\n int ans = INT_MAX;\n int mx = INT_MIN;\n unordered_map<int, int> mp;\n\n for(auto n: nums)\n {\n int r = n % space; //evaluate reminder\n m...
0
0
['Array', 'Hash Table', 'Counting']
0
destroy-sequential-targets
[JavaScript] Easy Understaning Solution!
javascript-easy-understaning-solution-by-x4my
Code\n\n/**\n * @param {number[]} nums\n * @param {number} space\n * @return {number}\n */\nvar destroyTargets = function(nums, space) {\n nums.sort((a, b) =
nguyennhuhung72
NORMAL
2023-07-17T06:56:21.869979+00:00
2023-07-17T06:56:21.870001+00:00
9
false
# Code\n```\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 let m = new Map(), res = 0, cnt = 0;\n for (let i = 0; i < nums.length; i++){\n if (m.get(nums[i] % space))\n m.set(num...
0
0
['Hash Table', 'JavaScript']
0
length-of-longest-v-shaped-diagonal-segment
[Python] DP
python-dp-by-lee215-gtub
ExplanationDFS with memo. Current position (i, j), the value to search x, where x = 0,1,2 the direction indice d, where direction is [[1,1],[1,-1],[-1,-1],[-1,1
lee215
NORMAL
2025-02-16T04:19:09.755926+00:00
2025-02-16T06:27:57.122333+00:00
1,917
false
# **Explanation** DFS with memo. Current position `(i, j)`, the value to search `x`, where `x = 0,1,2` the direction indice `d`, where direction is `[[1,1],[1,-1],[-1,-1],[-1,1]]` and `k` is the time to turn. # **Complexity** Time and Space `O(m * n * 3 * 4 * 2)` <br> ```py [Python3] def lenOfVDiagonal(self, g: L...
15
0
['Dynamic Programming', 'Depth-First Search', 'Python3']
2
length-of-longest-v-shaped-diagonal-segment
simple DP solution in c++:
simple-dp-solution-in-c-by-vijay_15-bijq
IntuitionApproachComplexity Time complexity: Space complexity: Code
vijay_15
NORMAL
2025-02-16T05:33:55.683373+00:00
2025-02-17T09:16:31.098205+00:00
1,174
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 `...
10
1
['Dynamic Programming', 'C++']
2
length-of-longest-v-shaped-diagonal-segment
Concise Java DFS
concise-java-dfs-by-czahie-kc9z
Code
czahie
NORMAL
2025-02-16T04:25:36.652131+00:00
2025-02-16T04:28:21.012794+00:00
639
false
# Code ```java [] class Solution { int[][] dirs = new int[][]{{-1, 1}, {1, 1}, {1, -1}, {-1, -1}}; int[][] grid; int m, n; public int lenOfVDiagonal(int[][] grid) { m = grid.length; n = grid[0].length; this.grid = grid; int res = 0; for (int i = 0; i < m; i...
6
0
['Depth-First Search', 'Java']
2
length-of-longest-v-shaped-diagonal-segment
It's Not Hard..!
its-not-hard-by-senorita143-49va
IntuitionThe approach uses DFS with memoization to explore "V" shaped paths starting from each 1 in the grid, alternating between 2 and 0 at each step. It recur
senorita143
NORMAL
2025-02-16T06:07:28.472672+00:00
2025-02-16T06:07:28.472672+00:00
377
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> The approach uses DFS with memoization to explore "V" shaped paths starting from each 1 in the grid, alternating between 2 and 0 at each step. It recursively checks all four diagonal directions while ensuring only one turn is made, maximizi...
5
0
['Dynamic Programming', 'Depth-First Search', 'Python3']
0
length-of-longest-v-shaped-diagonal-segment
🔥Using DP Clever Explanation
using-dp-clever-explanation-by-sapilol-xfjp
🚀 Approach: We use 4 DP matrices (a, b, c, d) to track the length of diagonal segments in 4 directions: a: top-left ↖️ bottom-right (↘️) b: top-right ↗️ b
LeadingTheAbyss
NORMAL
2025-02-16T04:14:06.171994+00:00
2025-02-16T15:34:21.400341+00:00
480
false
# 🚀 Approach: - We use 4 DP matrices `(a, b, c, d)` to track the length of diagonal segments in 4 directions: - `a`: top-left ↖️ bottom-right (↘️) - `b`: top-right ↗️ bottom-left (↙️) - `c`: bottom-left ↙️ top-right (↗️) - `d`: bottom-right ↘️ top-left (↖️) - For each cell (if `value ≠ 1`), we extend ...
5
0
['Graph', 'C++']
0
length-of-longest-v-shaped-diagonal-segment
[Python3] dp
python3-dp-by-ye15-tmnw
IntuitionThis is DP problem. Define state space as (i, j, di, dj, turn) where (i, j) is the current location in the grid, (di, dj) represent the direction and t
ye15
NORMAL
2025-02-16T04:01:12.960235+00:00
2025-02-16T04:14:57.914443+00:00
578
false
# Intuition This is DP problem. Define state space as `(i, j, di, dj, turn)` where `(i, j)` is the current location in the grid, `(di, dj)` represent the direction and `turn` is a boolean indicating if a clockwise rotate is allowed. # Approach It is noticed that grid with value 1 can only be followed by 2, 2 can onl...
5
0
['Python3']
1
length-of-longest-v-shaped-diagonal-segment
Super easy recursive + memeo solution. Top Down.
super-easy-recursive-memeo-solution-top-l4rr4
Code
Michael_Teng6
NORMAL
2025-02-16T06:10:10.052803+00:00
2025-02-16T06:10:10.052803+00:00
259
false
# Code ```cpp [] class Solution { public: int m,n; int dp[500][500][2][4]; int dfs(vector<vector<int>>& grid,int row,int col,bool canchange,int dir) { if(row<0||col<0||row==m||col==n||grid[row][col]==1) return 0; if(dp[row][col][canchange][dir]!=-1) return dp[row][col][canchange][dir]...
4
0
['Recursion', 'Memoization', 'C++']
0
length-of-longest-v-shaped-diagonal-segment
[Python] Memoize DP
python-memoize-dp-by-awice-ejmu
Let dp(r, c, dr, dc, expected, turned) be the length of a path starting at (r, c), going in direction (dr, dc), which expects a current value of A[r][c] == expe
awice
NORMAL
2025-02-16T10:58:05.208128+00:00
2025-02-16T10:58:05.208128+00:00
206
false
Let `dp(r, c, dr, dc, expected, turned)` be the length of a path starting at `(r, c)`, going in direction `(dr, dc)`, which expects a current value of `A[r][c] == expected`, and `turned` represents whether we have done a clockwise turn yet. # Code ```python3 [] class Solution: def lenOfVDiagonal(self, A: List[List...
3
0
['Python3']
0
length-of-longest-v-shaped-diagonal-segment
DFS with a Twist: Longest V-Diagonals 🚀🔥
dfs-with-a-twist-longest-v-diagonals-by-efixi
IntuitionStart from each cell with a 1 and explore diagonals in all 4 directions (top-right, top-left, bottom-right, bottom-left). 2. For each direction, use DF
sahil241202
NORMAL
2025-02-17T20:00:12.757987+00:00
2025-02-17T20:01:41.872539+00:00
82
false
# Intuition Start from each cell with a 1 and explore diagonals in all 4 directions (top-right, top-left, bottom-right, bottom-left). 2. For each direction, use DFS to explore valid alternating patterns of 1 → 2 → 0. 3. At each step, check the maximum valid sequence—either continue straight or take one allowed turn to ...
2
0
['Depth-First Search', 'Recursion', 'C++']
1
length-of-longest-v-shaped-diagonal-segment
Brute Force Using BFS
brute-force-using-bfs-by-conganhhcmus-ahdn
Approach Use BFS to compute values starting from each point (i,j) where grid[i][j] = 1, Return the maximum value obtained from all starting points. The maximum
conganhhcmus
NORMAL
2025-02-16T11:35:40.945330+00:00
2025-02-16T11:35:40.945330+00:00
130
false
# Approach - Use BFS to compute values starting from each point `(i,j)` where `grid[i][j] = 1`, - Return the maximum value obtained from all starting points. - The maximum possible answer is `Max(n,m)`. - If there is only one occurrence of this maximum value, return it immediately to optimize performance. # Complexity...
2
0
['Breadth-First Search', 'C#']
0
length-of-longest-v-shaped-diagonal-segment
DP Soln | beats 100%
dp-soln-beats-100-meow-meow-by-drunkencl-2412
IntuitionThis problem involves finding the longest valid 'V' or diagonal path in the grid. We use dynamic programming to efficiently compute diagonal lengths in
drunkencloud9
NORMAL
2025-02-16T05:05:50.141834+00:00
2025-02-16T05:14:11.907408+00:00
212
false
# Intuition This problem involves finding the longest valid 'V' or diagonal path in the grid. We use dynamic programming to efficiently compute diagonal lengths in all four diagonal directions and then combine them. # Approach We use a dp array `dp[i][j][d]` stores the length of the longest valid diagonal path ending ...
2
0
['Dynamic Programming', 'C++']
2
length-of-longest-v-shaped-diagonal-segment
Brute Force | C++
brute-force-c-by-nilay_c-8f5e
store the length of the sequence starting at each 0 and 2 in all four directions, this gives you the additional length you get if you turn to that index. from t
nilay_c
NORMAL
2025-02-16T04:06:12.668637+00:00
2025-02-16T04:09:58.799246+00:00
52
false
store the length of the sequence starting at each 0 and 2 in all four directions, this gives you the additional length you get if you turn to that index. from there, you can simply brute force. from each 1, go in a direction and find what answer you can get if you turn at that point or continue forward. do this for all...
2
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
[Python][DFS+Memoization]Easy to understand code
pythondfsmemoizationeasy-to-understand-c-mdft
IntuitionSimple dfs traversal whenever we spot a 1. DFS parameters are: r:= Current Row c:= Current Column d:= Current direction (see directions array in code,
buggy_d_clown
NORMAL
2025-03-01T09:33:44.717942+00:00
2025-03-01T09:33:44.717942+00:00
42
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Simple dfs traversal whenever we spot a 1. DFS parameters are: r:= Current Row c:= Current Column d:= Current direction (see directions array in code, its ordered in clockwise) hasTurned:= Wether we have turned for the Vertex of our v shape...
1
0
['Python3']
0
length-of-longest-v-shaped-diagonal-segment
Python3 || dfs dp w/ cache || T/S: 90% / 31%
python3-dp-w-cache-ts-90-31-by-spaulding-mpwt
https://leetcode.com/problems/length-of-longest-v-shaped-diagonal-segment/submissions/1558544812/I could be wrong, but I think that time complexity is O(MN) and
Spaulding_
NORMAL
2025-02-28T20:40:48.735648+00:00
2025-02-28T20:42:15.481052+00:00
31
false
```python3 [] class Solution: def lenOfVDiagonal(self, grid: List[List[int]]) -> int: @lru_cache(None) def dfs(row,col, dr,dc, element, hasTurned): if not (0 <= row < m and 0 <= col < n) or grid[row][col] != element: return 0 ans = dfs(r...
1
0
['Python3']
0
length-of-longest-v-shaped-diagonal-segment
Very Clean DP code with memoization
very-clean-dp-code-with-memoization-by-s-5bq3
IntuitionApproachComplexity Time complexity: Space complexity: Code
Shaurya_Malhan
NORMAL
2025-02-17T19:19:24.505714+00:00
2025-02-17T19:19:24.505714+00:00
133
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 `...
1
0
['Java']
0
length-of-longest-v-shaped-diagonal-segment
C++ | DP + Traversal
c-dp-traversal-by-kena7-05in
Code
kenA7
NORMAL
2025-02-17T04:13:57.422683+00:00
2025-02-17T04:13:57.422683+00:00
53
false
# Code ```cpp [] class Solution { public: int dp[501][501][4][2]; int m,n; int dx[4]={1,1,-1,-1}; int dy[4]={-1,1,-1,1}; int clockwise[4]={2,0,3,1}; bool valid(int i,int j) { return !(i<0 || j<0 || i>=m || j>=n); } int find(int i,int j,int dir,int turn,vector<vector<int>>& g)...
1
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
Brute Force using DFS -> Travel all possible paths
brute-force-using-dfs-travel-all-possibl-rivr
IntuitionApproachComplexity Time complexity: Space complexity: Code
got_u
NORMAL
2025-02-16T17:22:40.298684+00:00
2025-02-16T17:22:40.298684+00:00
39
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 `...
1
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
Normal DFS + DP (for optimization)
normal-dfs-dp-for-optimization-by-rthaku-qbmd
IntuitionJust create a dp state which tells the maximum ans from this coordinate upto the end when the status of turn_taken is (used or unused).Code
rthakur2712
NORMAL
2025-02-16T12:38:28.383067+00:00
2025-02-16T12:38:28.383067+00:00
56
false
# Intuition Just create a dp state which tells the maximum ans from this coordinate upto the end when the status of turn_taken is (used or unused). # Code ```cpp [] class Solution { //direction are 1,2,3,4 or 0,1,2,3(preferred) /* directions are 0 1 2 3 */ public: int lenOfVDiagonal(vector...
1
0
['Dynamic Programming', 'Depth-First Search', 'C++']
0
length-of-longest-v-shaped-diagonal-segment
✅✅✅Easy To Understand C++ Code
easy-to-understand-c-code-by-codeblunder-ozn2
IntuitionStart at Every 1: Since every valid segment must start with 1, we only begin our search from cells with a 1.Try Every Diagonal: There are 4 diagonal di
codeblunderer
NORMAL
2025-02-16T08:36:17.613820+00:00
2025-02-16T08:36:17.613820+00:00
94
false
# Intuition Start at Every 1: Since every valid segment must start with 1, we only begin our search from cells with a 1. Try Every Diagonal: There are 4 diagonal directions, so we try all possibilities from each starting point. Follow the Pattern: Using the expected function, we know exactly which number should come ...
1
0
['Depth-First Search', 'C++']
1
length-of-longest-v-shaped-diagonal-segment
Simple & Clear Solution | Intuitive Approach | DP | C++ 🚀
simple-clear-solution-intuitive-approach-mvqk
Approach DFS with Memoization (DP): For each cell with 1, explore all 4 diagonal directions. Track states using row, col, required number (1, 2, 0), direct
vedant115
NORMAL
2025-02-16T08:13:09.823248+00:00
2025-02-16T08:31:43.142676+00:00
54
false
# Approach - DFS with Memoization (DP): - For each cell with 1, explore all 4 diagonal directions. - Track states using row, col, required number (1, 2, 0), direction, and whether a turn has been made. - State Transitions: - Same Direction: Continue in the current direction. - Turn Once: Make a 90-...
1
0
['Dynamic Programming', 'Depth-First Search', 'Memoization', 'C++']
0
length-of-longest-v-shaped-diagonal-segment
easy cpp solution to understand
easy-cpp-solution-to-understand-by-prati-vr28
IntuitionApproachComplexity Time complexity: Space complexity: Code
pratik5722
NORMAL
2025-02-16T06:39:10.405897+00:00
2025-02-16T06:39:10.405897+00:00
27
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 `...
1
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
Recursion (Dp optional for optimization) || O(n.m) || 100 % beat || Must check
recursion-dp-optional-for-optimization-o-n0a5
Complexity Time complexity: O(n.m) Space complexity: O(n.m)Code
Priyanshu_pandey15
NORMAL
2025-02-16T06:34:13.263408+00:00
2025-02-16T06:34:13.263408+00:00
64
false
# Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> $$O(n.m)$$ - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> $$O(n.m)$$ # Code ```java [] class Solution { static public int lenOfVDiagonal(int[][] arr) { int ans = 0, n = arr.length, m = arr[0].l...
1
0
['Dynamic Programming', 'Recursion']
1
length-of-longest-v-shaped-diagonal-segment
Simple recursive solution | turn or no turn
simple-recursive-solution-turn-or-no-tur-1rs2
IntuitionApproachWe will try to do exactly what we are told to. We will start from a cell containing '1', and explore 4 directions diagonally as long as pattern
Abhishek_Jain_18
NORMAL
2025-02-16T04:51:23.485099+00:00
2025-02-22T14:08:11.070178+00:00
56
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> We will try to do exactly what we are told to. We will start from a cell containing '1', and explore 4 directions diagonally as long as pattern is matched and we are allowe...
1
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
|| ✅✅Easiest Solution && DP && #DAY_29th_Of_Daily_Coding🙏🙏 ||
easiest-solution-dp-day_29th_of_daily_co-x3mz
IntuitionApproachComplexity Time complexity: Space complexity: Code
Coding_With_Star
NORMAL
2025-02-16T04:06:05.035467+00:00
2025-02-16T04:06:05.035467+00:00
58
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
1
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
DP keep track of direction and whether turned
dp-keep-track-of-direction-and-whether-t-kbvj
null
theabbie
NORMAL
2025-02-16T04:01:50.359870+00:00
2025-02-16T04:01:50.359870+00:00
130
false
```python3 [] class Solution: def lenOfVDiagonal(self, grid): m = len(grid) n = len(grid[0]) clock = {(1, 1): (1, -1), (1, -1): (-1, -1), (-1, -1): (-1, 1), (-1, 1): (1, 1)} @cache def dp(i, j, dx, dy, done, even): if not (0 <= i < m) or not (0 <= j < n): ...
1
0
['Python3']
1
length-of-longest-v-shaped-diagonal-segment
Java DP solution
java-dp-solution-by-precel332-2d8l
IntuitionMantain dp array with the best score for every state of the sequence (4 direction before rotation and 4 directions after rotation). Perform Depth first
precel332
NORMAL
2025-03-20T17:18:33.692842+00:00
2025-03-20T17:18:33.692842+00:00
15
false
# Intuition Mantain dp array with the best score for every state of the sequence (4 direction before rotation and 4 directions after rotation). Perform Depth first traversal to compute dp array. # Complexity - Time complexity: $$O(n*m)$$ - Space complexity: $$O(n*m)$$ # Code ```java [] class Solution { int[][]...
0
0
['Java']
0
length-of-longest-v-shaped-diagonal-segment
Simple Self-explanatory DP | Beats 100%
simple-self-explanatory-dp-beats-100-by-gzb5e
IntuitionAt every 1, we have 4 choices of directions. And at each further point, we have 2 choices (to continue in same dir or make a turn). This screams for a
pramodhv_28
NORMAL
2025-03-16T08:19:02.828659+00:00
2025-03-16T08:19:02.828659+00:00
14
false
# Intuition At every 1, we have 4 choices of directions. And at each further point, we have 2 choices (to continue in same dir or make a turn). This screams for a dp approach. While the intuition was simple, its quite hard to implement - Hence I feel the LC hard tag is justified. # Approach Dimensions defined - Row, c...
0
0
['Dynamic Programming', 'Memoization', 'Matrix', 'C++']
0
length-of-longest-v-shaped-diagonal-segment
Python || Dynamic Programming || Faster than 94%
python-dynamic-programming-faster-than-9-f4wl
IntuitionApproachComplexity Time complexity: O(n * m) Space complexity: O(n * m)Code
vilaparthibhaskar
NORMAL
2025-03-06T23:23:36.813317+00:00
2025-03-06T23:23:53.077302+00:00
29
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)$$ --> O(n * m) - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> ...
0
0
['Dynamic Programming', 'Matrix', 'Python3']
0
length-of-longest-v-shaped-diagonal-segment
Self-explanatory DP
self-explanatory-dp-by-iofjuupasli-fss6
IntuitionThe first intuition was that it's either DP or just BFS brute force. For DP you have to try to iterate through the data and see if it's possible to get
iofjuupasli
NORMAL
2025-03-06T19:13:55.582328+00:00
2025-03-06T19:13:55.582328+00:00
19
false
# Intuition The first intuition was that it's either DP or just BFS brute force. For DP you have to try to iterate through the data and see if it's possible to get the new solution from already iterated results. BFS is easy to implement, but obviously the solution will be less effective, so I need to disprove the DP so...
0
0
['Dynamic Programming', 'Memoization', 'Matrix', 'TypeScript', 'JavaScript']
0
length-of-longest-v-shaped-diagonal-segment
CPP || Recursion + Memo || 4D DP
cpp-recursion-memo-4d-dp-by-shubham_loha-aatt
Code
shubham_lohan
NORMAL
2025-02-24T18:33:41.070989+00:00
2025-02-24T18:33:41.070989+00:00
8
false
# Code ```cpp [] #include <bits/stdc++.h> using namespace std; class Solution { public: int n, m; int dp[501][501][4][2]; // DP table: [row][col][direction][turn] int dx[4] = {1, 1, -1, -1}; int dy[4] = {1, -1, -1, 1}; bool isValidTurn(int oldDir, int newDir) { return (newDir != oldDir) &...
0
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
DP + Memoization
dp-memoization-by-aadarshkt-5981
IntuitionSearch all the possiblities.ApproachFor every one go in four directions.Complexity Time complexity:O(n^2) Space complexity:O(n^2) Code
aadarshkt
NORMAL
2025-02-23T04:36:25.184626+00:00
2025-02-23T04:36:25.184626+00:00
4
false
# Intuition Search all the possiblities. # Approach For every one go in four directions. # Complexity - Time complexity: O(n^2) - Space complexity: O(n^2) # Code ```cpp [] class Solution { public: bool inrange(int i, int j, int n, int m){ if(i >= 0 && i < n && j >= 0 && j < m)return true; return...
0
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
Rust solution
rust-solution-by-abhineetraj1-qwxm
IntuitionThe problem asks for the longest length of a "V-shaped" diagonal in a given 2D grid, where cells are either 1 (part of a path) or 0 (empty). A "V-shape
abhineetraj1
NORMAL
2025-02-22T03:06:21.395311+00:00
2025-02-22T03:06:37.460079+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> The problem asks for the longest length of a "V-shaped" diagonal in a given 2D grid, where cells are either 1 (part of a path) or 0 (empty). A "V-shaped" diagonal means starting from a 1 cell and moving in one of the four diagonal direction...
0
0
['Dynamic Programming', 'Memoization', 'Matrix', 'Rust']
0
length-of-longest-v-shaped-diagonal-segment
DFS | C++
dfs-c-by-siddharth96shukla-z037
Code
siddharth96shukla
NORMAL
2025-02-20T14:34:53.898756+00:00
2025-02-20T14:34:53.898756+00:00
7
false
# Code ```cpp [] class Solution { public: int m, n; bool chk(int i, int j){ return (i>=0 && j>=0 && i<n && j<m); } int dfs(vector<vector<int>>&A, int ri, int ci, int r, int c, bool ir){ int cv=A[r][c], ret=0; if(cv==2){ if(chk(r+ri, c+ci) && A[r+ri][c+ci]==0)ret=max(...
0
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
C++ | Memoization | Beats 90% | Optimized Recursive Approach
c-memoization-beats-90-optimized-recursi-8s8i
IntuitionThe problem requires finding the longest valid diagonal path in the grid, following specific movement rules. The key observation is that a valid path m
Tarikcr7
NORMAL
2025-02-20T08:40:32.429970+00:00
2025-02-20T08:40:32.429970+00:00
16
false
# Intuition The problem requires finding the longest valid diagonal path in the grid, following specific movement rules. The key observation is that a valid path must start from cells containing `1`, continue through cells containing `2`, and follow diagonal directions. The direction can change under certain conditio...
0
0
['Dynamic Programming', 'Memoization', 'Matrix', 'C++']
0
length-of-longest-v-shaped-diagonal-segment
Easy DP Memoization solution with TC (n*m*4*2)
easy-dp-memoization-solution-with-tc-nm4-vikh
IntuitionApproachComplexity Time complexity: Space complexity: Code
vaibhav11022003
NORMAL
2025-02-20T07:26:34.449554+00:00
2025-02-20T07:26:34.449554+00:00
8
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 `...
0
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
OpenAI solution
openai-solution-by-dawninghu-3y7w
I was just curious whether OpenAI can solve it, I pasted the question, and choose answer with reasoning. Is data structure and algorithm an outdated skill?this
dawninghu
NORMAL
2025-02-20T07:22:40.087173+00:00
2025-02-20T07:22:40.087173+00:00
9
false
I was just curious whether OpenAI can solve it, I pasted the question, and choose answer with reasoning. Is data structure and algorithm an outdated skill? this is what I got: # Code ```cpp [] class Solution { public: int lenOfVDiagonal(vector<vector<int>>& grid) { int n = grid.size(), m = grid[0].size(); ...
0
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
My Solutions
my-solutions-by-hope_ma-qdw0
null
hope_ma
NORMAL
2025-02-18T10:31:31.545999+00:00
2025-02-18T10:31:31.545999+00:00
7
false
``` /** * Time Complexity: O(rows * cols) * Space Complexity: O(rows * cols) * where `rows` is the number of the rows of the matrix `grid` * `cols` is the number of the columns of the matrix `grid` */ class Solution { private: static constexpr int directions[] = {1, 1, -1, -1, 1}; static constexpr int n...
0
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
Brute Force using Memoization DP in C++ || Easy to Understand
brute-force-using-memoization-dp-in-c-ea-efvv
IntuitionApproachComplexity Time complexity: Space complexity: Code
sumitgarg380
NORMAL
2025-02-18T09:40:31.798290+00:00
2025-02-18T09:40:31.798290+00:00
12
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 `...
0
0
['C++']
0
length-of-longest-v-shaped-diagonal-segment
Python Top-Down DP
python-top-down-dp-by-danieljhkim-y7de
Intuitionfor each 1's -> go DFS -> return max distance traveledComplexity Time complexity: O(n∗m) Space complexity: O(n∗m) Code
danieljhkim
NORMAL
2025-02-18T00:53:10.422058+00:00
2025-02-18T00:53:10.422058+00:00
35
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> for each 1's -> go DFS -> return max distance traveled # Complexity - Time complexity: $$O(n * m)$$ <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: $$O(n * m)$$ <!-- Add your space complexity here, e.g. $$O(n)$$...
0
0
['Dynamic Programming', 'Memoization', 'Python3']
0
length-of-longest-v-shaped-diagonal-segment
DP (n x m x 4 states) | No Memorization | 111ms | Beats 100%
dp-no-memorization-111ms-beats-100-by-xp-hreh
IntuitionDP: Let f(x,y,d) denote the largest length after the turn, where x,y are the coordinates, d is the direction, and x∈[0..n), y∈[0..m), d∈[0..3].Approach
xpycc
NORMAL
2025-02-17T20:23:14.891385+00:00
2025-02-17T21:41:58.940956+00:00
20
false
# Intuition DP: Let $$f(x, y, d)$$ denote the largest length after the turn, where $$x, y$$ are the coordinates, $$d$$ is the direction, and $$x \in [0..n)$$, $$y \in [0..m)$$, $$d \in [0..3]$$. # Approach We solve it by 2 steps: 1. We first calculate $$g(x,y,d)$$ which is the largest lenth before the turn. This can b...
0
0
['Dynamic Programming', 'C++']
0
length-of-longest-v-shaped-diagonal-segment
Simple JAVA DFS solution
simple-java-dfs-solution-by-vinay_p2-2lu1
Code
vinay_p2
NORMAL
2025-02-17T15:44:56.187766+00:00
2025-02-17T15:44:56.187766+00:00
64
false
# Code ```java [] class Solution { int n, m; int[] dx = {-1, -1, 1, 1}; int[] dy = {-1, 1, 1, -1}; public int lenOfVDiagonal(int[][] grid) { n = grid.length; m = grid[0].length; List<int[]> list = new ArrayList<>(); for (int i=0; i<n; i++){ for (int j=0; j<m...
0
0
['Depth-First Search', 'Java']
0
length-of-longest-v-shaped-diagonal-segment
Easiest Solution || Java || Beats 100%
easiest-solution-java-beats-100-by-adiii-ywmo
IntuitionThis code finds the longest valid diagonal path between cells of a 2D grid. The grid contains two types of cells, marked by 1 and 2. A valid diagonal p
adiiityaambekar
NORMAL
2025-02-17T10:33:39.084539+00:00
2025-02-17T10:33:39.084539+00:00
66
false
# Intuition This code finds the longest valid diagonal path between cells of a 2D grid. The grid contains two types of cells, marked by 1 and 2. A valid diagonal path is one where you can move between cells marked with 1 and 2 by stepping through diagonals. The key to solving this problem lies in the use of depth-firs...
0
0
['Java']
0
length-of-longest-v-shaped-diagonal-segment
2D matrix DP
2d-matrix-dp-by-rsysz-6y0z
Intuitionsimilar problem: https://leetcode.com/problems/longest-increasing-path-in-a-matrix/description/Approachfind all 8 state for each grid[i][j] then we can
rsysz
NORMAL
2025-02-17T08:11:47.710395+00:00
2025-02-17T08:11:47.710395+00:00
12
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> similar problem: https://leetcode.com/problems/longest-increasing-path-in-a-matrix/description/ # Approach <!-- Describe your approach to solving the problem. --> find all 8 state for each grid[i][j] then we can leverage dp arr to reduce t...
0
0
['C++']
0