I liked your approach. Most people use dynamic programming for the solution but you applied both, stack+ queue for the solution. On the leetcode website, this question is under stacks therefore your solution is okay but if the interviewer is an as..... he may tell you ,you used stacks and queues at the same time since you pop from the left(popleft() used for queue) so the answer will not be valid if the interviewer asks you to use only stacks so also try ONLY popping the last element in the array/List. What i am saying is that it is very important to have multiple solutions for a problem, try to solve it using only stacks. But i loved your solution....
@saleheen1Ай бұрын
That was super helpful and easy to understand
@carpedim24 Жыл бұрын
Great explanation, I have a series request for you , Can you please make videos on data structures implemented in python???
@rohitmujumdar81953 жыл бұрын
Haven't they asked us to do this in place? Can we employ another data structure here (eg. queue)?
@ppippiminiverse40403 жыл бұрын
Your explanation is crystal clear. Superb!!!
@saianishmalla26463 жыл бұрын
Thanks a lot glad it helps
@krishnaharshith98542 жыл бұрын
Excellent explanation man. Really loved it!!
@pythonenthusiast92924 жыл бұрын
great explanation, I have a series request for you , Can you please make videos on data structures implemented in python? it would be awesome man!
@saianishmalla26464 жыл бұрын
Thank you! And actually I have been planning on doing thing right now I wanted tk start off by doing sorting algorithms from there I'll do data structure and so on.
@pythonenthusiast92924 жыл бұрын
@@saianishmalla2646 great !
@praneetkomandur65764 ай бұрын
great vid
@gastonjarju13704 жыл бұрын
Great explanation!
@saianishmalla26463 жыл бұрын
Thank you! glad it helped!
@dddddddddr2 жыл бұрын
Thank you!
@vm72402 жыл бұрын
how did you know that there will be a cycle ?
@codedoctor32653 жыл бұрын
Space - O(1) Time: O(N) class Solution: def reorderList(self, head: ListNode) -> None: """ Do not return anything, modify head in-place instead. """ fast = slow = head while fast and fast.next: fast = fast.next.next slow = slow.next prev = None cur = slow while cur: next_node = cur.next cur.next = prev prev = cur cur = next_node first = head second = prev while second and second.next: t1 = first.next first.next = second t2 = second.next second.next = t1 first = t1 second = t2
@tapaskumarswain98623 жыл бұрын
could u plz explain ur code.. it will be greater man