=============================================================
Problem Statement
����
A sequence of integers
(a1, a2, a3, ..., an)
is called arithmetic if a2  a1 = a3  a2 = a4  a3 = ... In order to make the given sequence arithmetic, you are allowed to replace each element with a different integer value (no fractions allowed). Unfortunately, each such replacement has an associated cost of 1. Return the minimum cost required to make the given sequence arithmetic. If the given sequence is already arithmetic, return 0.
Definition
����
Class:
ArithmeticReplace
Method:
howMany
Parameters:
int[]
Returns:
int
Method signature:
int howMany(int[] seq)
(be sure your method is public)
����
Notes

An element can be replaced by a value less than 10000 or greater than 10000.
Constraints

seq will contain between 3 and 50 elements inclusive.

Each element of seq will be between 10000 and 10000 inclusive.
Examples
0)
����
{1,4,7,11}
Returns: 1
Replacing the 11 with a 10 we get an arithmetic sequence.
1)
����
{10,5,0,5,10,15}
Returns: 0
This sequence is already arithmetic.
2)
����
{157, 119, 15, 5, 25}
Returns: 2
Replacing the first two elements with 55 and 35 we get an arithmetic sequence.
3)
����
{1,2,4,7,11,16,22,29,37,46,56,67,79,92,106}
Returns: 13
4)
����
{1,100,10,40,2,200,71,250,99,103,325}
Returns: 7
===============================================
.............
we add solutions...
can anybody make it further correct...
coz we are able to find out the correct result by adding further code to that but that doesn't make the series in AP
see the question is asking that find out how many numbers we should add to make the series to be in AP .. even if we find the anwer we are not able to make the series in AP...
here is my code

import java.util.Arrays;
public class ArithmeticReplace {
int counter = 0;
public int howMany(int[] seq) {
Arrays.sort(seq);
System.out.println("length " + seq.length);
for (int i = 0; i < seq.length; i++)
System.out.print(seq[i] + " ");
int dif = 0;
System.out.println("diff " + dif);
int[] a = new int[seq.length  1];
for (int i = 0; i < seq.length  1; i++) {
// System.out.println("each diff " + (seq[i + 1]  seq[i]));
a[i] = seq[i + 1]  seq[i];
System.out.print(" " + a[i]);
}
System.out.println();
System.out.println("a length " + a.length);
Arrays.sort(a);
for (int i = 0; i < a.length; i++)
System.out.print(" " + a[i]);
int n = 1, k = 1, l = 0;
for (int i = 0; i < a.length  1; i++) {
if (a[i + 1] == a[i]) {
n++;
l = a[i];
} else {
if (n > k) {
k = n;
l = a[i];
}
n = 1;
}
}
System.out.println();
System.out.println("l " + l);
System.out.println("k " + k);
dif = l;
// seq.lengthk*2;
for (int i = 0; i < seq.length  1; i++) {
if (seq[i + 1]  seq[i] != dif) {
counter++;
}
}
// if (counter > 0)
// counter++;
return counter;
}
/**
* @param args
*/
public static void main(
String[] args) {
// TODO Autogenerated method stub
ArithmeticReplace ar = new ArithmeticReplace();
int k = ar.howMany(new int[] {1,100,10,40,2,200,71,250,99,103,325});
System.out.println("k>>>> " + k);
}
}

thanks
[ April 09, 2006: Message edited by: amit taneja ]
[ April 10, 2006: Message edited by: amit taneja ]