How about traversing LinkedList till middle using slow pointer (jumps one) and fast pointer(jumps two)....Then from middle put the nodes in the stack... Start traversing LinkedList from head keep poping elements from stack and insert at a gap of one node in LinkedList.
@HarshaKalluri5 жыл бұрын
thats extra space.
@safiabegum70604 ай бұрын
Can u be more clear
@rifathossain24404 жыл бұрын
My mans always looking high :)
@anshulsingh12653 жыл бұрын
Agree😂😂😂
@miadinh63812 жыл бұрын
Strategy starts from 3:09
@shamanthhegde27864 жыл бұрын
can you say how the merging condition breaks in odd number of linked list.
@jollysrivastava33264 жыл бұрын
Hi Nick, you may need to rework on your logic for the merge. It's not working fine for odd length array.
@ommule49993 жыл бұрын
This logic works for odd & even length LinkedLists ! No issues
@jacksonripper-mp8dr8 ай бұрын
and you need to rework on developing your brain.....
@jollysrivastava33268 ай бұрын
@@jacksonripper-mp8dr I did. Thanks for letting me know. I just forgot to use my brain.
@jacksonripper-mp8dr8 ай бұрын
@@jollysrivastava3326 I was just kidding.... Everyone learns from mistakes.
@aishwarygupta198 ай бұрын
Does anyone else getting a "Time Limit Exceeded" error
@samwilson45972 жыл бұрын
I first tried it with a stack. this solution is a bit tricky
@vikramreddy75864 жыл бұрын
My dogs are barking in the background :D Like always an awesome explanation. !!
@vasurohilla581210 ай бұрын
where can i found the source code
@nik15oc4 жыл бұрын
Whats the time and space complexities? Time Complexity: O(n) & Space Complexity: O(1) ?
@abe104 жыл бұрын
Yeah, I guess. We traverse all the nodes twice and constant space for temporary variables.
@raginibhadani7257 Жыл бұрын
merge logic does not work correctly
@safiabegum70604 ай бұрын
Explain merge function again Mergin both lists is difficult
@DheerajSharma-fs6je Жыл бұрын
Thank You!!
@akshitgupta76654 жыл бұрын
brilliant
@prathamanand10372 жыл бұрын
thanks
@honey-xr5kp7 ай бұрын
doesnt work for me
@antoniomartinez34294 жыл бұрын
what about traversing the list and pushing values into an array first?
@rajarshibose51224 жыл бұрын
That is something you are not allowed to do for most interviews.Else you can solve every problem like that.....Do that only when you have no other way possible ...
@ianpan01024 жыл бұрын
@@rajarshibose5122 agreed
@Adarsh-mn7pl2 жыл бұрын
Not working for this case Input [1,2,3,4,5] stdout 1 2 5 4 3 Output [1,5,2,4] Expected [1,5,2,4,3]
@arishsheikh30002 жыл бұрын
Split it into 1,2,3 and 4,5
@jagdishwarbiradar17634 жыл бұрын
fast and slow doesn't work properly
@ramesh_hegdeАй бұрын
nice dog bark in background
@ianpan01024 жыл бұрын
My C++ solution using the same idea: """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" class Solution { public: void reorderList(ListNode* head) { if (!head || !head->next || !head->next->next) return; ListNode *slow = head, *fast = head, *head1 = head, *head2, *tmp1, *tmp2; while (fast && fast->next) { slow = slow->next; fast = fast->next->next; } head2 = slow->next; slow->next = nullptr; // split list in half head2 = reverseList(head2); // reverse 2nd half while (head1 && head2) { tmp1 = head1->next; head1->next = head2; tmp2 = head2->next; head2->next = tmp1; head1 = tmp1; head2 = tmp2; } } private: ListNode* reverseList(ListNode* head) { ListNode* prev = nullptr; ListNode* curr = head; ListNode* tmp; while (curr) { tmp = curr->next; curr->next = prev; prev = curr; curr = tmp; } return prev; } };
@abivilion85592 жыл бұрын
brilliant buddy
@viditsharma39293 жыл бұрын
great.
@johncho916010 ай бұрын
the way youre explaining the merge method is confusing af and the way youre naming these variables certainly dont help
@millenialmusings84512 жыл бұрын
man you spend a lot of time on the intro talking unnecessary trivia.. the actual video starts at 3:09.. plz get straight to the point
@wirelessbrain122 жыл бұрын
No you just don't know what he's talking about before that. He's going through what your mindset should be when breaking down a problem. For ex he talks about 2 pointers because that's the solution for arrays and hence you would think of that to see if it's applicable but then explains why it's not.