Added Advanced solution in Java