Length of Longest V-Shaped Diagonal Segment
A hard-tier problem at 34% community acceptance, tagged with Array, Dynamic Programming, Memoization. Reported in interviews at Visa and 0 others.
You're looking at a hard dynamic programming problem that Visa is confirmed asking. The acceptance rate sits at 34%, which means most people either miss the V-shape pattern entirely or build a slow brute-force solution that times out. The trick is recognizing that you need to track diagonal direction changes and use memoization to avoid recomputing overlapping states. If this problem hits your live assessment and you blank on the state definition, StealthCoder surfaces a working solution in seconds while your proctor watches the problem statement.
Companies that ask "Length of Longest V-Shaped Diagonal Segment"
Length of Longest V-Shaped Diagonal Segment is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.
Get StealthCoderThe V-shaped diagonal constraint is the trap. Your first instinct is probably to scan all diagonals, but that's O(n^3) or worse. The pattern requires tracking your current position, the direction you came from, and how many direction changes you've made. Memoization on (row, col, direction_state) cuts the complexity drastically. Common failure: forgetting that a V requires exactly one turn, not just any two directions. Another: building the DP table wrong and double-counting segments. If you hit this in a real OA and the recursion isn't clicking, StealthCoder gives you the memo structure and the transition logic immediately.
Pattern tags
You know the problem.
Make sure you actually pass it.
Length of Longest V-Shaped Diagonal Segment recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Length of Longest V-Shaped Diagonal Segment interview FAQ
Is this really as hard as the rating suggests?+
Yes. The 34% acceptance rate reflects both the algorithmic pattern and implementation difficulty. Most candidates get stuck on state representation. The V-shape constraint isn't intuitive, and the DP transition has multiple edge cases. It's a legitimate hard problem, not mislabeled.
What's the trick that separates AC from TLE?+
Memoization with the right state tuple. Don't brute-force all diagonal combinations. Your memo key must capture position and direction history compactly. Without it, you'll revisit the same (row, col) pair thousands of times with different contexts, blowing up time complexity.
Will I actually see this at Visa?+
Visa is the only company in the public data asking it. That doesn't mean it's ultra-rare, but it's not typical Google or Amazon material. If you're interviewing there or similar quant-heavy companies, this pattern is worth studying. Most general SWE roles skip it.
Do I need to know all the matrix and DP topics to solve it?+
You need Array, Matrix index manipulation, and DP fundamentals. Memoization is the core. You don't need advanced DP like segment trees or convex hull tricks. Solid recursion and hash-map caching will get you there.
What breaks most submissions on this?+
Off-by-one errors in diagonal direction tracking, forgetting to validate that the diagonal stays in bounds, and recomputing the same cells because the memo key is wrong. Also, not recognizing that you can only have one direction change for a valid V. Read the constraints carefully.
Want the actual problem statement? View "Length of Longest V-Shaped Diagonal Segment" on LeetCode →