Find shortest distance in graph

Last updated: August 4, 2025

Quick Overview

Given a graph, find the longest subsequence using Dynamic Programming.

Walmart
Coding & Algorithms
Software Engineer
Walmart
August 4, 2025
Software Engineer
Onsite
Coding & Algorithms
Hard

363

7

1,194 solved


Given a graph, find the longest subsequence using Dynamic Programming.

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.
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 requires us to find the longest subsequence in a given graph, which can be understood as a problem of identifying paths through a directed acyclic graph (DAG). The dynamic programming app...

Approach
  1. Topologically Sort the Graph: Begin by performing a topological sort on the graph. This step ensures that we process each node only after all its dependencies (predecessors) have been processed...

Submit Your Answer
Markdown supported

Related Questions