LeetCode Reorder List Solution Explained - Java

  Рет қаралды 31,557

Nick White

Nick White

4 жыл бұрын

The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
Join my free exclusive community built to empower programmers! - www.skool.com/software-develo...
Preparing For Your Coding Interviews? Use These Resources
--------------------
(My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.dev/courses/nick
AlgoCademy - algocademy.com/?referral=nick...
Daily Coding Interview Questions - bit.ly/3xw1Sqz
10% Off Of The Best Web Hosting! - hostinger.com/nickwhite
Follow Me on X/Twitter - x.com/nickwhitereal
Follow My Instagram - / nickwwhite
Other Social Media
----------------------------------------------
Discord - / discord
Twitch - / nickwhitettv
TikTok - / nickwhitetiktok
LinkedIn - / nicholas-w-white
Show Support
------------------------------------------------------------------------------
Patreon - / nick_white
PayPal - paypal.me/nickwwhite?locale.x...
Become A Member - / @nickwhite
#coding #programming #softwareengineering

Пікірлер: 36
@rifathossain2440
@rifathossain2440 3 жыл бұрын
My mans always looking high :)
@anshulsingh1265
@anshulsingh1265 2 жыл бұрын
Agree😂😂😂
@shamanthhegde2786
@shamanthhegde2786 4 жыл бұрын
can you say how the merging condition breaks in odd number of linked list.
@yachnagupta2081
@yachnagupta2081 4 жыл бұрын
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.
@HarshaKalluri
@HarshaKalluri 4 жыл бұрын
thats extra space.
@safiabegum7060
@safiabegum7060 27 күн бұрын
Can u be more clear
@vasurohilla5812
@vasurohilla5812 7 ай бұрын
where can i found the source code
@akshitgupta7665
@akshitgupta7665 4 жыл бұрын
brilliant
@DheerajSharma-fs6je
@DheerajSharma-fs6je 8 ай бұрын
Thank You!!
@prathamanand1037
@prathamanand1037 2 жыл бұрын
thanks
@samwilson4597
@samwilson4597 2 жыл бұрын
I first tried it with a stack. this solution is a bit tricky
@jollysrivastava3326
@jollysrivastava3326 3 жыл бұрын
Hi Nick, you may need to rework on your logic for the merge. It's not working fine for odd length array.
@ommule4999
@ommule4999 2 жыл бұрын
This logic works for odd & even length LinkedLists ! No issues
@jacksonripper-mp8dr
@jacksonripper-mp8dr 4 ай бұрын
and you need to rework on developing your brain.....
@jollysrivastava3326
@jollysrivastava3326 4 ай бұрын
@@jacksonripper-mp8dr I did. Thanks for letting me know. I just forgot to use my brain.
@jacksonripper-mp8dr
@jacksonripper-mp8dr 4 ай бұрын
@@jollysrivastava3326 I was just kidding.... Everyone learns from mistakes.
@miadinh6381
@miadinh6381 2 жыл бұрын
Strategy starts from 3:09
@viditsharma3929
@viditsharma3929 3 жыл бұрын
great.
@vikramreddy7586
@vikramreddy7586 4 жыл бұрын
My dogs are barking in the background :D Like always an awesome explanation. !!
@safiabegum7060
@safiabegum7060 27 күн бұрын
Explain merge function again Mergin both lists is difficult
@antoniomartinez3429
@antoniomartinez3429 4 жыл бұрын
what about traversing the list and pushing values into an array first?
@rajarshibose5122
@rajarshibose5122 4 жыл бұрын
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 ...
@ianpan0102
@ianpan0102 4 жыл бұрын
@@rajarshibose5122 agreed
@nik15oc
@nik15oc 4 жыл бұрын
Whats the time and space complexities? Time Complexity: O(n) & Space Complexity: O(1) ?
@abe10
@abe10 4 жыл бұрын
Yeah, I guess. We traverse all the nodes twice and constant space for temporary variables.
@raginibhadani7257
@raginibhadani7257 Жыл бұрын
merge logic does not work correctly
@honey-xr5kp
@honey-xr5kp 3 ай бұрын
doesnt work for me
@aishwarygupta19
@aishwarygupta19 4 ай бұрын
Does anyone else getting a "Time Limit Exceeded" error
@jagdishwarbiradar1763
@jagdishwarbiradar1763 4 жыл бұрын
fast and slow doesn't work properly
@Adarsh-mn7pl
@Adarsh-mn7pl 2 жыл бұрын
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]
@arishsheikh3000
@arishsheikh3000 Жыл бұрын
Split it into 1,2,3 and 4,5
@ianpan0102
@ianpan0102 4 жыл бұрын
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; } };
@abivilion8559
@abivilion8559 2 жыл бұрын
brilliant buddy
@johncho9160
@johncho9160 6 ай бұрын
the way youre explaining the merge method is confusing af and the way youre naming these variables certainly dont help
@millenialmusings8451
@millenialmusings8451 Жыл бұрын
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
@wirelessbrain12
@wirelessbrain12 Жыл бұрын
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.
LeetCode - Reverse Linked List Solution
7:02
Nick White
Рет қаралды 122 М.
LeetCode 48. Rotate Image (Solution Explained)
10:18
Nick White
Рет қаралды 84 М.
Fast and Furious: New Zealand 🚗
00:29
How Ridiculous
Рет қаралды 45 МЛН
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 19 МЛН
SPILLED CHOCKY MILK PRANK ON BROTHER 😂 #shorts
00:12
Savage Vlogs
Рет қаралды 8 МЛН
541 Leetcode problems are NOT enough.
7:12
Sahil & Sarra
Рет қаралды 158 М.
LeetCode Decode String Solution Explained - Java
10:52
Nick White
Рет қаралды 58 М.
LeetCode 238. Product of Array Except Self (Solution Explained)
14:49
Array vs. ArrayList in Java Tutorial - What's The Difference?
17:36
Coding with John
Рет қаралды 510 М.
Prefer Arrays Over Lists. Seriously...
8:31
Amigoscode
Рет қаралды 40 М.
Запрещенный Гаджет для Авто с aliexpress 2
0:50
Тимур Сидельников
Рет қаралды 1,1 МЛН
Ускоряем ваш TV🚀
0:44
ARTEM_CHIBA
Рет қаралды 418 М.
Vision Pro наконец-то доработали! Но не Apple!
0:40
ÉЖИ АКСЁНОВ
Рет қаралды 603 М.
My iPhone 15 pro max 😱🫣😂
0:21
Nadir Show
Рет қаралды 1,9 МЛН