Count maximum path in grid

Last updated: April 11, 2026

Quick Overview

Given a grid of cells where each cell can either be traversable or blocked, count the maximum number of cells that can be visited in a single continuous path starting from any cell. The path can move in four directions (up, down, left, right) and cannot revisit cells. Return the maximum length of such a path as an integer.

SentinelOne
Coding & Algorithms
Software Engineer
SentinelOne
April 11, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

8

7

4,880 solved


Given a grid of cells where each cell can either be traversable or blocked, count the maximum number of cells that can be visited in a single continuous path starting from any cell. The path can move in four directions (up, down, left, right) and cannot revisit cells. Return the maximum length of such a path as an integer.

Coding interviews at SentinelOne 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
Time and space complexity analysis
Sorting and searching
Dynamic programming and memoization
Common algorithm patterns (sliding window, two pointers, BFS/DFS)
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
  • What if the input doesn't fit in memory?
  • Can you solve this iteratively instead of recursively (or vice versa)?
  • 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

This problem can be effectively solved using Depth-First Search (DFS) with backtracking. The reason DFS is suitable here is that we need to explore all potential paths from any starting cell, moving i...

Approach
  1. Initialize Variables: Start by defining a variable max_length to store the maximum path length found. Create a 2D list visited to keep track of which cells have been visited.

  2. **DFS Fun...


Submit Your Answer
Markdown supported

Related Questions