Solution to cacheMatrix