Pergunta de entrevista da empresa Google

1. manage the import headers 2. sort an array based on the distance to certain origin

Resposta da entrevista

Sigiloso

2 de mai. de 2013

public static ArrayList sortWithFn(ArrayList a) { ArrayList a1 = new ArrayList(); for (Float f : a) { a1.add(new NumAndDistance(f.floatValue())); } Collections.sort(a1); ArrayList a2 = new ArrayList(); for (NumAndDistance nd : a1) { a2.add(new Float(nd.f)); } return a2; } public class NumAndDistance implements Comparable { float f; float dist; public NumAndDistance(float f) { this.f = f; dist = distF(f); } @Override public int compareTo(NumAndDistance o) { return (new Float(f)).compareTo(o.f); } }