Added solution-2 for a variation of the problem in solution-1