DS and Algo code in Java