DEV Community

Discussion on: 🎯Merge two sorted arrays without using any extra space🎯

Collapse
 
trueneu profile image
Pavel Gurkov

Do you think it's an optimal solution or it can be improved?

Collapse
 
kaiwalyakoparkar profile image
Kaiwalya Koparkar

This is an O(n) Solution whereas all others are O(n^2). According to me, any other optimal method would take the same O(n) time. So according to me, this is one of the optimal approaches. If you get one lesser than this please do let me know...😀

Collapse
 
trueneu profile image
Pavel Gurkov

Um, this is not O(n) but O(nlogn), unless you can sort in linear time.

And there are a number of others with the same upper limit.

It seems to me that this cannot be done linearly, but I wanted to ask what's your thoughts on this.

Thread Thread
 
kaiwalyakoparkar profile image
Kaiwalya Koparkar

I got your point. I found this as the only optimal way (As far as I found)