one test case is correct while some have time error and wrong answer. what is the mistake?
LL - k Reverse problem
Hi vipin
- In reverse func, while loop to reverse use condition while(count-- && curr!=NULL)
- In kreverse func , in while loop use condition while(head!=NULL)
It will get right answers. But - You are breaking the list in parts of k units each and not keeping track of parts. You need the build single combined list with every k units reversed.
Hope it helps
Mark resolved if satisfied
@shivansh1498 thanks my code is working fine but Is this approach which i was using was totally wrong and if it does i am not getting how to reverse k elements in a list without breaking.
The approach you are using to reverse k elements of a list is perfectly fine but you need the combine a single list. Refer to this for the correct approach :
1 Like