Topological Sort

Topological Sort

Twenty questions on topological sorting, for ordering tasks with dependencies in a directed acyclic graph.

Course Schedule

medium
There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1.

Course Schedule II

medium
There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1.

Course Schedule IV

medium
There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1.

Find All Possible Recipes from Given Supplies

medium
You have information about n different recipes.

Find Eventual Safe States

medium
There is a directed graph of n nodes with each node labeled from 0 to n - 1.

Loud and Rich

medium
There is a group of n people labeled from 0 to n - 1 where each person has a different amount of money and a different level of quietness.

Minimum Height Trees

medium
A tree is an undirected graph in which any two vertices are connected by exactly one path.

Number of Restricted Paths From First to Last Node

medium
There is an undirected weighted connected graph.

Number of Ways to Arrive at Destination

medium
You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections.

Build a Matrix With Conditions

hard
You are given a positive integer k.

Cat and Mouse

hard
A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns.

Cat and Mouse II

hard
A game is played by a cat and a mouse named Cat and Mouse.

Collect Coins in a Tree

hard
There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1.

Count Ways to Build Rooms in an Ant Colony

hard
You are an ant tasked with adding n new rooms numbered 0 to n-1 to your colony.

Frequencies of Shortest Supersequences

hard
You are given an array of strings words.

Largest Color Value in a Directed Graph

hard
There is a directed graph of n colored nodes and m edges.

Longest Cycle in a Graph

hard
You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge.

Longest Increasing Path in a Matrix

hard
Given an m x n integers matrix, return the length of the longest increasing path in matrix.

Longest Path With Different Adjacent Characters

hard
You are given a tree (i.e.

Maximum Employees to Be Invited to a Meeting

hard
A company is organizing a meeting and has a list of n employees, waiting to be invited.