Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
Can someone explaine how this works please?
Not entirely sure where you're getting O(n^2) from. Size is O(1), sort is O(nlogn) and array lookup is O(1).
Although, even with this miscalculation, you'd be right in asserting that O(n) solutions do exist.
This is an amazing approach!
Just to improve it even more, you all can use std::partial_sort to just sort a certain number of elements.
Like, std::partial_sort(ages.begin(), ages.begin()+2, ages.end(), std::greater{}); this line with just sort 2 elements, the two greater elements actually.
And that would sort only two elements leaving the others disordered.
If you're doing some challenges in c++ in this website, I recommend you all to visit https://en.cppreference.com/w/cpp/algorithm
There are a bunch of useful functions and classes there (but somewhat complicated to actually use correctly).
This is O(n^2) order. Slowest approach.
amazing