Algos in Java & Scala