This problem can be solved by the Dijkstra algorithm. Ring any bells?

What will be the priority for nodes?

Set the first priority for the lesser landing time and the second priority to the indices of the countries. Use the landing time as visiting order level of the nodes.

Time Complexity: $O(N \times M \times log(N \times M))$

75%
Solution Ratio

tanvirtareqEarliest,

Kuddus.6068Fastest, 0.1s

fextivityLightest, 11 MB

tanvirtareqShortest, 1155B

Toph uses cookies. By continuing you agree to our Cookie Policy.