Insertion at tail in O(1)

If i have to input n elements at the tail of linked list, how can i do it in O(n) time.

There’s one way by inserting n elements at head and then reversing the linked list. Is there any other way of doing the same.

Please refer to this code.
I have included two seperate input functions. One which takes exactly n inputs and other which takes input till -1.

Code - https://ide.codingblocks.com/s/91037

Use these functions for input linked lists for insertion at tail.

1 Like

Thanks a lot. Really helpful

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.