This is a verified interview question from Paloalto-network. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Hands on Programming" covers key patterns like Arrays.
"### Problem You are given an integer N representing the size of the array A and an integer array A. The goal is to find the count of distinct values of K from 1 to N that allow you to transform the given array into sorted order using swap operations with the following constraints: - The swap operation involves swapping elements at indices i and i + K. - The swap operation can only be performed if the absolute difference between the indices is K. ### Input - input1: An integer value N, representing the size of the array A. - input2: An integer array A. ### Output Return an integer value, representing the count of distinct values of K from 1 to N that allow you to transform the given array into sorted order using the above operations. ### Constraints - 1 <= N <= 1000 - The elements of the array A are distinct integers between 1 and N. ### Test Cases - Example 1: - input1: 6 - input2: [2,3,5,4,1,6] - output: 2 - Example 2: - input1: 4 - input2: [1,2,3,4] - output: 4"
Join thousands of developers practicing for Paloalto-network.