This will contain the solution of the Algorithm in Java