My code is timing out as it is inefficient. Program takes in a line of n integers. Each consecutive pair of integers represents a single point (x, y) this is an example of input :
-5 -10 20 25 30 2 -1 -40
Output:
java.awt.Point[x=-5,y=-10]
java.awt.Point[x=-1,y=-40]
java.awt.Point[x=20,y=25]
java.awt.Point[x=30,y=2]
4
I have the code to sort all the points. They are sorted from smallest to biggest. Where "x" values are equal, I then check the y value. The PROBLEM is this: I need to count how many times a point is bigger than every other point (both x and y). So in the above example, the answer is 4.
The fourth point is bigger than the first and second point.
The third point is bigger than the first and second.
Which results in 4.
If points are equal, also increase the counter.
For really really longer line of integers, my program times out (killed). I can't provide the input here as it is way too long. How else can I improve the complexity?
public void calculateDomination(){
int counter =0;
int sizeOfList = this.coordinateList.size();
for(int i = 0; i < sizeOfList ; i++){
for(int j = i+1; j < sizeOfList ; j++){
if(((this.coordinateList.get(i).x) < (this.coordinateList.get(j).x)) && ((this.coordinateList.get(i).y) < (this.coordinateList.get(j).y)) ){
counter++;
}
else if(((this.coordinateList.get(i).x) == (this.coordinateList.get(j).x)) && ((this.coordinateList.get(i).y) == (this.coordinateList.get(j).y)) ){
counter++;
}
}
}
System.out.println(counter);
}