Computer Science, asked by dinesha3980, 11 months ago

Given a array ,what is the min number of numbers you need to change in array to make it a ap.

Answers

Answered by danielshivasai
0

You can change any element of the array to any integer. The task is to find the minimum number of change(s) required to make the given array an Arithmetic Progression with the common difference . Examples: Input : N = 4, d = 2 arr[] = {1, 2, 4, 6} Output : 1 Explanation: change a[0]=0.

Answered by priyarksynergy
0

Explanation:

Given an array arr [] of N   integers and a number d . You can change any element of the array to an integer. The task is to find the minimum number of change(s) required to make the given array an Arithmetic Progression with the common difference d .

     We are given the values of d   and an. So, we will find the value of a0 for all values of i, where 1<=i<=n and store the frequency of occurrences of a0 for different values of i.

    Where maximum frequency of a0 signifies the total number of elements in the array for which the value of the first term in the AP is the same.

Example:-  

   Input : N = 4, d = 2

       arr[] = {1, 2, 4, 6}

  Output : 1

  Explanation: change a[0]=0.

  So, new sequence is 0, 2, 4, 6 which is an AP.

Similar questions