Leetcode Solutions | 1027 | Longest Arithmetic Sequence

  Рет қаралды 14,456

Rahul Manghnani

Rahul Manghnani

Күн бұрын

Пікірлер: 68
@dakshsharma8006
@dakshsharma8006 Жыл бұрын
best explanation of this coding problem. Hats off!!!!
@rahuldasari1886
@rahuldasari1886 Жыл бұрын
Really very good explanation video....
@pavan-nc2gs
@pavan-nc2gs 2 жыл бұрын
stoped my coading practice beacause of this problem, And now resuming because of this video, thank you so much sir.
@raj_kundalia
@raj_kundalia Жыл бұрын
I think this is the best explanation out there!
@RAHULYADAV-zr5fq
@RAHULYADAV-zr5fq 2 жыл бұрын
Really loved the way u explained!!
@sachin_getsgoin
@sachin_getsgoin 4 жыл бұрын
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.
@rahulmanghnani3081
@rahulmanghnani3081 4 жыл бұрын
Hi Sachin, thank you for the warm feedback! :) Glad my explanation was helpful, Happy LeetCoding!
@soumyakarmakar6470
@soumyakarmakar6470 Жыл бұрын
Awesome Explanation !!!!!
@swapnildarmora6258
@swapnildarmora6258 3 жыл бұрын
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.
@bishwajeetsharma3498
@bishwajeetsharma3498 3 жыл бұрын
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!!
@mrprime557
@mrprime557 2 жыл бұрын
Did the same. created a map of common difference.
@anthonykostal1633
@anthonykostal1633 Жыл бұрын
Great Work!
@MehtabButt-q2f
@MehtabButt-q2f Жыл бұрын
please do leave useful links in descriptions
@mounishsavier5774
@mounishsavier5774 2 жыл бұрын
Great solution, thanks!!
@tushartilwani9540
@tushartilwani9540 2 жыл бұрын
Awesome explanation Rahul. Keep making more videos.
@shobhitkumar6820
@shobhitkumar6820 4 жыл бұрын
Really loved your honesty sir...that sometimes its not easy to come up with a solution....
@rahulmanghnani3081
@rahulmanghnani3081 4 жыл бұрын
That's true :) Thanks Shobhit!
@sainathreddy2632
@sainathreddy2632 3 жыл бұрын
by just watcing first 12 min i had coded it up and it worked on first go : )). thank's a ton
@pulavarthichaitanya3403
@pulavarthichaitanya3403 2 жыл бұрын
very good explaination
@naincyrastogi6304
@naincyrastogi6304 2 жыл бұрын
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.
@adityakrishnan3133
@adityakrishnan3133 3 жыл бұрын
Thank you. Your video helped me understand the logic to solve this problem. Much appreciated!
@burakarslan1885
@burakarslan1885 2 жыл бұрын
That helped me a lot. Thank you very much mate. Keep going
@shreyasjain9382
@shreyasjain9382 3 жыл бұрын
Thanks man! The explanation before coding and the verbose code does make things crystal clear. Keep up the good work :)
@AyushiSharmaDSA
@AyushiSharmaDSA 3 жыл бұрын
Great explanation, helped a lot. thanks :)
@gauravniranjan2770
@gauravniranjan2770 3 жыл бұрын
Thank You! I was struggling for quite some time in this question.
@sushmitakumari8252
@sushmitakumari8252 Жыл бұрын
thanks best explanation
@ash_j3
@ash_j3 4 жыл бұрын
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!!
@rahulmanghnani3081
@rahulmanghnani3081 4 жыл бұрын
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!
@sanjanar9198
@sanjanar9198 2 жыл бұрын
Awesome explanation, I could not find any explanation to be better than this
@e.sowmia
@e.sowmia 2 жыл бұрын
thanks for your vedio
@think__tech
@think__tech 4 жыл бұрын
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
@rahulmanghnani3081
@rahulmanghnani3081 4 жыл бұрын
Hahaha! Thanks a lot Devanshu, made my day! :)
@ritesh_sinha
@ritesh_sinha 3 жыл бұрын
Crux at 6:16 does the trick. I could code the solution in one go with just that line. Great video
@gautamarora6516
@gautamarora6516 3 жыл бұрын
Thanks! This video helped me a lot :)
@tanmayagarwal8513
@tanmayagarwal8513 3 жыл бұрын
Great Explanation!! Really we can see .. u really put some efforts in it!
@narutouzumaki-yx9mw
@narutouzumaki-yx9mw 2 жыл бұрын
Is there a way to solve this using memoization?
@gandhijainamgunvantkumar6783
@gandhijainamgunvantkumar6783 2 жыл бұрын
Thank you for amazing explanation :)
@yashjain1492
@yashjain1492 Жыл бұрын
if we iterate the j loop from i - 1 to 0 then why it gives wrong answer on some test case?
@yili9725
@yili9725 2 жыл бұрын
really nice solution and explanation. I just think line 21 is not needed.
@tejakayyala5795
@tejakayyala5795 3 жыл бұрын
Great Bro
@tejeshvaish17
@tejeshvaish17 3 жыл бұрын
thank you sir!!
@arpit_singh10
@arpit_singh10 4 жыл бұрын
Great explanation :)
@rahulmanghnani3081
@rahulmanghnani3081 4 жыл бұрын
Thanks a lot, Arpit! :) Happy LeetCoding!
@prachurjyabasistha4682
@prachurjyabasistha4682 4 жыл бұрын
Really nice explanation but I think that the elements have to be distinct for the solution to work
@amarshinde5863
@amarshinde5863 2 жыл бұрын
finally understood 😄
@nagalakshmi1385
@nagalakshmi1385 4 жыл бұрын
very good explanation
@rahulmanghnani3081
@rahulmanghnani3081 4 жыл бұрын
Thank you so much! :)
@sathya1657
@sathya1657 3 жыл бұрын
Thanks sir
@taimurkhaliq4477
@taimurkhaliq4477 3 жыл бұрын
God bless you. Also you have over 30k emails to check.
@timzhang6651
@timzhang6651 3 жыл бұрын
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-me1nb
@ShivamSingh-me1nb 4 жыл бұрын
Nice explanation
@rahulmanghnani3081
@rahulmanghnani3081 4 жыл бұрын
Thanks a lot, Shivam! Happy LeetCoding! :)
@saurabhshukla4900
@saurabhshukla4900 3 жыл бұрын
at 9:57 the difference 3 has occurred thrice before 12
@vineethsai1575
@vineethsai1575 3 жыл бұрын
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 ```
@harvitech8871
@harvitech8871 4 жыл бұрын
Nice explanation but the notifications sounds were a bit annoying
@rahulmanghnani3081
@rahulmanghnani3081 4 жыл бұрын
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! :)
@aayushrajput1261
@aayushrajput1261 3 жыл бұрын
Used same approach in cpp but got TLE in leetcode.
@manideep1218
@manideep1218 3 жыл бұрын
us a array instead of unordered_map and add 500 to the value(difference) so that u can store in the array
@adityakajale4403
@adityakajale4403 2 жыл бұрын
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
@pisanghangus2
@pisanghangus2 3 жыл бұрын
nicesah
@pabloarkadiusz4687
@pabloarkadiusz4687 4 жыл бұрын
Lol. i Came up with this solution and discarted it because though that it can´t be that strange xd
@rahulmanghnani3081
@rahulmanghnani3081 4 жыл бұрын
Hahaha, yup that happens! :D
@engineerhiteshahuja
@engineerhiteshahuja 4 жыл бұрын
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.
@rahulmanghnani3081
@rahulmanghnani3081 4 жыл бұрын
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
@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; } } }
@MrSpidm
@MrSpidm 2 жыл бұрын
Why can't you code in swift ? There also exists a huge iOS community to support you.
@Om-mb8cv
@Om-mb8cv 2 жыл бұрын
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
Leetcode 1027. Longest Arithmetic Subsequence
23:06
Elite Code
Рет қаралды 699
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 7 МЛН
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 38 МЛН
Winning Google Kickstart Round C 2020
30:57
William Lin (tmwilliamlin168)
Рет қаралды 4 МЛН
Leetcode 1027 Longest Arithmetic Subsequence
9:51
Jeevan Kumar
Рет қаралды 4,4 М.
Easy Google Coding Interview With Ben Awad
28:00
Clément Mihailescu
Рет қаралды 1 МЛН
Leetcode Solutions | 583 | Delete Operation for Two Strings
23:27
Rahul Manghnani
Рет қаралды 1,1 М.
10 years of coding in 13 minutes
13:28
Joma Tech
Рет қаралды 4,9 МЛН
LeetCode Solutions | 837 | New 21 Game
37:53
Rahul Manghnani
Рет қаралды 4,7 М.
5 Problem Solving Tips for Cracking Coding Interview Questions
19:12
Not Everyone Should Code
8:47
PolyMatter
Рет қаралды 3,5 МЛН
LeetCode Solutions | 721 | Accounts Merge
30:11
Rahul Manghnani
Рет қаралды 7 М.