 # Well, that was fun. (Java, no floating-point in map)

#1

No Pair class in Java8: check
No GCD function in Math: check
Floating points here acting like floating points in real life: X (seriously, how does everyone storing calculated floats as map keys get away with that??)

``````public class Solution {

public class Pair<L,R> {
private final L left;
private final R right;

public Pair(L left, R right) {
this.left = left;
this.right = right;
}

public L getLeft() { return left; }
public R getRight() { return right; }

@Override
public int hashCode() { return left.hashCode() ^ right.hashCode(); }

@Override
public boolean equals(Object o) {
if (!(o instanceof Pair)) return false;
Pair pairo = (Pair) o;
return this.left.equals(pairo.getLeft()) &&
this.right.equals(pairo.getRight());
}
}

public int gcd(int a, int b) { return b==0 ? a : gcd(b, a%b); }

public int maxPoints(ArrayList<Integer> a, ArrayList<Integer> b) {
int retval = 0;
for (int left = 0; left < a.size(); ++left) {
// {num, den} -> count
Map<Pair<Integer, Integer>, Integer> slopeCount = new HashMap<>();
int overlap = 1;
int vertical = 0;
int maxSlopes = 0;
for (int right = left + 1; right < a.size(); ++right) {
if (a.get(left) == a.get(right) && b.get(left) == b.get(right)) {
overlap++;
} else if (a.get(left) == a.get(right)) {
vertical++;
} else {
int num = b.get(left) - b.get(right);
int den = a.get(left) - a.get(right);
int div = gcd(num, den);
num /= div;
den /= div;
Pair<Integer, Integer> frac = new Pair<>(num, den);
slopeCount.put(frac, slopeCount.getOrDefault(frac, 0) + 1);
maxSlopes = Math.max(slopeCount.get(frac), maxSlopes);
}

}
int localMax = Math.max(maxSlopes + overlap, vertical + overlap);
retval = Math.max(retval, localMax);

}  // end for
return retval;
}
}``````