Build an undirected, unweighted graph from an edge list and find the
shortest path (minimum number of edges) between two nodes using BFS.
Graph class
class Graph {
addEdge(u, v) // register undirected edge u ↔ v
bfs(source, target) // → hop count, or -1 if unreachable
}Store adjacency lists in a Map<string, string[]>.
solve(edges, source, target) builds the graph, then returns bfs(source, target).
Examples
// Direct edge
solve([['A','B'],['B','C'],['A','C']], 'A', 'C') → 1
// Two hops
solve([['A','B'],['B','C']], 'A', 'C') → 2
// Disconnected
solve([['A','B'],['C','D']], 'A', 'C') → -1
// Same node
solve([['A','B']], 'A', 'A') → 0Constraints
source has no edges at all and source ≠ target, return -1.Sample tests