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
Matrix Transformation with Edge Cases
00:00
5 left

Matrix Transformation with Edge Cases

MediumPython

Problem

Transform a 2D matrix from one input format into a specified output format, handling large test cases with tricky edge cases

Asked in the Round 2 - Technical Assessment stage. The candidate gave a garbled example: input [[1,2],[3,4]] -> output [[1,3],[4,10]]; this output is the 2D prefix sum matrix.

Implement prefix_sum_matrix(matrix). For each position (r, c), return the sum of all input values in the rectangle from (0, 0) through (r, c).

Contract

Input is a non-empty rectangular list of lists of integers. Return a matrix with the same dimensions.

Constraints

  • 1 <= rows, columns <= 1000
  • rows * columns <= 10^6
  • -10^9 <= matrix[r][c] <= 10^9
  • The matrix is non-empty and rectangular

Function Signature

def prefix_sum_matrix(matrix):
Interviewer

Your question is Matrix Transformation with Edge Cases. 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.