Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created September 17, 2019 23:04
Show Gist options
  • Save surinoel/9980282095d317c079ec7decb22e1c70 to your computer and use it in GitHub Desktop.
Save surinoel/9980282095d317c079ec7decb22e1c70 to your computer and use it in GitHub Desktop.
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
vector<int> answer;
int size = commands.size();
for (int test_case = 0; test_case < size; test_case++) {
int i, j, k;
i = commands[test_case][0];
j = commands[test_case][1];
k = commands[test_case][2];
vector<int> subarray(array.begin() + i - 1, array.begin() + j);
sort(subarray.begin(), subarray.end());
answer.push_back(subarray[k - 1]);
}
return answer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment