Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Cache-Friendly Matrix Multiplication
00:00
5 left

Cache-Friendly Matrix Multiplication

HardPython

Problem

Zoox's onboard perception and planning computations use matrix multiplication for feature transformations. Implement matrix multiplication with a cache-conscious access pattern rather than the straightforward triple loop.

Given matrix A with dimensions m x n and matrix B with dimensions n x p, return their product C = A * B, with dimensions m x p. Your implementation must use both matrix blocking and a transposed representation of B so that repeated inner-loop accesses are contiguous in memory.

The block size is provided as an argument. Blocks at the matrix boundaries may be smaller than the requested block size.

Formal Specification

Implement cache_optimized_multiply(A, B, block_size):

  • A is a non-empty list of m rows, each containing n integers.
  • B is a non-empty list of n rows, each containing p integers.
  • block_size is a positive integer.
  • Return a list of m rows, each containing p integers, where C[i][j] = sum(A[i][k] * B[k][j] for k in range(n)).

Constraints

  • 1 <= m, n, p <= 512
  • 1 <= block_size <= 512
  • A has dimensions m x n
  • B has dimensions n x p
  • -10^4 <= A[i][k], B[k][j] <= 10^4
  • All matrix rows are rectangular

Function Signature

def cache_optimized_multiply(A, B, block_size):
Interviewer

Your question is Cache-Friendly Matrix Multiplication. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.