please explain me how is the above mentioned question possible
How can we append more elements to the front than those are present in the linked list
@snatchit think of it in a circular manner. Like if there are 7 elements in linked list and k = 10 so you first append 7 elements (len of list) and you just start the process again after that, it’s not like the list has ended, there are still elements in the back and a head where insertion can happen. You can pick an element from the end and insert it in front as many times as you want… Do a dry run once for more clarity
mam can you please give an example of this?
@snatchit for eg n = 3
list = 1, 2, 3
and k = 7
now you have to pick the last element 7 times and bring it to the front
so the list changes like this after each iteration
3 1 2
2 3 1
1 2 3
3 1 2
2 3 1
1 2 3
3 1 2
so effectively, the change happened for 1 node only.
so we can write k as k = k % n
in this case k = 7%3 = 1
I hope it is clear now
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.