Implemented solution for 1.d