Implement exponentiation and fill grid distances | Meta Interview Question