{"id":11422,"date":"2025-12-31T16:19:45","date_gmt":"2025-12-31T10:49:45","guid":{"rendered":"https:\/\/namastedev.com\/blog\/?p=11422"},"modified":"2025-12-31T17:02:58","modified_gmt":"2025-12-31T11:32:58","slug":"number-of-ways-to-arrive-at-destination","status":"publish","type":"post","link":"https:\/\/namastedev.com\/blog\/number-of-ways-to-arrive-at-destination\/","title":{"rendered":"Number of Ways to Arrive at Destination"},"content":{"rendered":"\n<!-- PrismJS for Syntax Highlighting -->\n<link href=\"https:\/\/cdn.jsdelivr.net\/npm\/prismjs@1.29.0\/themes\/prism-tomorrow.min.css\" rel=\"stylesheet\">\n<script src=\"https:\/\/cdn.jsdelivr.net\/npm\/prismjs@1.29.0\/prism.min.js\"><\/script>\n<script src=\"https:\/\/cdn.jsdelivr.net\/npm\/prismjs@1.29.0\/plugins\/autoloader\/prism-autoloader.min.js\"><\/script>\n\n<style>\n.wp_blog_theme {\n  --primary: #E58C32;\n  --secondary: #030302;\n  --light-bg: #fef9f4;\n  --text-dark: #2d2d2d;\n  --tab-radius: 12px;\n  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);\n  --code-bg: #001f3f;\n  --code-text: #d4f1ff;\n}\n\n.wp_blog_container {\n  font-family: 'Segoe UI', sans-serif;\n  background: var(--light-bg);\n  margin: 0;\n  padding: 0;\n  color: var(--text-dark);\n}\n\n\/* Heading *\/\n.wp_blog_main-heading {\n  text-align: center;\n  font-size: 2.4rem;\n  color: var(--primary);\n  margin-top: 2.5rem;\n  font-weight: bold;\n}\n\n\/* Explanation Card *\/\n.wp_blog_explanation,\n.wp_blog_code-tabs-container {\n  max-width: 940px;\n  margin: 2rem auto;\n  padding: 2rem;\n  background: white;\n  border-radius: var(--tab-radius);\n  box-shadow: var(--shadow);\n}\n\n\/* Text and Visuals *\/\n.wp_blog_explanation h2 {\n  font-size: 1.4rem;\n  color: var(--primary);\n  margin-bottom: 0.5rem;\n}\n\n.wp_blog_explanation p,\n.wp_blog_explanation li {\n  font-size: 1.05rem;\n  line-height: 1.7;\n  margin: 0.5rem 0;\n}\n\n.wp_blog_explanation code {\n  background: #fef9f4;   \/* light bg instead of dark blue *\/\n  color: #E58C32;        \/* brand orange *\/\n  padding: 3px 6px;\n  border-radius: 4px;\n  font-family: 'Courier New', monospace;\n  font-weight: 600;      \/* optional, makes it pop *\/\n}\n\n.wp_blog_explanation img {\n  max-width: 100%;\n  border-radius: var(--tab-radius);\n  margin-top: 1rem;\n  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);\n}\n\n\/* Tab Buttons *\/\n.wp_blog_code-tabs-header {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 0.5rem;\n  margin-bottom: 1rem;\n}\n\n.wp_blog_code-tab-button {\n  padding: 0.6rem 1.2rem;\n  border: 1px solid var(--primary);\n  background: white;\n  color: var(--primary);\n  border-radius: 50px;\n  font-weight: 600;\n  cursor: pointer;\n  transition: all 0.3s ease;\n}\n\n.wp_blog_code-tab-button:hover {\n  background: var(--secondary);\n}\n\n.wp_blog_code-tab-button.active {\n  background: var(--primary);\n  color: white;\n}\n\n\/* Code Content *\/\n.wp_blog_code-tab-content {\n  display: none;\n  background: var(--code-bg);\n  border-radius: var(--tab-radius);\n}\n\n.wp_blog_code-tab-content.active {\n  display: block;\n}\n\n.wp_blog_code-tab-content pre {\n  margin: 0;\n  padding: 1.5rem;\n  font-size: 1rem;\n  overflow-x: auto;\n  background: var(--code-bg);\n  border-radius: var(--tab-radius);\n  color: var(--code-text);\n}\n\n\/* Dark mode variables *\/\n.wp_blog_theme.dark-mode {\n  --light-bg: #121212;\n  --text-dark: #f5f5f5;\n  --shadow: 0 4px 12px rgba(255, 255, 255, 0.08);\n  --code-bg: #1e1e1e;\n  --code-text: #c5f0ff;\n}\n\n.wp_blog_theme.dark-mode .wp_blog_explanation {\n  background: #1e1e1e;\n}\n\n\/* Dark mode code highlight *\/\n.wp_blog_theme.dark-mode .wp_blog_explanation code {\n  background: #333;\n  color: #ffd27f;\n}\n\n.wp_blog_theme {\n  position: relative; \/* makes it the reference for absolute children *\/\n}\n\n.wp_blog_toggle-btn {\n  position: absolute;\n  top: 1rem;\n  right: 1rem;\n  z-index: 9999;\n  padding: 0.5rem 0.8rem;\n  border-radius: 10%;\n  background: var(--primary);\n  color: white;\n  font-weight: bold;\n  cursor: pointer;\n  border: none;\n  box-shadow: var(--shadow);\n  transition: background 0.3s, transform 0.2s;\n}\n\n.wp_blog_toggle-btn:hover {\n  background: #cc772e;\n}\n\n.wp_blog_theme.dark-mode .wp_blog_code-tabs-container {\n  background: #1e1e1e;\n}\n<\/style>\n\n<div class=\"wp_blog_container wp_blog_theme\">\n  <button id=\"blogNotesThemeToggle\" class=\"wp_blog_toggle-btn\">\ud83c\udf19<\/button>\n  <h1 class=\"wp_blog_main-heading\"><\/h1>\n\n  <div class=\"wp_blog_explanation\">\n    <h2>Problem Statement<\/h2>\n    <p>\n        You are in a city that consists of <code>n<\/code> intersections numbered from <code>0<\/code> to <code>n - 1<\/code> with <strong>bi-directional<\/strong> roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.\n    <\/p>\n\n    <p>\n        You are given an integer <code>n<\/code> and a 2D integer array <code>roads<\/code> where <code>roads[i] = [u<sub>i<\/sub>, v<sub>i<\/sub>, time<sub>i<\/sub>]<\/code> means that there is a road between intersections u<sub>i<\/sub> and v<sub>i<\/sub> that takes <code>time<sub>i<\/sub><\/code> minutes to travel. You want to know in how many ways you can travel from intersection 0 to intersection n &#8211; 1 in the shortest amount of time.\n    <\/p>\n\n    <p>\n        Return the <strong><i>number of ways<\/i><\/strong> you can arrive at your destination in the <strong><i>shortest amount of time<\/i><\/strong>. Since the answer may be large, return it <strong>modulo<\/strong> <code>10<sup>9<\/sup> + 7<\/code>.\n    <\/p>\n\n    <h3>Example 1:<\/h2>\n    <img decoding=\"async\" src=\"https:\/\/namastedev.com\/blog\/wp-content\/uploads\/2025\/12\/Screenshot-2025-12-31-at-10.43.31-AM.png\" alt=\"\">\n        <p><strong>Input:<\/strong> n = 7, roads = [[0,6,7],[0,1,2],[1,2,3],[1,3,3],[6,3,3],[3,5,1],[6,5,1],[2,5,1],[0,4,5],[4,6,2]]<\/p>\n    <p><strong>Output:<\/strong> 4<\/p>\n    <p><strong>Explanation:<\/strong> \n        The shortest amount of time it takes to go from intersection 0 to intersection 6 is 7 minutes.\nThe four ways to get there in 7 minutes are:\n<ul>\n    <li> 0 \u279d 6<\/li>\n    <li> 0 \u279d 4 \u279d 6<\/li>\n    <li> 0 \u279d 1 \u279d 2 \u279d 5 \u279d 6<\/li>\n    <li> 0 \u279d 1 \u279d 3 \u279d 5 \u279d 6<\/li>\n<\/ul>\n<\/p>\n\n    <h3>Example 2:<\/h2>\n    <p><strong>Input:<\/strong> n = 2, roads = [[1,0,10]]<\/p>\n    <p><strong>Output:<\/strong> 1<\/p>\n    <p><strong>Explanation:<\/strong>There is only one way to go from intersection 0 to intersection 1, and it takes 10 minutes.<\/p>\n\n    <h3>Constraints<\/h3>\n    <ul>\n        <li><code>1 <= n <= 200<\/code><\/li>\n        <li><code>n - 1 <= roads.length <= n * (n - 1) \/ 2<\/code><\/li>\n        <li><code>roads[i].length == 3<\/code><\/li>\n        <li><code>0 <= u<sub>i<\/sub>, v<sub>i<\/sub> <= n - 1<\/code><\/li>\n        <li><code>1 <= time<sub>i<\/sub> <= 10<sup>9<\/sup><\/code><\/li>\n        <li><code>u<sub>i<\/sub> != v<sub>i<\/sub><\/code><\/li>\n        <li>There is at most one road connecting any two intersections.<\/li>\n        <li>You can reach any intersection from any other intersection.<\/li>\n    <\/ul>\n    \n<h2>Approach<\/h2>\n<ul>\n    <li>Build an <code>adjacency list<\/code> from the given roads.<\/li>\n    <li>Use <strong>Dijkstra\u2019s algorithm<\/strong> to find the shortest distance from node 0 to all nodes.<\/li>\n    <li>Along with distance <code>(minW)<\/code>, maintain <code>pathCount[i]<\/code> = number of shortest paths to node i.<\/li>\n    <li><strong>Initialize:<\/strong>\n        <ul>\n            <li><code>minW[0] = 0, pathCount[0] = 1<\/code><\/li>\n            <li><code>Min-heap (priority queue) with <code>[0, 0]<\/code><\/code><\/li>\n        <\/ul>\n    <\/li>\n\n    <li><strong>For each extracted node:<\/strong>\n        <ul>\n            <li>If a <code>shorter path<\/code> to a neighbor is found, update its distance and copy the path count.<\/li>\n            <li>If an <code>equal shortest path<\/code> is found, add the path count <strong>(mod 10<sup>9<\/sup> + 7)<\/strong>.<\/li>\n        <\/ul>\n    <\/li>\n\n    <li>Final answer is <code>pathCount[n-1]<\/code>, the number of shortest paths to the destination.<\/li>\n<\/ul>\n\n    <h2>Time & Space Complexity<\/h2>\n    <p><strong>Time Complexity:<\/strong> <code>O((V + E) log V)<\/code><\/p>\n    <p><code>Here, V = n (number of nodes), E = roads.length<\/code><\/p>\n    <p><strong>Space Complexity:<\/strong> <code>O(V + E)<\/code><\/p>\n\n<h2>Dry Run<\/h2> \n<div style=\"background: var(--light-bg); border-left: 4px solid var(--primary); padding: 1rem; border-radius: var(--tab-radius); margin: 1rem 0; color: var(--text-dark);\"> \n    <p><strong>Input:<\/strong> <code>n = 3<\/code>, \n        <code>roads = [[0,1,1],[1,2,1],[0,2,2]]<\/code> <\/p> \n        \n        <pre style=\"white-space: pre-wrap; background: var(--code-bg); padding: 1rem; border-radius: 8px; overflow-x: auto; color: var(--code-text);\"> \nStep 0: Start Function countPaths(3, roads) \n\n<br\/>\n            \nStep 1: Build Graph (Adjacency List) \ngraph = [ [[1, 1], [2, 2]], [[0, 1], [2, 1]], [[1, 1], [0, 2]] ] \n\n\nStep 2: Initialize Variables minW = [Infinity, Infinity, Infinity] \npathCount = [0, 0, 0] Priority Queue (pq): pq = [[0, 0]] minW[0] = 0 pathCount[0] = 1 \n\n\nStep 3: First Pop from Priority Queue [currW, curr] = [0, 0] \n   \n\nStep 4: Explore Neighbors of Node 0 Neighbor = 1 Edge Weight = 1 \n\nnewW = 0 + 1 = 1 1 < Infinity \u2192 update shortest path minW = [0, 1, Infinity] \npathCount = [1, 1, 0] pq.push([1, 1]) \nNeighbor = 2 Edge Weight = 2 \nnewW = 0 + 2 = 2 2 < Infinity \u2192 update shortest path minW = [0, 1, 2] \npathCount = [1, 1, 1] pq.push([2, 2]) \n\n\nStep 5: Second Pop from Priority Queue [currW, curr] = [1, 1] \n   \n\nStep 6: Explore Neighbors of Node 1 Neighbor = 0 Edge Weight = 1 \n\nnewW = 1 + 1 = 2 2 > minW[0] \u2192 ignore this path Neighbor = 2 \nEdge Weight = 1 newW = 1 + 1 = 2 newW == minW[2] \nAlternate shortest path found pathCount[2] = pathCount[1] + pathCount[2] pathCount[2] = 1 + 1 = 2 \n\n\nStep 7: Third Pop from Priority Queue [currW, curr] = [2, 2] \n\n\nStep 8: Explore Neighbors of Node 2 Neighbor = 1 \nEdge Weight = 1 newW = 2 + 1 = 3 3 > minW[1] \u2192 ignore Neighbor = 0 \nEdge Weight = 2 newW = 2 + 2 = 4 4 > minW[0] \u2192 ignore\n\n\nStep 9: End of Dijkstra Loop Priority Queue is empty Step 10: \n\nFinal State minW = [0, 1, 2] pathCount = [1, 1, 2] \n <br\/>           \nStep 11: Return Result pathCount[n - 1] = pathCount[2] = 2 \n        <\/pre> \n            \n            <p><strong>Output:<\/strong> <code>2<\/code><\/p> <\/div>\n        <!-- <h2>Visualisation:<\/h2>\n        <img decoding=\"async\" src=\"https:\/\/namastedev.com\/blog\/wp-content\/uploads\/2025\/09\/4.png\" alt=\"\"> -->\n   \n<\/div>\n\n\n  <div class=\"wp_blog_code-tabs-container\">\n    <div class=\"wp_blog_code-tabs-header\">\n      <button class=\"wp_blog_code-tab-button active\" data-lang=\"js\">JavaScript<\/button>\n      <button class=\"wp_blog_code-tab-button\" data-lang=\"py\">Python<\/button>\n      <button class=\"wp_blog_code-tab-button\" data-lang=\"java\">Java<\/button>\n      <button class=\"wp_blog_code-tab-button\" data-lang=\"cpp\">C++<\/button>\n      <button class=\"wp_blog_code-tab-button\" data-lang=\"c\">C<\/button>\n      <button class=\"wp_blog_code-tab-button\" data-lang=\"cs\">C#<\/button>\n    <\/div>\n\n    <div class=\"wp_blog_code-tab-content active\" data-lang=\"js\">\n      <pre><code class=\"language-javascript\">\nvar countPaths = function(n, roads) {\n    \/\/create adj list\n    let graph = Array.from({ length: n }, () => []);\n    for(let [u, v, w] of roads) {\n        graph[u].push([v, w]);\n        graph[v].push([u, w]);\n    } \n\n    \/\/ PQ, minWeight, pathCount\n    let pq = new MinPriorityQueue(x => x[0]);\n    let minW = new Array(n).fill(Infinity);\n    let pathCount = new Array(n).fill(0);\n    pq.push([0, 0]);\n    minW[0] = 0;\n    pathCount[0] = 1;\n\n    \/\/ Dijkstra's Algorithm\n    while(!pq.isEmpty()) {\n        let [currW, curr] = pq.pop();\n        for(let [neighbor, neighborW] of graph[curr]) {\n            let newW = currW + neighborW;\n            \/\/ new shortest path\n            if(newW < minW[neighbor]) {\n                minW[neighbor] = newW\n                pq.push([newW, neighbor]);\n                pathCount[neighbor] = pathCount[curr];\n            }\n            \/\/ alternative shortest path\n            else if(newW === minW[neighbor]) {\n                pathCount[neighbor] = (pathCount[curr] + pathCount[neighbor]) % (1e9 + 7);\n            }\n        }\n    }\n    return pathCount[(n-1)];\n};\n<\/code><\/pre>\n    <\/div>\n    <div class=\"wp_blog_code-tab-content\" data-lang=\"py\">\n      <pre><code class=\"language-python\">\nimport heapq\n\ndef countPaths(n, roads):\n    MOD = 10**9 + 7\n\n    graph = [[] for _ in range(n)]\n    for u, v, w in roads:\n        graph[u].append((v, w))\n        graph[v].append((u, w))\n\n    minW = [float('inf')] * n\n    pathCount = [0] * n\n\n    minW[0] = 0\n    pathCount[0] = 1\n\n    pq = [(0, 0)]  # (weight, node)\n\n    while pq:\n        currW, curr = heapq.heappop(pq)\n\n        if currW > minW[curr]:\n            continue\n\n        for neighbor, w in graph[curr]:\n            newW = currW + w\n\n            if newW < minW[neighbor]:\n                minW[neighbor] = newW\n                pathCount[neighbor] = pathCount[curr]\n                heapq.heappush(pq, (newW, neighbor))\n\n            elif newW == minW[neighbor]:\n                pathCount[neighbor] = (pathCount[neighbor] + pathCount[curr]) % MOD\n    return pathCount[n - 1]\n<\/code><\/pre>\n    <\/div>\n    <div class=\"wp_blog_code-tab-content\" data-lang=\"java\">\n      <pre><code class=\"language-java\">\nimport java.util.*;\n\nclass Solution {\n    static final int MOD = 1000000007;\n\n    public int countPaths(int n, int[][] roads) {\n        List<List<int[]>> graph = new ArrayList<>();\n        for (int i = 0; i < n; i++) graph.add(new ArrayList<>());\n\n        for (int[] r : roads) {\n            graph.get(r[0]).add(new int[]{r[1], r[2]});\n            graph.get(r[1]).add(new int[]{r[0], r[2]});\n        }\n\n        long[] minW = new long[n];\n        long[] pathCount = new long[n];\n        Arrays.fill(minW, Long.MAX_VALUE);\n\n        minW[0] = 0;\n        pathCount[0] = 1;\n\n        PriorityQueue<long[]> pq = new PriorityQueue<>(Comparator.comparingLong(a -> a[0]));\n        pq.offer(new long[]{0, 0});\n\n        while (!pq.isEmpty()) {\n            long[] curr = pq.poll();\n            long currW = curr[0];\n            int node = (int) curr[1];\n\n            if (currW > minW[node]) continue;\n\n            for (int[] nei : graph.get(node)) {\n                int next = nei[0];\n                long newW = currW + nei[1];\n\n                if (newW < minW[next]) {\n                    minW[next] = newW;\n                    pathCount[next] = pathCount[node];\n                    pq.offer(new long[]{newW, next});\n                } else if (newW == minW[next]) {\n                    pathCount[next] = (pathCount[next] + pathCount[node]) % MOD;\n                }\n            }\n        }\n        return (int) pathCount[n - 1];\n    }\n}\n    <\/code><\/pre>\n    <\/div>\n\n    <div class=\"wp_blog_code-tab-content\" data-lang=\"cpp\">\n      <pre><code class=\"language-cpp\">\n#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\n\nclass Solution {\npublic:\n    int countPaths(int n, vector<vector<int>>& roads) {\n        const int MOD = 1e9 + 7;\n\n        vector<vector<pair<int,int>>> graph(n);\n        for (auto &r : roads) {\n            graph[r[0]].push_back({r[1], r[2]});\n            graph[r[1]].push_back({r[0], r[2]});\n        }\n\n        vector<long long> minW(n, LLONG_MAX), pathCount(n, 0);\n        minW[0] = 0;\n        pathCount[0] = 1;\n\n        priority_queue<pair<long long,int>, vector<pair<long long,int>>, greater<>> pq;\n        pq.push({0, 0});\n\n        while (!pq.empty()) {\n            auto [currW, curr] = pq.top();\n            pq.pop();\n\n            if (currW > minW[curr]) continue;\n\n            for (auto &[next, w] : graph[curr]) {\n                long long newW = currW + w;\n\n                if (newW < minW[next]) {\n                    minW[next] = newW;\n                    pathCount[next] = pathCount[curr];\n                    pq.push({newW, next});\n                } else if (newW == minW[next]) {\n                    pathCount[next] = (pathCount[next] + pathCount[curr]) % MOD;\n                }\n            }\n        }\n        return pathCount[n - 1];\n    }\n};\n<\/code><\/pre>\n    <\/div>\n    <div class=\"wp_blog_code-tab-content\" data-lang=\"c\">\n      <pre><code class=\"language-c\">\n#include &lt;stdio.h&gt;\n#include &lt;limits.h&gt;\n\n#define MAXN 200\n#define MOD 1000000007\n\nlong long minW[MAXN], pathCount[MAXN];\nint graph[MAXN][MAXN], weight[MAXN][MAXN];\n\nint minNode(int n, int visited[]) {\n    long long min = LLONG_MAX;\n    int idx = -1;\n    for (int i = 0; i < n; i++) {\n        if (!visited[i] &#038;&#038; minW[i] < min) {\n            min = minW[i];\n            idx = i;\n        }\n    }\n    return idx;\n}\n\nint countPaths(int n) {\n    int visited[MAXN] = {0};\n\n    for (int i = 0; i < n; i++) {\n        minW[i] = LLONG_MAX;\n        pathCount[i] = 0;\n    }\n\n    minW[0] = 0;\n    pathCount[0] = 1;\n\n    for (int i = 0; i < n; i++) {\n        int u = minNode(n, visited);\n        if (u == -1) break;\n        visited[u] = 1;\n\n        for (int v = 0; v < n; v++) {\n            if (graph[u][v]) {\n                long long newW = minW[u] + weight[u][v];\n\n                if (newW < minW[v]) {\n                    minW[v] = newW;\n                    pathCount[v] = pathCount[u];\n                } else if (newW == minW[v]) {\n                    pathCount[v] = (pathCount[v] + pathCount[u]) % MOD;\n                }\n            }\n        }\n    }\n    return pathCount[n - 1];\n}\n <\/code><\/pre>\n    <\/div>\n\n    <div class=\"wp_blog_code-tab-content\" data-lang=\"cs\">\n      <pre><code class=\"language-csharp\">\nusing System;\nusing System.Collections.Generic;\n\npublic class Solution {\n    const int MOD = 1000000007;\n\n    public int CountPaths(int n, int[][] roads) {\n        var graph = new List<(int, int)>[n];\n        for (int i = 0; i < n; i++) graph[i] = new List<(int, int)>();\n\n        foreach (var r in roads) {\n            graph[r[0]].Add((r[1], r[2]));\n            graph[r[1]].Add((r[0], r[2]));\n        }\n\n        long[] minW = new long[n];\n        long[] pathCount = new long[n];\n        Array.Fill(minW, long.MaxValue);\n\n        minW[0] = 0;\n        pathCount[0] = 1;\n\n        var pq = new PriorityQueue<(int node, long dist), long>();\n        pq.Enqueue((0, 0), 0);\n\n        while (pq.Count > 0) {\n            var (curr, currW) = pq.Dequeue();\n\n            if (currW > minW[curr]) continue;\n\n            foreach (var (next, w) in graph[curr]) {\n                long newW = currW + w;\n\n                if (newW < minW[next]) {\n                    minW[next] = newW;\n                    pathCount[next] = pathCount[curr];\n                    pq.Enqueue((next, newW), newW);\n                } else if (newW == minW[next]) {\n                    pathCount[next] = (pathCount[next] + pathCount[curr]) % MOD;\n                }\n            }\n        }\n        return (int) pathCount[n - 1];\n    }\n}\n      <\/code><\/pre>\n    <\/div>\n  <\/div>\n<\/div>\n\n<script>\ndocument.addEventListener(\"DOMContentLoaded\", () => {\n  const buttons = document.querySelectorAll(\".wp_blog_code-tab-button\");\n  const contents = document.querySelectorAll(\".wp_blog_code-tab-content\");\n\n  buttons.forEach((button) => {\n    button.addEventListener(\"click\", () => {\n      const lang = button.getAttribute(\"data-lang\");\n\n      buttons.forEach((btn) => btn.classList.remove(\"active\"));\n      contents.forEach((content) => content.classList.remove(\"active\"));\n\n      button.classList.add(\"active\");\n      document\n        .querySelector(`.wp_blog_code-tab-content[data-lang=\"${lang}\"]`)\n        .classList.add(\"active\");\n    });\n  });\n\n  const themeToggle = document.getElementById(\"blogNotesThemeToggle\");\n  const themeContainer = document.querySelector(\".wp_blog_theme\");\n\n  themeToggle.addEventListener(\"click\", () => {\n    themeContainer.classList.toggle(\"dark-mode\");\n    themeToggle.textContent =\n      themeContainer.classList.contains(\"dark-mode\") ? \"\u2600\ufe0f\" : \"\ud83c\udf19\";\n  });\n});\n<\/script>\n\n","protected":false},"excerpt":{"rendered":"<p>\ud83c\udf19 Problem Statement You are in a city that consists of n intersections numbered from 0 to n &#8211; 1 with bi-directional roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections. You are<\/p>\n","protected":false},"author":108,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[210,322,260,176,175,211,811,810,174,172,173],"tags":[],"class_list":["post-11422","post","type-post","status-publish","format-standard","category-algorithms","category-algorithms-and-data-structures","category-c-c-plus-plus","category-csharp","category-cplusplus","category-data-structures","category-data-structures-and-algorithms","category-dsa","category-java","category-javascript","category-python"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/11422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/users\/108"}],"replies":[{"embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/comments?post=11422"}],"version-history":[{"count":1,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/11422\/revisions"}],"predecessor-version":[{"id":11423,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/11422\/revisions\/11423"}],"wp:attachment":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/media?parent=11422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/categories?post=11422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/tags?post=11422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}