+ 2
Erase and keep only Unique elements from not sorted data
Hi Please refer code below: I have tried to remove all repeated numbers from not sorted input data. It is inplace operation and I belive time complexity is O(N) where as space complexity is O(N) for storing data into unordered map... Is time and space complexity correct? Also is it possible to get better solution from this for non sorted data ? If yes , please suggest. https://code.sololearn.com/ctapIM5P1OzC/?ref=app
4 Respuestas
+ 5
You might wanna look at std::unique () to achive this.
Or just go through different implementations of it in case you don't want to use the function as it is and just want some inspiration to maybe improve your implementation.
-----
https://en.cppreference.com/w/cpp/algorithm/unique
+ 3
Ketan Lalcheta, theoretically, a hash map could improve on your complexity score. See if unordered_map from the STL could handle things better and faster for you in one pass at roughly O(1) lookup/storage.
+ 1
I tried to go through this link...
It seems unique from stl works only for sorted data only ..
Right ?
- 2
Hi the answer is 5.0 is it correct?!