Working algorithm, checking in correct solution output!