best explanation of this coding problem. Hats off!!!!
@rahuldasari1886 Жыл бұрын
Really very good explanation video....
@pavan-nc2gs2 жыл бұрын
stoped my coading practice beacause of this problem, And now resuming because of this video, thank you so much sir.
@raj_kundalia Жыл бұрын
I think this is the best explanation out there!
@RAHULYADAV-zr5fq2 жыл бұрын
Really loved the way u explained!!
@sachin_getsgoin4 жыл бұрын
Very good explanation. Indeed the question is tricky and it was difficult to build the intuition to solution. Appreciate your honesty and the fact that you acknowledge the problem is difficult.
@rahulmanghnani30814 жыл бұрын
Hi Sachin, thank you for the warm feedback! :) Glad my explanation was helpful, Happy LeetCoding!
@soumyakarmakar6470 Жыл бұрын
Awesome Explanation !!!!!
@swapnildarmora62583 жыл бұрын
I would like to say that this best explanation without actually jumping into the coding first. What I liked about your approach was you explained it in a way that I was able to grasp at the beginning itself and didn't need to watch the entire video.
@bishwajeetsharma34983 жыл бұрын
I myself struggled a lot, spent like 5 hrs pondering tried but i was doing a mistake i was creating a map of all the common differences which was both time and space consuming. Thanks for the video!! Helped me save my night for other problems!!
@mrprime5572 жыл бұрын
Did the same. created a map of common difference.
@anthonykostal1633 Жыл бұрын
Great Work!
@MehtabButt-q2f Жыл бұрын
please do leave useful links in descriptions
@mounishsavier57742 жыл бұрын
Great solution, thanks!!
@tushartilwani95402 жыл бұрын
Awesome explanation Rahul. Keep making more videos.
@shobhitkumar68204 жыл бұрын
Really loved your honesty sir...that sometimes its not easy to come up with a solution....
@rahulmanghnani30814 жыл бұрын
That's true :) Thanks Shobhit!
@sainathreddy26323 жыл бұрын
by just watcing first 12 min i had coded it up and it worked on first go : )). thank's a ton
@pulavarthichaitanya34032 жыл бұрын
very good explaination
@naincyrastogi63042 жыл бұрын
Thank you so much.. You have explained it very well... Seriously... It's awesome. If someone will try to listen you with the calm mind he will get to know the logic of solving this question. Really thank you so much.
@adityakrishnan31333 жыл бұрын
Thank you. Your video helped me understand the logic to solve this problem. Much appreciated!
@burakarslan18852 жыл бұрын
That helped me a lot. Thank you very much mate. Keep going
@shreyasjain93823 жыл бұрын
Thanks man! The explanation before coding and the verbose code does make things crystal clear. Keep up the good work :)
@AyushiSharmaDSA3 жыл бұрын
Great explanation, helped a lot. thanks :)
@gauravniranjan27703 жыл бұрын
Thank You! I was struggling for quite some time in this question.
@sushmitakumari8252 Жыл бұрын
thanks best explanation
@ash_j34 жыл бұрын
9:40 [[ : ], [3 : 1], [6 : 1, 3 : 2], [9 : 1, 6 : 2, 3 : 3]] I think, this should be the final array, although it doesn't make any difference to the final result. Correct me if I am wrong. Nice explanation, BTW!!
@rahulmanghnani30814 жыл бұрын
Hi Jatin! Thanks for your comment! Actually no, [[ : ], [3 : 1], [6 : 1, 3 : 2], [9 : 1, 6 : 1, 3 : 3]] is still correct because when we compare the difference between the current element and any previous element we update the current element's dictionary only for the difference between the current element and the previous element, we do not update all dictionary elements of the current element. Since there can be only 'one difference' between the current element and the previous element, we end up updating the value for only one key whenever we compare the current element with any previous element. Also, if you look at the array, you cannot find a scenario where you have 3 numbers separated by a difference of 6, so 6:2 would not be a valid dictionary entry. Hope that clears things up! Have a good day!
@sanjanar91982 жыл бұрын
Awesome explanation, I could not find any explanation to be better than this
@e.sowmia2 жыл бұрын
thanks for your vedio
@think__tech4 жыл бұрын
14:03 One can clearly see the amount of effort you are putting in trying yo explain the concept, really liked that. It was a wonderful explanation thanks! :D
@rahulmanghnani30814 жыл бұрын
Hahaha! Thanks a lot Devanshu, made my day! :)
@ritesh_sinha3 жыл бұрын
Crux at 6:16 does the trick. I could code the solution in one go with just that line. Great video
@gautamarora65163 жыл бұрын
Thanks! This video helped me a lot :)
@tanmayagarwal85133 жыл бұрын
Great Explanation!! Really we can see .. u really put some efforts in it!
@narutouzumaki-yx9mw2 жыл бұрын
Is there a way to solve this using memoization?
@gandhijainamgunvantkumar67832 жыл бұрын
Thank you for amazing explanation :)
@yashjain1492 Жыл бұрын
if we iterate the j loop from i - 1 to 0 then why it gives wrong answer on some test case?
@yili97252 жыл бұрын
really nice solution and explanation. I just think line 21 is not needed.
@tejakayyala57953 жыл бұрын
Great Bro
@tejeshvaish173 жыл бұрын
thank you sir!!
@arpit_singh104 жыл бұрын
Great explanation :)
@rahulmanghnani30814 жыл бұрын
Thanks a lot, Arpit! :) Happy LeetCoding!
@prachurjyabasistha46824 жыл бұрын
Really nice explanation but I think that the elements have to be distinct for the solution to work
@amarshinde58632 жыл бұрын
finally understood 😄
@nagalakshmi13854 жыл бұрын
very good explanation
@rahulmanghnani30814 жыл бұрын
Thank you so much! :)
@sathya16573 жыл бұрын
Thanks sir
@taimurkhaliq44773 жыл бұрын
God bless you. Also you have over 30k emails to check.
@timzhang66513 жыл бұрын
Good job explaining. When approaching this problem, I thought the question asks to find the maximum of increasing or decreasing subsequence in an integer array 😂.
@ShivamSingh-me1nb4 жыл бұрын
Nice explanation
@rahulmanghnani30814 жыл бұрын
Thanks a lot, Shivam! Happy LeetCoding! :)
@saurabhshukla49003 жыл бұрын
at 9:57 the difference 3 has occurred thrice before 12
@vineethsai15753 жыл бұрын
Python solution for the same logic. ``` class Solution: def longestArithSeqLength(self, nums: List[int]) -> int: length = len(nums) dp = [collections.defaultdict(lambda: 0) for _ in range(length)] maxValue = 1; # because min length is 2. There is atleast 1 difference subsequence for i in range(length): currentElement = nums[i] currentMap = dp[i] j = 0 while j < i: difference = currentElement - nums[j] previousMap = dp[j] newValue = previousMap[difference] + 1 currentMap[difference] = newValue dp[i] = currentMap maxValue = max(maxValue, currentMap[difference]) j += 1 return maxValue + 1 ```
@harvitech88714 жыл бұрын
Nice explanation but the notifications sounds were a bit annoying
@rahulmanghnani30814 жыл бұрын
I totally understand and I apologize! I will make sure to keep my phone off the next time :) Thank you for your feedback, Happy LeetCoding! :)
@aayushrajput12613 жыл бұрын
Used same approach in cpp but got TLE in leetcode.
@manideep12183 жыл бұрын
us a array instead of unordered_map and add 500 to the value(difference) so that u can store in the array
@adityakajale44032 жыл бұрын
use a array instead of unordered_map and add 500 to the value(difference) so that u can store in the array now try to solve it
@pisanghangus23 жыл бұрын
nicesah
@pabloarkadiusz46874 жыл бұрын
Lol. i Came up with this solution and discarted it because though that it can´t be that strange xd
@rahulmanghnani30814 жыл бұрын
Hahaha, yup that happens! :D
@engineerhiteshahuja4 жыл бұрын
Hey rahul, Nice explanation. Don't you think that this solution is going to have huge space complexity in contrast to other dp solutions? Miles to go before I sleep. Keep practicing and keep delivering good videos. Try to reduce the length of videos if possible by doing the editing in the end.
@rahulmanghnani30814 жыл бұрын
Hi Hitesh, thank you so much for the honest feedback! I will work on it :) Yup, I agree with you. This solution does have relatively greater space complexity but I like this approach because it is more intuitive to me :)
@hhcdghjjgsdrt235 Жыл бұрын
can you optimize my code ?? public class Solution { public int LongestArithSeqLength(int[] nums) { int result = 2; for (int i = 0; i < nums.Length; i++) { int current = nums[i]; for (int j = i+1; j < nums.Length; j++) { int diff = (nums[j] - nums[i]); int nextInd = j + 1; result = Math.Max(result, Helper(nextInd, diff, 2)); } } return result; int Helper(int currInd, int difference,int R) { int res = R; for (int i = currInd; i < nums.Length; i++) { int differ = nums[i] - nums[currInd - 1]; if (differ == difference) { res = Math.Max(res, Helper(i+1,differ, R+1)); } } return res; } } }
@MrSpidm2 жыл бұрын
Why can't you code in swift ? There also exists a huge iOS community to support you.
@Om-mb8cv2 жыл бұрын
I was finding it hard to understand from other solutions, thanks for explaining it properly !! I would love to connect with you and learn from you, if possible would love to talk to you on LinkedIn