JavaScript Solution
Intuition\nBuild an adjacency list with distances between the cities, where distance is 0 if incoming and 1 if outgoing.\n\n# Approach\nTraversing through the l
# Intuition\nBuild an adjacency list with distances between the cities, where distance is 0 if incoming and 1 if outgoing.\n\n# Approach\nTraversing through the list just adding distances to cities that haven\'t been visited\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\n/**\n * @param {number} n\n * @param {number[][]} connections\n * @return {number}\n */\nvar minReorder = function(n, connections) {\n    const adjList = {}\n\n    for (let c of connections) {\n        const [src, dest] = c\n        if (!adjList.hasOwnProperty(src)) adjList[src] = []\n        if (!adjList.hasOwnProperty(dest)) adjList[dest] = []\n        adjList[src].push({\n            city: dest,\n            distance: 1\n        })\n        adjList[dest].push({\n            city: src,\n            distance: 0\n        })\n    }\n\n    const visited = new Set()\n    const queue = []\n    queue.push(0)\n    let changes = 0\n\n    while (queue.length) {\n        const curr = queue.shift()\n\n        if (visited.has(curr)) continue\n        visited.add(curr)\n\n        for (let n of adjList[curr]) {\n            if (visited.has(n.city)) continue\n            changes += parseInt(n.distance)\n            queue.push(n.city)\n        }\n    }\n\n    return changes\n};\n```
['JavaScript']