Тёмный

Remove Nodes From Linked List - Leetcode 2487 - Python 

NeetCodeIO
Подписаться 144 тыс.
Просмотров 9 тыс.
50% 1

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
🐦 Twitter: / neetcode1
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
Problem Link: leetcode.com/problems/remove-...
0:00 - Read the problem
0:42 - Drawing Explanation 1
3:50 - Coding Explanation 1
6:57 - Drawing Explanation 2
9:56 - Coding Explanation 2
leetcode 2487
#neetcode #leetcode #python

Опубликовано:

 

5 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 31   
@mahesh_bvn
@mahesh_bvn 2 месяца назад
One suggestion, can you explain other dp problems which includes subarray, sub sequences and subset other than daily streak problems! Rest your explanations are crisp and thanks to you for that🎉
@E1an9640
@E1an9640 2 месяца назад
brother you have no idea how much your explanation videos means to some of us. Some problems in the past few days were quite challenging and I actually wished you were there to explain it (daily challenge problem on april 31 and few others).Hope you are fine and if possible can you release a video explaining the solution of the problem given on april 31st
@JamesBond-mq7pd
@JamesBond-mq7pd 2 месяца назад
Thanks to this channel I was able to solve this problem on my own
@vedantjha2327
@vedantjha2327 2 месяца назад
Today it was problem of day, solved it , good logic to reverse the list then remove all elements less than maximum...nice
@juanito1410
@juanito1410 2 месяца назад
I'm not sure if it's possible in python but.... For the first solution with stack, we can make the code shorter First initiliaze the stack with a node which has a value of INT_MAX. Next, immediately setting the st.top()->next = current. Instead of doing another loop for bulding the linkedlist.
@vidallera8869
@vidallera8869 2 месяца назад
yes you can!, i solved it in the same way. class Solution: def removeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]: s = [] dummy = curr = ListNode(10 ** 5 + 1, head) # MAX_VAL in Constraints while curr: while s and curr.val > s[-1].val: node = s.pop() s[-1].next = curr s.append(curr) curr = curr.next return dummy.next
@hamirmahal
@hamirmahal 2 месяца назад
Thanks for the explanations!
@VidyaBhandary
@VidyaBhandary 2 месяца назад
Very clever solutions !!!
@pradyumnachakraborty3262
@pradyumnachakraborty3262 2 месяца назад
Just create a dp array and store all the values > k for the head. Then traverse the entire thing. If dp[i] > k then dp[i] = dp[i-1] - 1, else dp[i]=dp[i-1]. Now find the first element where the value is equal to 0 and return all the elements from that till end.
@DeathSugar
@DeathSugar 2 месяца назад
First time I've received Time Exceed on compiled language. Stack solutions doesn't cut for Rust - it will timeout. The only solution to fiddle with pointers implementing the last algo AND reversing it back at the same time.
@Munchen888
@Munchen888 2 месяца назад
I’ve seen your video before I’ve solved. Passed 96% TC and 96% SC. Just reversed LL, use two pointers: current and next_node
@subhankarhotta7094
@subhankarhotta7094 Месяц назад
The first solution will have a worst case time complexity of O(n^2) right? Becz in the worst case (when the linked list is something like [5, 3, 2, 1, 10] you need to pop the whole stack out when the curr element is 10).
@lyk2244
@lyk2244 2 месяца назад
monotonic stack?
@satyamjha68
@satyamjha68 2 месяца назад
Solved it !!
@akhilchauhan9417
@akhilchauhan9417 2 месяца назад
bro is back
@ik6071
@ik6071 Месяц назад
I wish you could do daily leetcode problems :/
@vishnusunil9610
@vishnusunil9610 2 месяца назад
I am confident that your course coupled with your video solutions will land me a MLE role, let us meet one year from now !!
@subhashreebanik8131
@subhashreebanik8131 2 месяца назад
I'm rooting for you!
@priyanshagarwal8490
@priyanshagarwal8490 Месяц назад
1353. Maximum Number of Events That Can Be Attended. Next Please..
@fraserdab
@fraserdab 2 месяца назад
Dude u just disappeared for like 9 days, what happened? Ik some questions were done before but some hard ones we needed
@DeathSugar
@DeathSugar 2 месяца назад
Just search old videos
@vidallera8869
@vidallera8869 2 месяца назад
​@@DeathSugar i couldn't find some, maybe LeetCode change the names. did you find all videos ?
@DarkNomadness
@DarkNomadness 2 месяца назад
Give him a break lol, there were other videos that explained those hard questions pretty well, however I did miss neetcodeio solutions for those hard ones 😅
@MehmetDemir-xi3yy
@MehmetDemir-xi3yy 2 месяца назад
@@DeathSugar there is no neetcode videos for some of previous questions
@cenacr007
@cenacr007 2 месяца назад
in the first solution, we know stack stores elements in reverse order so how are we getting right answer if we are directly constructing new LL by traversing in stack directly, shouldn't we reverse it or while constructing LL add new node to front of existing LL ??
@juanito1410
@juanito1410 2 месяца назад
stack in this code is just implemented with a List data structure. So when the for loop/iterarion was called the traversal doesn't really implement the FILO/LIFO.
@dineshkumarkb1372
@dineshkumarkb1372 2 месяца назад
That's because we are not popping from the stack rather we are just iterating through it like a regular list. Had we popped from the stack and then built our LL, we would have got it in reverse like you said.
@MehmetDemir-xi3yy
@MehmetDemir-xi3yy 2 месяца назад
dude I thought you were kidnapped
@phanthe3471
@phanthe3471 2 месяца назад
Just solved it and struggle with the requirement until I realize that is monotonic stack. An easy problem when we find out the pattern for it.
@pastori2672
@pastori2672 2 месяца назад
bro disappears when we need him the most 😭 (end the month)
Далее
Longest Ideal Subsequence - Leetcode 2370 - Python
28:02
Четыре тормоза
00:53
Просмотров 45 тыс.
Лайфхак с колой не рабочий
00:16
Просмотров 463 тыс.
how Google writes gorgeous C++
7:40
Просмотров 806 тыс.
How I would learn Leetcode if I could start over
18:03
Просмотров 299 тыс.
8 patterns to solve 80% Leetcode problems
7:30
Просмотров 221 тыс.
Should you grind LeetCode? feat. NeetCode | 051
56:22
5 Good Python Habits
17:35
Просмотров 408 тыс.
Minimum Cost to Hire K Workers - Leetcode 857 - Python
19:01
Четыре тормоза
00:53
Просмотров 45 тыс.