Tap here to switch tabs
Problem
Submissions

Problem: Find the Power of K-Size Subarrays I

med
30 min
Try to solve the Find the Power of K-Size Subarrays I problem.

Statement

You are given an array of integers nums of length n and a positive integer k.

The power of an array is defined as:

  • Its maximum element if all of its elements are consecutive and sorted in ascending order (meaning each adjacent element differs by exactly +1+1).

  • −1-1 otherwise.

Return an array of integers results of size n −- k +1+ 1, where results[i] is the power of the subarray of size k starting at index i.

Constraints:

  • 1≤n==1 \leq n == nums.length ≤500\leq 500

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • 1≤k≤n1 \leq k \leq n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Power of K-Size Subarrays I

med
30 min
Try to solve the Find the Power of K-Size Subarrays I problem.

Statement

You are given an array of integers nums of length n and a positive integer k.

The power of an array is defined as:

  • Its maximum element if all of its elements are consecutive and sorted in ascending order (meaning each adjacent element differs by exactly +1+1).

  • −1-1 otherwise.

Return an array of integers results of size n −- k +1+ 1, where results[i] is the power of the subarray of size k starting at index i.

Constraints:

  • 1≤n==1 \leq n == nums.length ≤500\leq 500

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • 1≤k≤n1 \leq k \leq n