AP 2.1 Keshav
AP 2.1 Keshav
AP 2.1 Keshav
Experiment 2.1
Objective:
Consider an undirected graph where each edge weighs 6 units. Each of the nodes is labeled
consecutively from 1 to n.
You will be given a number of queries. For each query, you will be given a list of edges
describing an undirected graph. After you create a representation of the graph, you must
determine and report the shortest distance to each of the other nodes from a given starting
position using the breadth-first search algorithm (BFS). Return an array of distances from
the start node in node number order. If a node is unreachable, return -1 for that node.
adjList.get(u).add(v);
adjList.get(v).add(u); // Undirected graph, so add both directions
}
boolean[] visited = new boolean[n + 1];
int[] distance = new int[n + 1];
Arrays.fill(distance, -1);
Objective:
Complete the quickestWayUp function in the editor below. It should return an integer that
represents the minimum number of moves required.
quickestWayUp has the following parameter(s):
ladders: a 2D integer array where each ladders[i] contains the start and end cell
numbers of a ladder
snakes: a 2D integer array where each snakes[i] contains the start and end cell
numbers of a snake
class Result {
Output: