Тёмный
AlgoSkills
AlgoSkills
AlgoSkills
Подписаться
Комментарии
@Mistake-xd9xe
@Mistake-xd9xe 4 месяца назад
good approch bro
@munavarpm5342
@munavarpm5342 5 месяцев назад
Thanks sir, Good presentation
@aynuayex
@aynuayex 7 месяцев назад
here is iteratively class Solution: def removeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]: # reverse the list pre, cur = None, head while cur: temp = cur.next cur.next = pre pre = cur cur = temp # remove the node that is less than the max(greater value to the right) head = pre cur = pre.next max = pre.val while cur: if cur.val < max: pre.next = cur.next cur.next = None cur = pre.next else: max = cur.val pre = cur cur = cur.next # reverse the list again pre, cur = None, head while cur: temp = cur.next cur.next = pre pre = cur cur = temp return pre
@sujaydas5024
@sujaydas5024 9 месяцев назад
public class Solution { public ListNode RemoveNodes(ListNode head) { ListNode current = head; ListNode l = current; ListNode r = current.next; ListNode prev = null; ListNode dummy = new ListNode(0); dummy.next = current; while(current != null) { while(l != null && r != null) { if(l.val<r.val) { if(prev!=null) { prev.next = r; } else { dummy.next = r; prev = r; } l = r; r = r.next; } else { prev = l; l = l.next; r = r.next; } } l = current; r = current.next; prev = null; current = current.next; } return dummy.next; } } my code fails in 9th test case. According to my initial analysis it should work. anything wrong ?
@deepayubipinchandraninama
@deepayubipinchandraninama 9 месяцев назад
You can just sort the array first and get the elements at 0 and 1 position and then apply the condition
@chetansah207
@chetansah207 10 месяцев назад
loved ur explanation on this problem, the way u explained the hashmap to us, tht helped alot in understanding the working of the code, none in the youtube community does tht and it gets super confusing, keep up the good work, Thank You!!!!!!!!!
@algoskills
@algoskills 10 месяцев назад
I'm so glad it helped you!
@avichaljain4155
@avichaljain4155 Год назад
Thank you so much
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with my course - bit.ly/algoskillsyt
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with my course - bit.ly/algoskillsyt
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with my course - bit.ly/algoskillsyt
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with my course - bit.ly/algoskillsyt
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with my course - bit.ly/algoskillsyt
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with my course - bit.ly/algoskillsyt
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with my course - bit.ly/algoskillsyt
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with my course - bit.ly/algoskillsyt
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with this course - bit.ly/algoskillsyt
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with my course - bit.ly/algoskillsyt
@fortznite8150
@fortznite8150 Год назад
Interesting but can you do it iteratively?
@algoskills
@algoskills Год назад
I have not attempted but it should be possible to do it iteratively too
@motivationkiaag1601
@motivationkiaag1601 Год назад
For iteratively You have to first reverse the list . Then traverse it from end ( it means from new head ) then take a Max value and check if a number is greater then current value the update max and if you get smaller value then you have to make connection between current node to those node which have greater value then finally reverse again the list and return head of list . I hope it helps you .
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with this course - bit.ly/algoskillsyt
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with this course - bit.ly/algoskillsyt
@algoskills
@algoskills Год назад
MASTER data structures and algorithms with this course - bit.ly/algoskillsyt