Given an array of n-elements. Given array is a permutation of some Arithmetic Progression. Find the minimum number of De-arrangements present in that array so as to make that array an Arithmetic progression.
Input : arr = [8, 6, 10 ,4, 2] Output : Minimum De-arrangement = 3 Explanation : arr = [10, 8, 6, 4, 2] is permutation which forms an AP and has minimum de-arrangements. Input : arr = [5, 10, 15, 25, 20] Output : Minimum De-arrangement = 2 Explanation : arr = [5, 10, 15, 20, 25] is permutation which forms an AP and has minimum de-arrangements.
As per property of Arithmetic Progression our sequence will be either in increasing or decreasing manner. Also, we know that reverse of any Arithmetic Progression also form another Arithmetic Progression. So, we create a copy of original array and then once sort our given array in increase order and find total count of mismatch again after that we will reverse our sorted array and found new count of mismatch. Comparing both the counts of mismatch we can find the minimum number of de-arrangements. Time Complexity = O(nlogn).
Minimum Dearrangement = 2
- Count of AP (Arithmetic Progression) Subsequences in an array
- Check whether Arithmetic Progression can be formed from the given array
- Change one element in the given array to make it an Arithmetic Progression
- Convert given array to Arithmetic Progression by adding an element
- Arithmetic Progression
- Longest Arithmetic Progression | DP-35
- Ratio of mth and nth term in an Arithmetic Progression (AP)
- Program to print Arithmetic Progression series
- Find the missing number in Arithmetic Progression
- Program for N-th term of Arithmetic Progression series
- Longest arithmetic progression with the given common difference
- PHP program to print an arithmetic progression series using inbuilt functions
- Longest string in non-decreasing order of ASCII code and in arithmetic progression
- Removing a number from array to make it Geometric Progression
- Probability of a key K present in array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar