Find K-Level Permutation

Problem Overview

  • Core task: Given N and K, arrange numbers 1..N so that across all N-K+1 windows of length K, the largest window sum minus the smallest is at most 1.
  • Inputs/outputs: Input N, K; output a permutation of 1..N meeting this condition.
  • Constraints: Not specified.
  • Domain: Array permutation and sliding window sums, focusing on balanced segments.
  • Asked in Amazon interviews; a coding interview problem and common interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: