Skip to main content

Medium LL ✔

  1. Middle of LL
    • For even number of item, middle is the first item of last part
  2. Reverse LL - Iterative
    • Bruteforce uses single stack
    • Iterative uses three pointer(prev, next, current)
  3. Reverse LL - Recursive
    1. 31 March, 2026: 00.26.54 ❌
      • Iterating to the last node and pointing head->next = head create a cycle
      • Ierate to the second last node, so that head->next(last node) can point head second last node
      1 2 3 4 5
      2 2 2 2 2
      3 3 3 3 3
      4 4 4 4
      5 5 5 5
      head = 4
      head->next = 5
      head->next->next = 5->4
      head->next = 4->NULL
      head = 3
      head->next = 4
      head->next->next = 4->3
      head->next = 3->NULL
  4. Detect Loop
  5. Begin of Loop
    1. 30 March, 2026: 00.12.52 ✔
      • In Loop condition use fast && fast->next
      • If slow and fast are not equal, loop not found, begining is NULL
      • The iteration to find begining will run untill slow and fast are equal.
      • head to begining node is equal to n*i+/-k
      • Return node will be slow/fast
  6. Length of Loop
    1. 30 March, 2026: 00.10.57 ✔
      • After loop detection both pointer point to same node, move one to next
      • Intialize counter with 1 as the current one will not consider in the loop
  7. Pallindrome
  8. Segrregate odd and even
    1. 31 March, 2026: 00.18.34 ❌
      • Failed at implmentation
        • Whatever is assigned to current->next, current usually becomes that value
          current->next = odd;
          current = odd;
  9. Remove Nth node from the back
  10. Delete Middle Node
    • Optimization done with only TortoiseHare method with extra pointer with NULL value
    • Use a NULL pointer approach to remove any type of remove operation
  11. Sort LL
    1. 31 March, 2026: 00.23.41 ❌
      • Failed at implmentation
      • Recursive call based on mid
      • Merge two part of the list
  12. Sort a LL of 0's 1's and 2's by changing links
    1. 31 March, 2026: 00.16.54 ❌
      • Failed at implementation
      • No need merge sort or DNF
      • Consider the case if there is no 0 or 1
  13. Intersection
    1. 31 March, 2026: 00.16.54 ❌
      • Failed at optimization
      • Check the same way, but in O(1)O(1) time complexity, if you found NULL during traversing any list, reassign the current pointer again as head.
      • Try to solve it with help of it's length
  14. Add 1 to a number represented by LL
    • Keep reverse function seperate
  15. Add 2 numbers in LL
    • List should be in reverse order