commit 2b6b0d00c7816e658165387dd04eb664cd4ddf38 parent c69cdb8dc8b58d2a5e0f48e95a1b731eb6e6dc26 Author: Dimitrije Dobrota <mail@dimitrijedobrota.com> Date: Thu, 29 Aug 2024 21:21:16 +0200 1 Random Problem Diffstat:
A | Problems/3254.cpp | | | 19 | +++++++++++++++++++ |
M | README.md | | | 1 | + |
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/Problems/3254.cpp b/Problems/3254.cpp @@ -0,0 +1,19 @@ +class Solution { + public: + vector<int> resultsArray(const vector<int> &nums, int k) const { + const int n = size(nums); + vector<int> res(n - k + 1, -1); + + for (int i = 0; i <= n - k; i++) { + for (int j = i + 1; j < i + k; j++) { + if (nums[j - 1] + 1 == nums[j]) continue; + i = j - 1; + goto next; + } + res[i] = nums[i + k - 1]; + next:; + } + + return res; + } +}; diff --git a/README.md b/README.md @@ -1334,3 +1334,4 @@ for solving problems. | 3228 | Medium | [Maximum Number of Operations to Move Ones to the End](Problems/3228.cpp) | | 3239 | Medium | [Minimum Number of Flips to Make Binary Grid Palindromic I](Problems/3239.cpp) | | 3249 | Medium | [Count the Number of Good Nodes](Problems/3249.cpp) | +| 3254 | Medium | [Find the Power of K-Size Subarrays I](Problems/3254.cpp) |