Greedy on grid

Last updated: March 1, 2026

Quick Overview

Given a grid of integers, implement a greedy algorithm to find the maximum sum of values collected by moving from the top-left corner to the bottom-right corner, only being allowed to move right or down. The input will be a 2D array representing the grid, and the output should be a single integer representing the maximum sum.

Shopify
Coding & Algorithms
Software Engineer
Shopify
March 1, 2026
Software Engineer
Take-home Project
Coding & Algorithms
Medium

372

10

4,601 solved


Given a grid of integers, implement a greedy algorithm to find the maximum sum of values collected by moving from the top-left corner to the bottom-right corner, only being allowed to move right or down. The input will be a 2D array representing the grid, and the output should be a single integer representing the maximum sum.

Coding interviews at Shopify focus on problem-solving approach as much as the final solution. The interviewer wants to see you break down the problem, consider edge cases, and optimize iteratively. Communication throughout the process is key.

What the Interviewer Expects
  • Recognize the underlying problem pattern (sliding window, two pointers, BFS/DFS, etc.)
  • Discuss multiple approaches and trade-offs before coding
  • Implement an optimal solution with clean, production-quality code
  • Handle all edge cases including boundary conditions and invalid input
  • Optimize both time and space complexity with clear justification
  • Test your solution systematically with well-chosen examples
Key Topics to Cover
Hash maps and frequency counting
Graph algorithms and traversal
Sorting and searching
Binary search and divide and conquer
Dynamic programming and memoization
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 parallelize this solution?
  • Can you solve this in a single pass?
  • Can you solve this iteratively instead of recursively (or vice versa)?
  • What happens if the input contains duplicates?
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 us to find the maximum sum of values collected while traversing a grid from the top-left corner to the bottom-right corner, with restrictions on movement (only right or down). Thi...

Approach
  1. Initialization: Create a 2D list dp of the same dimensions as the grid to store the maximum sum at each cell.
  2. Base Case: Set dp[0][0] to grid[0][0] since that's the starting point....

Submit Your Answer
Markdown supported

Related Questions