I want to add the solution for this problem in java. Kindly allow me to contribute in this repository.