diff --git a/kt/find-the-power-of-k-size-subarrays-i.kt b/kt/find-the-power-of-k-size-subarrays-i.kt new file mode 100644 index 0000000..9a3acb8 --- /dev/null +++ b/kt/find-the-power-of-k-size-subarrays-i.kt @@ -0,0 +1,29 @@ +class Solution { + fun resultsArray( + nums: IntArray, + k: Int, + ): IntArray { + if (k == 1) { + return nums + } + + val result = IntArray(nums.size - k + 1) { -1 } + (0.. + if (nums[i] == nums[i + 1] - 1) { + consecutive + 1 + } else { + 1 + } + } + .withIndex() + .drop(1) + .filter { + it.value >= k + } + .forEach { + result[it.index - k + 1] = nums[it.index] + } + return result + } +}