working algorithm commited