Skip to content
Optimal Lab

Practice · 5 problems

Advanced Graphs

0 of 5 solved on this device

Watch it first · interactiveDijkstra: shortest paths →Watch it first · interactiveTopological sort →Read the explainer · optimal-roundWhen to use it, and its look-alikes ↗
  1. 147Course Schedule IIGiven `numCourses` and a list of prerequisite pairs [a, b] meaning b must be taken before a, return any valid ordering in which all courses can be finished. If it is impossible, return an empty array.Medium
  2. 148Network Delay TimeYou are given `times` as directed edges [u, v, w] meaning a signal takes w time to go from u to v, a node count `n` and a start node `k`. Return the time for all nodes to receive the signal, or -1 if some never do.Medium
  3. 149Min Cost to Connect All PointsGiven points on a 2D plane, the cost of connecting two points is their Manhattan distance. Return the minimum total cost to connect all points so that there is exactly one path between any two.Medium
  4. 150Cheapest Flights Within K StopsGiven `n` cities, a list of flights [from, to, price], a source, a destination and an integer `k`, return the cheapest price from src to dst using AT MOST k stops, or -1 if no such route exists.Medium
  5. 151Reconstruct ItineraryGiven a list of airline tickets [from, to], reconstruct the itinerary in order. All tickets belong to a man departing from "JFK" and must be used exactly once. If several valid itineraries exist, return the smallest in lexical order.Hard