Apply commands to transform a matrix | Capital One Interview Question