Company: Amazon_20nov
Difficulty: medium
Minimum Operations to Sort Products Problem Description You are given an array serial of n distinct integers representing product serial numbers placed in a row on a shelf, and an integer k . In one operation you may pick any index i with 0 <= i < n - k and swap the products at positions i and i + k (0-indexed). You may perform this operation any number of times, in any order. Your goal is to arrange the shelf in ascending order of serial numbers. Return the minimum number of operations required, or -1 if ascending order can never be reached. Input Format The first line contains the integer n . The second line contains n space-separated integers, serial[0] ... serial[n - 1] . The third line contains the integer k . Output Format Print a single integer: the minimum number of operations, or -1 if sorting is impossible. Constraints 1 <= n <= 2000 1 <= k <= n 0 <= serial[i] <= 10^9 All serial numbers are distinct. Examples Example 1 Input: 5 6 4 1 2 3 2 Output: 3 Ex