Time Complexity
The entire linked list is traversed thrice, so the time complexity will be O(n) + O(n) + O(n), which amounts to O(n).
The entire linked list is traversed thrice, so the time complexity will be O(n) + O(n) + O(n), which amounts to O(n).