Rotate List - Linked List - Leetcode 61 - Python

  Рет қаралды 45,837

NeetCode

NeetCode

Күн бұрын

Пікірлер
@CST1992
@CST1992 8 ай бұрын
6:49 "k modded -" Rude interruption there
@floatingfortress721
@floatingfortress721 Жыл бұрын
Clear explanation with clean code :) Step 1: Compute length of list, storing a reference to tail node Step 2: Find pivot node, which becomes new tail node Step 3: Rotate list by reconnecting both parts
@JameS00989
@JameS00989 2 жыл бұрын
Best channel on Internet for DS and Algo 🎉 Thanks NeetCode ❤
@fazliddinfayziev-qg1vg
@fazliddinfayziev-qg1vg 10 ай бұрын
I always watch your videos, when I cannot solve algorithms by myself. You are good at explaining. Thank you bro.
@MrACrazyHobo
@MrACrazyHobo 2 жыл бұрын
I love you man, thanks for getting me a job!
@licokr
@licokr 9 ай бұрын
When I solve coding problems and use itereation, somehow, I think of iteration of all elements I think it's because many problems need to iterate. I think this is really important to break what I have known and think about the solution fit the best to the problem I currently encounter. My first approach was making a list then iterate them. Time: O(n) Space: O(n). After your explanation, I only replaced with two points. and I thought, okay it looks nice. Then I saw your solution. It iterates one more though, you don't use any space I mean O(1). Hoo, great. I really learned a lot from your videos. Your eyes to see problems is absolutely stand out
@louiswoolley987
@louiswoolley987 3 жыл бұрын
great explanation! could you make a video on leetcode 105 Construct Binary Tree from Preorder and Inorder Traversal ?
@ronpb3943
@ronpb3943 3 жыл бұрын
I wrote a recursive solution, it went good until the cases where the k number was huge appeared
@meghanapg7194
@meghanapg7194 2 жыл бұрын
Best teacher ever! Thank you :)
@salomeoumarouwate2024
@salomeoumarouwate2024 Жыл бұрын
NeetCode is GREAT!!!
@digestable_bits
@digestable_bits 2 жыл бұрын
very clear explanation, thanks as usual :)
@MrLeyt1125
@MrLeyt1125 9 ай бұрын
Hey why dont you use 2-pointers method from Leetcode 19?
@ComputerScienceSimplified
@ComputerScienceSimplified 3 жыл бұрын
Great video, keep up the incredible work! :)
@user-jn5se1kb2q
@user-jn5se1kb2q 9 ай бұрын
hello guys sorry i'm a beginner, when we assign the cur = head is it create a copy of the linked list or referencing the same linked list?
@garcj1499
@garcj1499 5 ай бұрын
it means cur is referencing the head of the same list!
@theysay6696
@theysay6696 3 жыл бұрын
Great drawing! Thanks!
@rohitkumarsinha876
@rohitkumarsinha876 3 жыл бұрын
great explanation bro and thanks alot
@juheehong7445
@juheehong7445 2 жыл бұрын
would a fast/slow pointer to get to our desired point work here? how exactly would we implement that, though?
@prateeksharma2354
@prateeksharma2354 2 жыл бұрын
ya even i thought the same
@anchitbhushan6172
@anchitbhushan6172 2 жыл бұрын
I think that would work too, but in worst case for reaching at k-1 th node will have O(n) complexity, but in case of for loop implemented here the worst case is O(k)
@Prince-gt5ju
@Prince-gt5ju 2 жыл бұрын
even i thought same but if k is larger than len of linked list then it wont work
@derrickagyemangduah2353
@derrickagyemangduah2353 Жыл бұрын
@@Prince-gt5ju just find the k mod len
@Ishaana3290
@Ishaana3290 Жыл бұрын
Why we are doing k=k% length
@AshokKota-p3w
@AshokKota-p3w 3 ай бұрын
because it reduces the time even for k=2000000000 .we will get the answer by doing only two rotations.
@AshokKota-p3w
@AshokKota-p3w 3 ай бұрын
Thank you Brother
@Ishaana3290
@Ishaana3290 Жыл бұрын
And what exactly happening in for loop New head = cur.next ie 4 Cur.next = none means 3 -> none What is the value of tail.next ??
@archanayogi7856
@archanayogi7856 2 жыл бұрын
i didnt understand the tail.next last line part after nhead become 45 how tail = head(12345) it should be added to the nhead , i am beginner pls help me
@dpsingh_287
@dpsingh_287 2 жыл бұрын
we already broke the connection between 123 and 45 when we set cur.next=None after exiting the loop therefore, head would now be (1->2->3). Now we essentially put this head at the end of the tail (which is 4->5). This gives us the desired rotated list which is 4->5->1->2->3
@sabyasachisahoo8975
@sabyasachisahoo8975 2 жыл бұрын
I love your way of explaining .
@triscuit5103
@triscuit5103 2 жыл бұрын
I knoooow, right? Nobody else can do it like he does, I absolutely love the way he explains things
@maamounhajnajeeb209
@maamounhajnajeeb209 2 жыл бұрын
I am the one who like this video for the 500 time
@shaantalk
@shaantalk 9 ай бұрын
you should like it off number if times 😂..otherwise the like would go away
@rudranshsharma2074
@rudranshsharma2074 2 жыл бұрын
k = k % len(linked_list).....right?
@codeduel
@codeduel 2 жыл бұрын
yes
@edwardteach2
@edwardteach2 8 ай бұрын
U a God
@shrimpo6416
@shrimpo6416 3 жыл бұрын
clean & neet
@halahmilksheikh
@halahmilksheikh 2 жыл бұрын
I don't understand, isn't the k = k%len part just an optimization? Without it, it should just be slow but should still work. But if you comment it out, there are test cases that fail. Why is that? Edit: Oh I get it now. The formula for finding the break is length - k - 1. It's possible to have a huge K which sets it to negative, so you need the % to keep k smaller than length.
@qazaqempire2446
@qazaqempire2446 2 жыл бұрын
if k > total len of linked list, then we will do more rotations than usual but the result will be same. so we only need to do actual remainder of k shifts, which is k % len
@vijayakumareyunni6010
@vijayakumareyunni6010 Жыл бұрын
Good explanation. But, some time can be saved by limiting the explanation of the problem.
@ngneerin
@ngneerin Жыл бұрын
In short: 2 pointer
@ximengzhao2168
@ximengzhao2168 3 жыл бұрын
Great video, line 26: cur.next = tail.next works as well :)
@codeduel
@codeduel 2 жыл бұрын
It does but for simplicity, None is preferred.
@davidmbugua6994
@davidmbugua6994 2 жыл бұрын
you can also the method of converting in into a list, then using the rotate list method!
@saran703
@saran703 3 жыл бұрын
can you please make a tutorial about python data struture !! That would me more helpful
@infiniteloop5449
@infiniteloop5449 Жыл бұрын
That is literally his whole channel
@ary_21
@ary_21 2 жыл бұрын
why cant we use reversals algorithm on this question?
@colonelondghoskots7759
@colonelondghoskots7759 2 жыл бұрын
I THINK THE code is not working
@jimwang8
@jimwang8 3 жыл бұрын
two passes
@davidlee588
@davidlee588 2 жыл бұрын
the skip length is 5 - 2 = 3; while we need i < 3 - 1, which means i starts from 0, and 1, it only moves one step, not two steps, that's why i DON'T understand the length - k - 1part; Could anyone explain more?
@qazaqempire2446
@qazaqempire2446 2 жыл бұрын
it's k = 2 but index starts from 0 so hence minus
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 192 М.
Война Семей - ВСЕ СЕРИИ, 1 сезон (серии 1-20)
7:40:31
Семейные Сериалы
Рет қаралды 1,6 МЛН
«Жат бауыр» телехикаясы І 30 - бөлім | Соңғы бөлім
52:59
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 340 М.
L22. Rotate a LinkedList
12:10
take U forward
Рет қаралды 78 М.
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 677 М.
Pow(x, n) - X to the power of N - Leetcode 50 - Python
12:37
NeetCode
Рет қаралды 84 М.
Palindrome Linked List - Leetcode 234 - Python
11:06
NeetCode
Рет қаралды 102 М.
Linked Lists for Technical Interviews - Full Course
1:27:24
freeCodeCamp.org
Рет қаралды 370 М.
Split Linked List in Parts - Leetcode 725 - Python
11:01
NeetCodeIO
Рет қаралды 12 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 765 М.
Simplify Path - Stack - Leetcode 71 - Python
12:47
NeetCode
Рет қаралды 65 М.
Война Семей - ВСЕ СЕРИИ, 1 сезон (серии 1-20)
7:40:31
Семейные Сериалы
Рет қаралды 1,6 МЛН