-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathMinSteps.java
More file actions
37 lines (32 loc) · 864 Bytes
/
MinSteps.java
File metadata and controls
37 lines (32 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package Array;
import java.util.ArrayList;
/**
* Author - archit.s
* Date - 18/08/18
* Time - 1:54 PM
*/
public class MinSteps {
public int coverPoints(ArrayList<Integer> A, ArrayList<Integer> B) {
int n = A.size();
int result = 0;
for (int i = 0; i < n-1; i++) {
final int DistA = Math.abs(A.get(i + 1) - A.get(i));
final int DistB = Math.abs(B.get(i + 1) - B.get(i));
if(A.get(i + 1).equals(A.get(i))){
result += DistB;
}
else if (B.get(i+1).equals(B.get(i))){
result += DistA;
}
else{
if(DistB < DistA){
result += DistA;
}
else {
result += DistB;
}
}
}
return result;
}
}