I am getting one wrong testcase

one testcases is getting TLE error. Code: https://ide.codingblocks.com/s/655744

hi @mitrapranav0027_5d705c8b616e0add, let me check once

Did you find the mistake?

@mitrapranav0027_5d705c8b616e0add, I checked your code its correct even submitted on gfg it worked then finally it came to my mind that when u r inserting at tail again and again it will be o(n^2) hence failing.

@mitrapranav0027_5d705c8b616e0add to actually check this thing comment out the code of merging and printing and just take the input all other test case will show wrong answer but that one will show TLE again which means that in taking input only its TLE.

You can do the same using array it will pass (i tried check this : https://ide.codingblocks.com/s/655784 )

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.

So how else am I supposed to do this? Building Linked List at tail is O(n^2) only as it iterates (1+2+3+…+n). Your answer is for merging sorted arrays which is not what the question says.

hi @mitrapranav0027_5d705c8b616e0add
Refer this
https://www.techiedelight.com/efficiently-merge-k-sorted-linked-lists/
Using min heaps it’s O(NlogK)…

@mitrapranav0027_5d705c8b616e0add
Is there anything else??

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.