Тёмный

Insertion Sort List - Leetcode 147 - Python 

NeetCode
Подписаться 750 тыс.
Просмотров 29 тыс.
50% 1

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🥷 Discord: / discord
🐦 Twitter: / neetcode1
🐮 Support the channel: / neetcode
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
💡 CODING SOLUTIONS: • Coding Interview Solut...
💡 DYNAMIC PROGRAMMING PLAYLIST: • House Robber - Leetco...
🌲 TREE PLAYLIST: • Invert Binary Tree - D...
💡 GRAPH PLAYLIST: • Course Schedule - Grap...
💡 BACKTRACKING PLAYLIST: • Word Search - Backtrac...
💡 LINKED LIST PLAYLIST: • Reverse Linked List - ...
💡 BINARY SEARCH PLAYLIST: • Binary Search
📚 STACK PLAYLIST: • Stack Problems
Problem Link: leetcode.com/problems/inserti...
0:00 - Read the problem
0:35 - Understand Insertion Sort
4:15 - Drawing Explanation
9:37 - Coding Explanation
leetcode 147
This question was identified as a microsoft interview question from here: github.com/xizhengszhang/Leet...
#microsoft #interview #python
Disclosure: Some of the links above may be affiliate links, from which I may earn a small commission.

Наука

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

 

13 июл 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 35   
@john_youtube
@john_youtube 2 года назад
Just got my job at Amazon and I can say without a doubt you're a major reason for that. Thank you neetcode
@__________________________6910
@__________________________6910 2 года назад
noice
@henryrussell7392
@henryrussell7392 2 года назад
congrats john
@sumosam1980
@sumosam1980 2 года назад
Congratulations! That's lots of hard work and time. Best wishes going forward!
@zabona
@zabona Год назад
tmp = dummy, or you will not sort first element. Dummy is not even used after it's initialized.
@ssenthilnathan3
@ssenthilnathan3 2 года назад
I just learned insertion sort, and you posted this problem. Very Thankyou !!
@__________________________6910
@__________________________6910 2 года назад
noice
@alaaal-habashna4722
@alaaal-habashna4722 2 года назад
Thank you! This is very clear.
@danielshvartz9702
@danielshvartz9702 7 месяцев назад
worth to mention that prev pointer will always point to the last sorted element so when we do prev.next = curr.next we do it to save the next nodes and to continue from the last sorted node.
@nathnaeldereje5127
@nathnaeldereje5127 Год назад
Great Job, That was so helpful.
@erkhembayarbayart3966
@erkhembayarbayart3966 2 года назад
nice explanation! thank u
@shidharthraj9310
@shidharthraj9310 2 года назад
Really helpful 😀👍
@rahulmalakar8288
@rahulmalakar8288 22 дня назад
Beautiful explanation
@sarahbavan3959
@sarahbavan3959 11 месяцев назад
you are the best!!!
@poorpanda9033
@poorpanda9033 10 месяцев назад
Thank You
@meme-blower
@meme-blower Год назад
super helpful
@ashkanfb
@ashkanfb 6 месяцев назад
Even if you don't do the extra comparison with the last element, this algorithm is still O(n) best case, but this best case happens when the initial linked list is sorted in reverse order.
@vrajeshbadgujar
@vrajeshbadgujar Год назад
Shukriya !
@chendong2197
@chendong2197 Год назад
after initializing the dummy node, which point to head. When assigning head to prev with (prev = head). Are you assigning the dummy node to prev or the old head to prev? 9th line
@cosepeter2197
@cosepeter2197 Год назад
old head is assigned to prev not the dummy node. This done because it's not required to check the first node , so cur node start from the second node
@orellavie6233
@orellavie6233 2 года назад
Why not checking if temp.next is not none before actually using its .val?
@xiaoyunzhi6900
@xiaoyunzhi6900 Год назад
Because cur.val is guaranteed to be smaller than prev.val, tmp will first reach prev before it reaches None
@christiangualteros36
@christiangualteros36 2 года назад
hello. i have a question silly but i don't know how I can proof this example and what I need to call for print in the screem the result. thank you
@anmolbakshi7983
@anmolbakshi7983 Год назад
start iterating from the head until it becomes null and print each node's value
@christiangualteros36
@christiangualteros36 Год назад
@@anmolbakshi7983 thank you. You're a great person
@venkateshvardhineedi9571
@venkateshvardhineedi9571 Год назад
ListNode temp = head while(temp != null){ System.out.println(temp.val) temp = temp.next }
@Monkey45139
@Monkey45139 2 года назад
Hi it’s me again I am your biggest fan plz read this comment u r helping me so much
@AlexSav
@AlexSav 2 года назад
11:05 Is't it crash on empty list? Line 9 (head might be None)
@venkateshvardhineedi9571
@venkateshvardhineedi9571 Год назад
add the condition if(head == null) return head
@wz9815
@wz9815 Год назад
Hello, why my code in java is not correct(Time Limit Exceeded)? ListNode dummy = head; ListNode curr = head.next; ListNode prev = head; ListNode tmp = null; while( curr != null){ if (curr.val >= prev.val){ prev = curr; curr = curr.next; continue; } tmp = head; while(curr.val > tmp.next.val){ tmp = tmp.next; } prev.next = curr.next; curr.next = tmp.next; tmp.next = curr; curr = prev; } return dummy.next;
@zabona
@zabona Год назад
That's most likely because two first elements are not sorted, and because of a mistake in the video you keep inserting second element before itself. Try changing tmp initialization to tmp = dummy
@user-vu8jp3si2r
@user-vu8jp3si2r Год назад
Why this code gives TLE? /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */ class Solution { public ListNode insertionSortList(ListNode head) { ListNode helpHead = new ListNode(-9999, head); //without set pointer dummy.next is works ListNode curr = head; while (curr != null) { ListNode prev = helpHead; while(prev.next != null && prev.next.val
@samirpaul2
@samirpaul2 2 года назад
👍👍❤❤⭐⭐🙌🙌
@masternobody1896
@masternobody1896 2 года назад
how do I get a job at fang. what do I need to learn. its been 2 years i have been unemployed
@__________________________6910
@__________________________6910 2 года назад
here is the ans ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-YYX93BWqQY8.html
Далее
Largest Number - Leetcode 179 - Python
10:17
Просмотров 52 тыс.
Sort List - Merge Sort - Leetcode 148
13:17
Просмотров 67 тыс.
Epic Reactions 😂
00:33
Просмотров 2,3 млн
My Puzzle Robot is 200x Faster Than a Human
21:21
Просмотров 3,3 млн
Middle of the Linked List - Leetcode 876 - Python
4:57
5 Useful F-String Tricks In Python
10:02
Просмотров 275 тыс.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Big-O Notation - For Coding Interviews
20:38
Просмотров 426 тыс.
LeetCode Sort List Explained - Java
9:29
Просмотров 78 тыс.
ОБСЛУЖИЛИ САМЫЙ ГРЯЗНЫЙ ПК
1:00