We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

not really a better solution. your solution requires a new y vector. so the space complexity is O(n), while the solution above did everything inplace, so its space complexity is O(1).

## Arrays - DS

You are viewing a single comment's thread. Return to all comments →

I'd say a much bettery solution (for c++14) is:

not really a better solution. your solution requires a new y vector. so the space complexity is O(n), while the solution above did everything inplace, so its space complexity is O(1).

And I'd say much better is simply