#

Title

Solution

Time

Space

Difficulty

Note

1136

Parallel Courses

Python

O(|V|+|E|)

O(|E|)

Medium

Premium, BFS, Topological Sort

310

Minimum Height Trees

Python

O(n)

O(n)

Medium

BFS

269

Alien Dictionary

Python

O(n)

O(1)

Hard

Premium, BFS, DFS, Topological Sort,

210

Course Schedule II

Python

O(|V|+|E|)

O(|E|)

Medium

BFS, Topological Sort, Kahn’s Algorithm

1631

Path With Minimum Effort

Python

O(n*m log(n*m))

O(n*m)

Medium

Graph, Binary Search, DFS, BFS, Bi-BFS, Union Find, Dijkstra’s Algorithm

787

Cheapest Flights Within K Stops

Python

O(|E|+log(|V|))

O(|E|)

Medium

BFS, Dijkstra’s Algorithm

743

Network Delay Time

Python

O(|E|+log(|V|))

O(|E|)

Medium

BFS, Dijkstra’s Algorithm

1584

Min Cost to Connect All Points

Python

O(n^2)

O(n)

Medium

Graph, Union Find, MST, Kruskal’s Algorithm

994

Rotting Oranges

Python

O(m*n)

O(m*n)

Medium

BFS,

429

N-ary Tree Level Order Traversal

Python

O(n)

O(w)

Medium

Tree

1091

Shortest Path in Binary Matrix

Python

O(n^2)

O(n)

Medium

BFS,

116

Populating Next Right Pointers in Each Node

Python

O(n)

O(1)

Medium

Recursion

797

All Paths From Source to Target

Python

O(p+r*n)

O(n)

Medium

DFS

1059

All Paths from Source Lead to Destination

Python

O(n+e)

O(n+e)

Medium

Premium, DFS,  

332

Reconstruct Itinerary

Python

O(|V|+|E| log(|V|))

O(|V|+|E|)

Hard

Graph, Hierholzer’s Algorithm

133

Clone Graph

Python

O(n)

O(n)

Medium

BFS

1168

Optimize Water Distribution in a Village

Python

O(n log(n))

O(n)

Hard

Premium, Graph, Union Find

399

Evaluate Division

Python

O(e + q)

O(n)

Medium

Graph, DFS, Union Find, Floyd-Warshall Algorithm

1202

Smallest String With Swaps

Python

O(n log(n))

O(n)

Medium

DFS, Union Find

1101

The Earliest Moment When Everyone Become Friends

Python

O(n log(n))

O(n)

Medium

Premium, Graph, Union Find

323

Number of Connected Components in an Undirected Graph

Python

O(n)

O(n)

Medium

Premium, Hash Table, Union Find

261

Graph Valid Tree

Python

O(|V|+|E|)

O(|V|+|E|)

Medium

Premium, BFS,  

547

Number of Provinces

Python

O(n^2)

O(n)

Medium

DFS, Union Find

#1136) You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relationswhere relations[i] = [prevCoursei, nextCoursei], representing a prerequisite relationship between course prevCourseiand course nextCoursei: course prevCoursei has to be taken before course nextCoursei.

In one semester, you can take any number of courses as long as you have taken all the prerequisites in the previous semester for the courses you are taking.

Return the minimum number of semesters needed to take all courses. If there is no way to take all the courses, return -1.

#269) There is a new alien language that uses the English alphabet. However, the order among the letters is unknown to you.

You are given a list of strings words from the alien language's dictionary, where the strings in words are sorted lexicographically by the rules of this new language.

Return a string of the unique letters in the new alien language sorted in lexicographically increasing order by the new language's rules. If there is no solution, return "". If there are multiple solutions, return any of them.

A string s is lexicographically smaller than a string t if at the first letter where they differ, the letter in s comes before the letter in t in the alien language. If the first min(s.length, t.length) letters are the same, then s is smaller if and only if s.length < t.length.

#1059) Given the edges of a directed graph where edges[i] = [ai, bi] indicates there is an edge between nodes ai and bi, and two nodes source and destination of this graph, determine whether or not all paths starting from source eventually, end at destination, that is:

Return true if and only if all roads from source lead to destination.

#1168) There are n houses in a village. We want to supply water for all the houses by building wells and laying pipes.

For each house i, we can either build a well inside it directly with cost wells[i - 1] (note the -1 due to 0-indexing), or pipe in water from another well to it. The costs to lay pipes between houses are given by the array pipes where each pipes[j] = [house1j, house2j, costj] represents the cost to connect house1j and house2j together using a pipe. Connections are bidirectional, and there could be multiple valid connections between the same two houses with different costs.

Return the minimum total cost to supply water to all houses.

#1101) There are n people in a social group labeled from 0 to n - 1. You are given an array logs where logs[i] = [timestampi, xi, yi] indicates that xi and yi will be friends at the time timestampi.

Friendship is symmetric. That means if a is friends with b, then b is friends with a. Also, person a is acquainted with a person bif a is friends with b, or a is a friend of someone acquainted with b.

Return the earliest time for which every person became acquainted with every other person. If there is no such earliest time, return -1.

#323) You have a graph of n nodes. You are given an integer n and an array edges where edges[i] = [ai, bi] indicates that there is an edge between ai and bi in the graph.

Return the number of connected components in the graph.

#261) You have a graph of n nodes labeled from 0 to n - 1. You are given an integer n and a list of edges where edges[i] = [ai, bi] indicates that there is an undirected edge between nodes ai and bi in the graph.

Return true if the edges of the given graph make up a valid tree, and false otherwise.