1 class Solution { 2 public: 3 vector<int> resultsArray(vector<int>& nums, int k) { 4 int n = nums.size(); 5 int cnt = 0; 6 vector<int> ans(n - k + 1, -1); 7 for (int i = 0; i <= n - k; i++) { 8 bool valid = true; 9 for (int j = i + 1; j < i + k; j++) { 10 if (nums[j] - nums[j - 1] != 1) { 11 valid = false; 12 break; 13 } 14 } 15 if (valid) { 16 ans[i] = nums[i + k - 1]; 17 } 18 } 19 return ans; 20 } 21 };