Wrote the solution for the cachematrix problem