Doordash | Phone Screen | Longest path duplicate numbers within a Matrix
Anonymous User
13130

Given an integer matrix, find the length of the longest path that have same values. The matrix has no boundary limits. (like, Google Maps - see edit for context)

From each cell, you can either move to two directions: horizontal or vertical. You may NOT move diagonally or move outside of the boundary.

nums = [
[1,1],
[5,5],
[5,5]
]

Return 4 ( Four 5's).


Thoughts
I used DFS to traverse the grid while keeping tracking of the max of longest path with same values. This solved the problem for a boundary contrained matrix grid. I got rejection for it. I wonder if its because I couldnt solve the problem for an infinite grid, but for a 33 min interview i thought i did decent. (45mins - 15 min intro + problem solving). Is there a better alternative?

EDIT - Regarding infinite grid . i asked for clarity, but he said its a matrix with no boundaries and refused to expand on it for further enquiry. So, I requested to for a limited boundary and expand it to a GoogleMaps like solution.
So, i gave a solution with limited boundary, and expanded it to a solution that is like GoogleMaps. with huge boundaries.

As I have interviewed many ppl, I consider not giving alot of clarity in a 45 min interview is quite annoying tbh. it was my weirdest interviews among 15 interview i had during that time period.

Comments (35)