# 18.05.2023 [1557. Minimum Number of Vertices to Reach All Nodes]
18.05.2023
1557. Minimum Number of Vertices to Reach All Nodes medium
blog post
Join me on Telegram
https://t.me/leetcode_daily_unstoppable/216
Problem TLDR
Find all starting nodes in graph.
Intuition
Count nodes that have no incoming connections.
Approach
we can use subtract operation in Kotlin
Complexity
Time complexity:
O(n)O(n)Space complexity:
O(n)O(n)
Code
fun findSmallestSetOfVertices(n: Int, edges: List<List<Int>>): List<Int> =
(0 until n) - edges.map { it[1] }