Count minimum cost in matrix

Last updated: May 23, 2026

Quick Overview

Given a matrix of integers, calculate the minimum cost to traverse from the top-left corner to the bottom-right corner, where the cost is defined as the sum of the values of the cells visited. You can only move either down or right at any point in time. Return the minimum cost as an integer.

Booking.com
Coding & Algorithms
Software Engineer
Booking.com
May 23, 2026
Software Engineer
Take-home Project
Coding & Algorithms
Easy

49

6

3,641 solved


Given a matrix of integers, calculate the minimum cost to traverse from the top-left corner to the bottom-right corner, where the cost is defined as the sum of the values of the cells visited. You can only move either down or right at any point in time. Return the minimum cost as an integer.

Booking.com uses this problem in the Take-home Project to evaluate your algorithmic thinking. They expect you to discuss multiple approaches, analyze trade-offs between them, and implement the optimal solution with clean, readable code.

What the Interviewer Expects
  • Identify the correct data structure and algorithm for the problem
  • Write clean, bug-free code with proper variable naming
  • Analyze time and space complexity correctly
  • Handle basic edge cases (empty input, single element)
  • Communicate your thought process while coding
Key Topics to Cover
Tree structures and recursion
Time and space complexity analysis
Dynamic programming and memoization
Sorting and searching
Binary search and divide and conquer
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you test this solution thoroughly?
  • How would you parallelize this solution?
  • Can you solve this in a single pass?
  • Can you optimize the space complexity of your solution?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Problem Analysis

The problem requires finding the minimum cost path from the top-left corner to the bottom-right corner of a matrix, which consists of integers representing costs. The constraints specify that we can o...

Approach
  1. Initialization: Create a 2D DP array of the same size as the input matrix, initialized to zero. This array will store the minimum cost to reach each cell.
  2. Base Case: Set the starting ce...

Submit Your Answer
Markdown supported

Related Questions