Keep Only the Last N
mediumQuestion 496Write a function deque<int> keepLast(const vector<int>& v, int n) that returns a deque holding only the last n elements of v, in their original order. If v has n or fewer elements, all of them are kept. You may assume n >= 1.
The tests print the returned deque separated by spaces. For v = {1, 2, 3, 4, 5} and n = 3 the output is exactly what is shown in Expected Output.
For v = {1, 2} and n = 5 the output is: 1 2
Do NOT write a main function.
Expected output
3 4 5 1 2
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
STL ContainersQueues
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.