(Hacker Rank) Breadth First Search: Shortest Reach - Solution
Link to the problem: https://www.hackerrank.com/challenges/bfsshortreach As the name of the problem states, it is necessary to use the Breadth-First Search to solve this problem. Through this approach, it is possible to find the shortest distance from the start node to all the other nodes in the graph. import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static HashMap<Integer, ArrayList<Integer>> adjList; public static void bfs(int start, int[] distances) { Queue<Distance> queue = new ArrayDeque<Distance>(); queue.add(new Distance(start, 0)); HashSet<Integer> visited = new HashSet<Integer>(); ...