Kodewick
Start learning →
Basic←→0 / 60

Race podium

#052BasicAlgorithmsvector5 min

After the race, times holds everyone's time in seconds. Only the three fastest stand on the podium. Write podium(times): sort fastest first and keep just the first 3; with fewer than 3 runners, keep them all.

Examples
podium({58, 52, 61, 55})→[52, 55, 58]
podium({70, 65})→[65, 70]
The functionvector<int> podium(vector<int> times)
main.cpp
#include <algorithm>
#include <vector>
using namespace std;

vector<int> podium(vector<int> times) {
    // your code here: sort, keep the first 3
    return times;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.