question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
count-subtrees-with-max-distance-between-cities | Bitmasking and FloyWarshall | bitmasking-and-floywarshall-by-ashishpat-cud1 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | AshishPatel17 | NORMAL | 2024-06-21T05:23:01.447721+00:00 | 2024-06-21T05:23:01.447756+00:00 | 29 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
count-subtrees-with-max-distance-between-cities | Bit mask + DFS step by step (best practices) | bit-mask-dfs-step-by-step-best-practices-b6p7 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | sulerhy | NORMAL | 2024-05-23T17:02:31.370334+00:00 | 2024-05-23T17:02:31.370372+00:00 | 41 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(m * (2**n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n + m)\n<!-- Add your space complexity... | 0 | 0 | ['Python3'] | 0 |
count-subtrees-with-max-distance-between-cities | Solution Count Subtrees With Max Distance Between Cities | solution-count-subtrees-with-max-distanc-rnat | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Suyono-Sukorame | NORMAL | 2024-05-23T01:19:11.358201+00:00 | 2024-05-23T01:19:11.358221+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['PHP'] | 0 |
count-subtrees-with-max-distance-between-cities | bitmask, dfs | bitmask-dfs-by-maxorgus-gifu | Code\n\nclass Solution:\n def countSubgraphsForEachDiameter(self, n: int, edges: List[List[int]]) -> List[int]:\n graph = {i:set([]) for i in range(1, | MaxOrgus | NORMAL | 2024-05-10T03:11:39.434894+00:00 | 2024-05-10T03:11:39.434917+00:00 | 14 | false | # Code\n```\nclass Solution:\n def countSubgraphsForEachDiameter(self, n: int, edges: List[List[int]]) -> List[int]:\n graph = {i:set([]) for i in range(1,n+1)}\n for u,v in edges:\n graph[u].add(v)\n graph[v].add(u)\n res = [0]*(n-1)\n for mask in range(1,2**n):\n ... | 0 | 0 | ['Depth-First Search', 'Bitmask', 'Python3'] | 0 |
count-subtrees-with-max-distance-between-cities | Golang + Tree Diameter (Double BFS) + Bitmask | golang-tree-diameter-double-bfs-bitmask-rahe6 | Approach\nUse bitmask to generate every city subset and then use double BFS to find tree diameter (max distance) for this city subset. Then increment the counte | michaeljank | NORMAL | 2024-04-28T04:52:35.455424+00:00 | 2024-04-28T04:52:35.455441+00:00 | 6 | false | # Approach\nUse bitmask to generate every city subset and then use double BFS to find tree diameter (max distance) for this city subset. Then increment the counter within the res slice. Basically combine Bitmasking to store state + Tree diameter (max distance)\n\n# Complexity\n- Time complexity:\nO(n * (2 ^ n))\n\n- Sp... | 0 | 0 | ['Go'] | 0 |
count-subtrees-with-max-distance-between-cities | Bitmasking + Dijkstra's | bitmasking-dijkstras-by-mereddysujithred-837h | Approach\n Describe your approach to solving the problem. \nI solved this problem in 3 parts.\n1. Create a Tree.\n2. Get all possible subsets using bitmasking.\ | mereddysujithreddy | NORMAL | 2024-04-21T06:28:21.957339+00:00 | 2024-04-21T06:28:21.957387+00:00 | 25 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nI solved this problem in 3 parts.\n1. Create a Tree.\n2. Get all possible subsets using bitmasking.\n3. Check if the subset form a connected component or not. If yes, For each node in subset as source, get the maximum distance. Update it in the output... | 0 | 0 | ['Shortest Path', 'Bitmask', 'Python3'] | 0 |
count-subtrees-with-max-distance-between-cities | [C++] Solution with Very clear code, with sperate functions | c-solution-with-very-clear-code-with-spe-2xcq | \n# Approach\n Describe your approach to solving the problem. \n- create a graph to map all the edges\n- generate all subtrees, use bitmask to save memory.\n- n | ishitarakchhit | NORMAL | 2024-02-19T14:20:26.375280+00:00 | 2024-02-19T14:24:48.411023+00:00 | 44 | false | \n# Approach\n<!-- Describe your approach to solving the problem. -->\n- create a graph to map all the edges\n- generate all subtrees, use bitmask to save memory.\n- now inside the `helper` function decode the subtrees one by one and then call `findMaxDist` function to find the max distance for that subtree and also ch... | 0 | 0 | ['C++'] | 0 |
count-subtrees-with-max-distance-between-cities | How to break this down in simple steps(91%Time)! | how-to-break-this-down-in-simple-steps91-auoa | Intuition\n Describe your first thoughts on how to solve this problem. \nEdges dict for faster access.\n\nMax dist can get caclulated via two bfs searches!\n\nL | lucasscodes | NORMAL | 2024-02-11T17:10:33.820676+00:00 | 2024-02-11T17:10:33.820709+00:00 | 25 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nEdges dict for faster access.\n\nMax dist can get caclulated via two bfs searches!\n\nLast use recursion to shrink graph and get max dist for all smaller subgraphs also.\n\nReturn counter over different max dists found.\n# Code\n```\nclas... | 0 | 0 | ['Breadth-First Search', 'Recursion', 'Memoization', 'Python3'] | 0 |
count-subtrees-with-max-distance-between-cities | Microsoft⭐ || Easy Solution🔥|| BEATS 100%✅ | microsoft-easy-solution-beats-100-by-pri-cj1j | #ReviseWithArsh #6Companies30Days challenge 2k24\nCompany 2 :- Google\n\n# Code\n\nclass Solution {\n vector<int> edges[16]; // edges[i] stores the neighbor | Priyanshi_gangrade | NORMAL | 2024-01-31T14:42:01.893455+00:00 | 2024-01-31T14:42:01.893486+00:00 | 51 | false | ***#ReviseWithArsh #6Companies30Days challenge 2k24\nCompany 2 :- Google***\n\n# Code\n```\nclass Solution {\n vector<int> edges[16]; // edges[i] stores the neighbors of city i\n int dists[16][16]{}; // dists[i][j] stores the distance between city i and city j\n int masks[16][16]{}; // masks[i][j] store... | 0 | 0 | ['C++'] | 0 |
count-subtrees-with-max-distance-between-cities | 1617. Count Subtrees With Max Distance Between Cities | 1617-count-subtrees-with-max-distance-be-mjaj | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | pgmreddy | NORMAL | 2024-01-30T15:29:18.788369+00:00 | 2024-01-30T15:29:18.788388+00:00 | 19 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['JavaScript'] | 0 |
count-subtrees-with-max-distance-between-cities | [Python] DFS and Bit solution with Japanese explanation | python-dfs-and-bit-solution-with-japanes-r083 | Intuition & Approach\n Describe your first thoughts on how to solve this problem. \n- \u6728\u306E\u76F4\u5F84\uFF08\u6700\u9577\u7D4C\u8DEF\uFF09\u306E\u6C42\u | tada_24 | NORMAL | 2024-01-15T13:04:29.234000+00:00 | 2024-01-15T13:04:29.234024+00:00 | 15 | false | # Intuition & Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\n- \u6728\u306E\u76F4\u5F84\uFF08\u6700\u9577\u7D4C\u8DEF\uFF09\u306E\u6C42\u3081\u65B9\u3092\u77E5\u3063\u3066\u3044\u308B\u5FC5\u8981\u304C\u3042\u308B\u3002\n- \u5168\u3066\u306E\u90E8\u5206\u6728\u306B\u3064\u3044\u3066\u800... | 0 | 0 | ['Python3'] | 0 |
count-subtrees-with-max-distance-between-cities | bitmask + dfs | bitmask-dfs-by-parkcloud-udf4 | Intuition\nbitmask + find connected component + tree diameter \n\n# Approach\n\n\n# Complexity\n- Time complexity:O(n * 2^n)\n\n\n- Space complexity:O(n)\n\n# C | parkCloud | NORMAL | 2023-11-29T06:49:17.550984+00:00 | 2023-11-29T06:49:17.551017+00:00 | 9 | false | # Intuition\nbitmask + find connected component + tree diameter \n\n# Approach\n\n\n# Complexity\n- Time complexity:O(n * 2^n)\n\n\n- Space complexity:O(n)\n\n# Code\n```\n/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number[]}\n */\nfunction getTreeDiameter(graph, nodes, n) {\n if (nodes.leng... | 0 | 0 | ['JavaScript'] | 0 |
count-subtrees-with-max-distance-between-cities | Floyd Warshall + Bitset + BFS | floyd-warshall-bitset-bfs-by-tangd6-k57y | Code\n\nclass Solution {\npublic:\n static const int MX = (int)20;\n int fw[MX][MX];\n vector<int> countSubgraphsForEachDiameter(int n, vector<vector<i | tangd6 | NORMAL | 2023-11-22T03:26:24.734630+00:00 | 2023-11-22T03:26:24.734661+00:00 | 32 | false | # Code\n```\nclass Solution {\npublic:\n static const int MX = (int)20;\n int fw[MX][MX];\n vector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {\n int LG = 1 << (n);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n fw[i][j] = (i... | 0 | 0 | ['C++'] | 0 |
count-subtrees-with-max-distance-between-cities | Short C++ DFS Code | short-c-dfs-code-by-tejasdesh18-sv12 | \n# Code\n\nclass Solution {\npublic:\n int max_depth = 0, farthest_node = 0;\n\n bool isConnected(int &nodes, unordered_map<int, vector<int>> &adj, int c | tejasdesh18 | NORMAL | 2023-10-13T20:23:22.205584+00:00 | 2023-10-13T20:23:22.205602+00:00 | 52 | false | \n# Code\n```\nclass Solution {\npublic:\n int max_depth = 0, farthest_node = 0;\n\n bool isConnected(int &nodes, unordered_map<int, vector<int>> &adj, int curr, int depth ){\n\n nodes = nodes^(1<<curr);\n\n if( depth>max_depth )\n max_depth = depth, farthest_node = curr; \n \n ... | 0 | 0 | ['C++'] | 0 |
count-subtrees-with-max-distance-between-cities | Floyd-Warshall || Bitmask || Explanation and Solution [C++] | floyd-warshall-bitmask-explanation-and-s-rw3f | *This problem is quite easy, just take two steps:\n+ First, I will find the length of any two vertices using the Floyd-Warshall algorithm.\n+ Browse all aggrega | doantrunghuy | NORMAL | 2023-09-07T23:20:44.483673+00:00 | 2023-09-07T23:20:44.483694+00:00 | 21 | false | ****This problem is quite easy, just take two steps:****\n+ First, I will find the length of any two vertices using the Floyd-Warshall algorithm.\n+ Browse all aggregations using Bitmask.\n\n****Vote if you think it\'s good****\n\n****Here is my C++ code you can refer to****\n\n```\nclass Solution {\npublic:\n vecto... | 0 | 0 | ['C', 'Bitmask'] | 0 |
count-subtrees-with-max-distance-between-cities | Bitmask | Diameter of tree | C++ | clean code | easiest approach | bitmask-diameter-of-tree-c-clean-code-ea-yywv | Approach\n Describe your approach to solving the problem. \n1. Traverse through each possible subset using bitmask\n2. Ignore the mask which contains only one n | raj_keshari | NORMAL | 2023-08-31T12:31:30.082801+00:00 | 2023-08-31T12:31:30.082822+00:00 | 48 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\n1. Traverse through each possible subset using bitmask\n2. Ignore the mask which contains only one node or the graph is not connected.\n + for one node use : `(i&(i-1)) == 0` [mask must be in powers of 2]\n + for graph with more than one comp... | 0 | 0 | ['C++'] | 0 |
count-subtrees-with-max-distance-between-cities | C++ solution | c-solution-by-pejmantheory-86fp | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | pejmantheory | NORMAL | 2023-08-29T08:09:38.145655+00:00 | 2023-08-29T08:09:38.145688+00:00 | 44 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
count-subtrees-with-max-distance-between-cities | Easy to Understand | easy-to-understand-by-raj_tirtha-azsh | \n# Code\n\nclass Solution {\npublic:\n int dfs_cnt(int node,int mask,vector<vector<int>> &adj,vector<int> &vis){\n vis[node]=1;\n int cnt=1;\n | raj_tirtha | NORMAL | 2023-08-15T18:06:39.678435+00:00 | 2023-08-15T18:06:39.678460+00:00 | 23 | false | \n# Code\n```\nclass Solution {\npublic:\n int dfs_cnt(int node,int mask,vector<vector<int>> &adj,vector<int> &vis){\n vis[node]=1;\n int cnt=1;\n for(int it:adj[node]){\n if(vis[it]==1) continue;\n if(mask & (1<<it)){\n cnt+=dfs_cnt(it,mask,adj,vis);\n ... | 0 | 0 | ['C++'] | 0 |
count-subtrees-with-max-distance-between-cities | Fastest C++ solution, beats 100%, smart brute force | fastest-c-solution-beats-100-smart-brute-hrt7 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Tim | 1337beef | NORMAL | 2023-07-30T15:01:38.138758+00:00 | 2023-07-30T15:01:38.138776+00:00 | 79 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- T... | 0 | 0 | ['Bit Manipulation', 'Breadth-First Search', 'Graph', 'Bitmask', 'C++'] | 0 |
count-subtrees-with-max-distance-between-cities | Bitmask+Floydd Warshall + Dsu | bitmaskfloydd-warshall-dsu-by-dijkstraal-v0m1 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | shadow2732 | NORMAL | 2023-06-16T15:57:39.229902+00:00 | 2023-06-16T15:57:39.229921+00:00 | 40 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(2^N *N)\n\n- Space complexity:\nO(N^2)\n\n# Code\n```\nclass Solution {\npublic:\nvoid make(int a,int parent[],int len[])\n{\n ... | 0 | 0 | ['C++'] | 0 |
count-subtrees-with-max-distance-between-cities | Very Hard | very-hard-by-aadityagautam-jt3c | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | aadityagautam | NORMAL | 2023-04-30T15:18:07.661777+00:00 | 2023-04-30T15:18:07.661814+00:00 | 159 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Java'] | 0 |
count-subtrees-with-max-distance-between-cities | c++ 93% faster solution trying all subsets using bitmask | c-93-faster-solution-trying-all-subsets-1432e | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | vedantnaudiyal | NORMAL | 2023-04-23T17:54:10.754531+00:00 | 2023-04-23T17:54:10.754570+00:00 | 94 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
count-subtrees-with-max-distance-between-cities | C++ | Submask Enumeration Bruteforce + BFS | c-submask-enumeration-bruteforce-bfs-by-mtfm4 | time~O(N * 2^N)\nspace~O(N + E)\n\nclass Solution {\npublic:\n vector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {\n vector | crimsonX | NORMAL | 2023-04-12T05:59:14.141411+00:00 | 2023-04-12T06:00:23.577531+00:00 | 81 | false | time~O(N * 2^N)\nspace~O(N + E)\n```\nclass Solution {\npublic:\n vector<int> countSubgraphsForEachDiameter(int n, vector<vector<int>>& edges) {\n vector<int> res(n-1);\n vector<vector<int>> adj(n+1);\n for(auto &a:edges){\n adj[a[0]].push_back(a[1]);\n adj[a[1]].push_back(... | 0 | 0 | ['Breadth-First Search', 'Queue', 'C', 'Bitmask', 'C++'] | 0 |
count-subtrees-with-max-distance-between-cities | C# bitmap | c-bitmap-by-rnajafi76-t9hn | Check the hints in description\n\n\npublic class Solution {\n public int[] CountSubgraphsForEachDiameter(int n, int[][] edges) {\n int[] res=new int[n | rnajafi76 | NORMAL | 2023-04-05T10:50:00.280644+00:00 | 2023-04-05T10:58:13.958032+00:00 | 30 | false | Check the hints in description\n\n```\npublic class Solution {\n public int[] CountSubgraphsForEachDiameter(int n, int[][] edges) {\n int[] res=new int[n-1];\n HashSet<int>[] g=BuildGraph(n,edges);\n for(int i=1;i<(1<<n);i++){\n int d=CalculateMaxDistance(n,g,i);\n if(d==0... | 0 | 0 | ['Bit Manipulation'] | 0 |
count-subtrees-with-max-distance-between-cities | Python (Simple BFS + DP + BitMasking) | python-simple-bfs-dp-bitmasking-by-rnota-u558 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | rnotappl | NORMAL | 2023-03-09T16:14:28.273994+00:00 | 2023-03-09T16:14:28.274028+00:00 | 114 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
count-subtrees-with-max-distance-between-cities | Just a runnable solution | just-a-runnable-solution-by-ssrlive-9m03 | Code\n\nimpl Solution {\n pub fn count_subgraphs_for_each_diameter(n: i32, edges: Vec<Vec<i32>>) -> Vec<i32> {\n let mut g = vec![vec![999; n as usize | ssrlive | NORMAL | 2023-02-13T17:41:12.798051+00:00 | 2023-02-13T17:47:15.780375+00:00 | 34 | false | # Code\n```\nimpl Solution {\n pub fn count_subgraphs_for_each_diameter(n: i32, edges: Vec<Vec<i32>>) -> Vec<i32> {\n let mut g = vec![vec![999; n as usize]; n as usize];\n for e in edges.iter() {\n let i = (e[0] - 1) as usize;\n let j = (e[1] - 1) as usize;\n g[i][j] =... | 0 | 0 | ['Rust'] | 0 |
count-subtrees-with-max-distance-between-cities | C++ bitmask + DFS, with explanation. | c-bitmask-dfs-with-explanation-by-geetes-bdq0 | Intuition\n Describe your first thoughts on how to solve this problem. \xA0\n \n# Approach\n Describe your approach to solving the problem. \n As n is small, | GeeteshSood | NORMAL | 2023-02-06T22:16:57.471947+00:00 | 2023-02-06T22:17:52.847893+00:00 | 120 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\xA0\n \n# Approach\n<!-- Describe your approach to solving the problem. -->\n As n is small, find all possible subsets and see if any of them can form a subtree. \n If it can form a subtree, find the greatest distance while treating... | 0 | 0 | ['Bit Manipulation', 'Depth-First Search', 'Bitmask', 'C++'] | 0 |
count-subtrees-with-max-distance-between-cities | Not a fast solution || C++ || Just working | not-a-fast-solution-c-just-working-by-re-z8t2 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | recker2903 | NORMAL | 2022-12-25T17:35:22.913680+00:00 | 2022-12-25T17:35:22.913721+00:00 | 131 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
count-subtrees-with-max-distance-between-cities | Python3 easiest solution | python3-easiest-solution-by-avs-abhishek-o3nh | Code\n\nclass Solution(object):\n def countSubgraphsForEachDiameter(self, n, edges):\n def bfs(src, cities):\n visited = {src}\n | avs-abhishek123 | NORMAL | 2022-12-08T05:41:39.919738+00:00 | 2022-12-08T05:41:39.919772+00:00 | 164 | false | # Code\n```\nclass Solution(object):\n def countSubgraphsForEachDiameter(self, n, edges):\n def bfs(src, cities):\n visited = {src}\n q = deque([(src, 0)]) # Pair of (vertex, distance)\n farthestDist = 0 # Farthest distance from src to other nodes\n while len(q) > ... | 0 | 0 | ['Python3'] | 0 |
count-subtrees-with-max-distance-between-cities | C++ | O(N log N * 2^N) | Bitmask & DFS | c-on-log-n-2n-bitmask-dfs-by-chawlasahil-949k | Algorithm:\n\nStep 1\nGenerate all subsets (or masks) -> O(2^N)\n\nStep 2\nFor every mask, check if the tree formed is valid or not.\nThis is done by finding th | chawlasahil565 | NORMAL | 2022-10-30T06:27:22.931639+00:00 | 2022-10-30T06:27:22.931681+00:00 | 127 | false | Algorithm:\n\nStep 1\nGenerate all subsets (or masks) -> O(2^N)\n\nStep 2\nFor every mask, check if the tree formed is valid or not.\nThis is done by finding the number of nodes reachable from one of the nodes using DFS -> O(number of edges in subtree) < O(N) (upper bound)\n\nStep 3\nFor every valid mask, find the diam... | 0 | 0 | ['Depth-First Search', 'C', 'Bitmask'] | 0 |
count-subtrees-with-max-distance-between-cities | C++ Simple Solution With Explanation Using Bitmask & Floyd Warshall Algorithm - O(2^N*N^2) | c-simple-solution-with-explanation-using-in2w | Firstly, we will use Floyd Warshall Algorithm to find the distance between every pair of nodes. Its time complexity will be O(N^3) \nHere, N is 15 so we can con | rahul-rj | NORMAL | 2022-10-20T09:45:39.953047+00:00 | 2022-10-20T09:45:39.953086+00:00 | 123 | false | Firstly, we will use Floyd Warshall Algorithm to find the distance between every pair of nodes. Its time complexity will be O(N^3) \nHere, N is 15 so we can consider every possible subset in O(2^N) and then\n1) check if it is a subtree: if it is a subtree then no of nodes (cities) - 1 = no of edges\n2) find the maximum... | 0 | 0 | ['C', 'Bitmask'] | 0 |
number-of-ways-to-arrive-at-destination | [C++/Python] Dijkstra - Clean & Concise | cpython-dijkstra-clean-concise-by-hiepit-5ww1 | Idea\n- We use Dijkstra algorithm to find the Shortest Path from src = 0 to dst = n - 1.\n- While dijkstra, we create additional ways array, where ways[i] keeps | hiepit | NORMAL | 2021-08-21T16:01:14.699252+00:00 | 2021-08-23T14:46:27.631003+00:00 | 34,461 | false | **Idea**\n- We use Dijkstra algorithm to find the Shortest Path from `src = 0` to `dst = n - 1`.\n- While dijkstra, we create additional `ways` array, where `ways[i]` keeps the number of shortest path from `src = 0` to `dst = i`. Then the answer is `ways[n-1]`.\n\n<iframe src="https://leetcode.com/playground/PhVJCRs6/s... | 548 | 6 | [] | 43 |
number-of-ways-to-arrive-at-destination | ✔️ DP + Dijkstra | Python | C++ | Java | JS | C# | Go | Rust | Kotlin | dp-shortest-path-python-by-otabek_kholmi-9eb0 | SUPPORT BY UPVOTING THE POST ⬆️IntuitionThis problem combines the shortest path algorithm with counting the number of ways to reach a destination using the shor | otabek_kholmirzaev | NORMAL | 2025-03-23T00:59:42.006959+00:00 | 2025-03-23T20:46:27.769866+00:00 | 17,501 | false | # SUPPORT BY UPVOTING THE POST ⬆️
# Intuition
This problem combines the shortest path algorithm with counting the number of ways to reach a destination using the shortest path. We use **Dijkstra's algorithm** to find the shortest paths and simultaneously count how many different ways we can reach each node with the cu... | 79 | 5 | ['Dynamic Programming', 'Shortest Path', 'C++', 'Java', 'Go', 'Python3', 'Rust', 'Kotlin', 'JavaScript', 'C#'] | 6 |
number-of-ways-to-arrive-at-destination | [python] Almost Dijktra, explained | python-almost-dijktra-explained-by-dbabi-p7tw | The idea of this problem is to use Dijkstra algorithm, but also we need to keep not only distances to nodes, but counts as well.\n\n1. If we meet candidate == d | dbabichev | NORMAL | 2021-08-21T16:01:09.796183+00:00 | 2021-08-21T20:02:52.131449+00:00 | 7,036 | false | The idea of this problem is to use Dijkstra algorithm, but also we need to keep not only distances to nodes, but counts as well.\n\n1. If we meet `candidate == dist[neib]`, it means we found one more way to reach node with minimal cost.\n2. If `candidate < dist[neib]`, it means that we found better candidate, so we upd... | 58 | 2 | [] | 9 |
number-of-ways-to-arrive-at-destination | [C++] Dijkstra - Clean & Concise | c-dijkstra-clean-concise-by-arpit00nine-0r1j | \nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& roads) {\n int mod = 1e9+7;\n vector<vector<pair<int, int>>> graph(n); | Arpit00nine | NORMAL | 2021-08-21T16:51:21.110580+00:00 | 2021-08-21T16:51:21.110610+00:00 | 7,850 | false | ```\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& roads) {\n int mod = 1e9+7;\n vector<vector<pair<int, int>>> graph(n);\n for(auto &road: roads) {\n graph[road[0]].push_back({road[1], road[2]});\n graph[road[1]].push_back({road[0], road[2]});\n ... | 46 | 1 | ['Dynamic Programming', 'C', 'C++'] | 4 |
number-of-ways-to-arrive-at-destination | JAVA STEP BY STEP EXPLAINED✅✅ || SIMPLEST SOLUTION😀✌️ | java-step-by-step-explained-simplest-sol-hw9c | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | abhiyadav05 | NORMAL | 2023-08-30T06:55:17.684401+00:00 | 2023-08-30T06:55:17.684427+00:00 | 3,068 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ --> O(m + n log n).\n\n- Space complexity:\n<!-- Add your space complexity here, ... | 34 | 1 | ['Breadth-First Search', 'Graph', 'Shortest Path', 'Java'] | 3 |
number-of-ways-to-arrive-at-destination | Simple Java Solution | simple-java-solution-by-hxgxs1-gi0o | From the problem statement it was clear we need to apply dijkistra to find shortest path between source and dest.\n2. Well, dijkistra to rescue. Using dijkistra | hxgxs1 | NORMAL | 2021-08-21T16:26:33.697873+00:00 | 2022-03-05T03:32:41.909884+00:00 | 4,632 | false | 1. From the problem statement it was clear we need to apply dijkistra to find shortest path between source and dest.\n2. Well, dijkistra to rescue. Using dijkistra we can keep shortest path by keep relaxing the edges. (Cormen lingo).\n3. Catch is, whenver you find a better way to reach a particular vertex update the nu... | 31 | 2 | [] | 4 |
number-of-ways-to-arrive-at-destination | Min heap | min-heap-by-votrubac-0k5d | This is just Vanila Dijkstra. I would only note that the min heap is required here not only for the performance, but also for the accuracy.\n\nWe process nodes | votrubac | NORMAL | 2021-08-22T23:35:09.905692+00:00 | 2021-08-22T23:37:49.008398+00:00 | 3,904 | false | This is just Vanila Dijkstra. I would only note that the min heap is required here not only for the performance, but also for the accuracy.\n\nWe process nodes in the queue from smallest to largest distance, so that we "wait" for all paths with the same distance to reach the node, accumulating the number of ways to rea... | 30 | 1 | [] | 3 |
number-of-ways-to-arrive-at-destination | C++ - Dijkstra algorithm + DP (Explained) | c-dijkstra-algorithm-dp-explained-by-sha-qpg6 | Idea:-\nDijkstra algorithm is being used to know the most optimal way to reach the target. \nWe are using an array to store the number of optimal ways to reach | sharmamayank94 | NORMAL | 2021-08-21T16:57:49.016334+00:00 | 2021-08-21T16:57:49.016383+00:00 | 2,461 | false | **Idea:-**\nDijkstra algorithm is being used to know the most optimal way to reach the target. \nWe are using an array to store the number of optimal ways to reach a node. Let us call this\n*paths[]*\n\nLet us consider an example only for DP logic:-\n\n || Floyd Warshall || DP | c-solution-on3-floyd-warshall-dp-by-kesh-jegj | \n#define ll long long int\nconst ll mod= 1e9+7;\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& roads) {\n ll dp[n][n][2]; \n | keshav_jain2161 | NORMAL | 2021-08-21T16:30:26.830000+00:00 | 2021-08-21T16:30:26.830062+00:00 | 1,419 | false | ```\n#define ll long long int\nconst ll mod= 1e9+7;\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& roads) {\n ll dp[n][n][2]; \n // dp[i][j][0] stores minimum distance and dp[i][j][1] stores number of ways to reach with the minimum distance dp[i][j][0]\n for(ll i=0; ... | 15 | 0 | [] | 3 |
number-of-ways-to-arrive-at-destination | Dijkstra's Algorithm | dijkstras-algorithm-by-zaidzack-4p6g | \nclass Solution {\n int mod = 1_000_000_007;\n public int countPaths(int n, int[][] roads) {\n List<int[]>[] graph = new ArrayList[n];\n \n | zaidzack | NORMAL | 2022-08-20T09:57:21.149159+00:00 | 2022-08-20T09:57:21.149191+00:00 | 3,142 | false | ```\nclass Solution {\n int mod = 1_000_000_007;\n public int countPaths(int n, int[][] roads) {\n List<int[]>[] graph = new ArrayList[n];\n \n for(int i = 0; i < n; i++)\n graph[i] = new ArrayList<int[]>();\n \n for(int[] edge: roads)\n {\n int src ... | 13 | 1 | ['Java'] | 3 |
number-of-ways-to-arrive-at-destination | Python - Dijkstra's Algorithm (Min Heap Implementation) >90% time score | python-dijkstras-algorithm-min-heap-impl-as12 | ```\nfrom heapq import *\nclass Solution:\n def countPaths(self, n: int, roads: List[List[int]]) -> int:\n # create adjacency list\n adj_list = | kaustav43 | NORMAL | 2022-01-06T05:31:55.362029+00:00 | 2022-01-06T05:33:00.724816+00:00 | 2,596 | false | ```\nfrom heapq import *\nclass Solution:\n def countPaths(self, n: int, roads: List[List[int]]) -> int:\n # create adjacency list\n adj_list = defaultdict(list)\n for i,j,k in roads:\n adj_list[i].append((j,k))\n adj_list[j].append((i,k))\n \n start = 0\n... | 13 | 0 | ['Graph', 'Heap (Priority Queue)', 'Python', 'Python3'] | 1 |
number-of-ways-to-arrive-at-destination | C++ - Dijkstra algorithm || Easy Understanding | c-dijkstra-algorithm-easy-understanding-kch2k | Apply Dijkstra shortest path algorithm as the problem involves shortest distance from source to destination. We need to modify Dijkstra\'s algorithm so that it | sahooc029 | NORMAL | 2022-10-14T05:01:01.482358+00:00 | 2022-10-15T02:48:45.041467+00:00 | 2,315 | false | Apply **Dijkstra shortest path algorithm** as the problem involves shortest distance from source to destination. We need to modify **Dijkstra\'s algorithm** so that it can keep track of the path counts from node 0 to every other node in a way that it can keep track of the distance from every other node to node 0 with t... | 11 | 0 | ['Graph', 'C', 'C++'] | 1 |
number-of-ways-to-arrive-at-destination | [Python] Dijkstra + DP solution (60-70% faster) | python-dijkstra-dp-solution-60-70-faster-o3c5 | Logic\n- Dijkstra algorithm can only get the shortest time from src to dst.\n- What we want to get is the number of ways with minimum time from src to dst.\n- W | lluB | NORMAL | 2022-06-02T13:08:01.235792+00:00 | 2022-06-02T13:10:48.407894+00:00 | 1,204 | false | ## Logic\n- Dijkstra algorithm can only get the shortest time from src to dst.\n- What we want to get is **the number of ways with minimum time from src to dst.**\n- We need\n\t1) **times** array : to check the minimum time to take from src to times[i].\n\t2) **ways** array : to check the total ways from src to ways[i]... | 11 | 0 | ['Dynamic Programming', 'Breadth-First Search', 'Python'] | 2 |
number-of-ways-to-arrive-at-destination | Dijkstra + Keeping Count of the number of ways | dijkstra-keeping-count-of-the-number-of-wdf3p | \ntypedef long long ll;\n typedef pair<long long, long long> ppl;\n int countPaths(int n, vector<vector<int>>& roads) {\n int mod = (1e9+7);\n | prakhar3099 | NORMAL | 2021-11-09T01:44:21.756800+00:00 | 2021-11-09T01:44:21.756850+00:00 | 1,381 | false | ```\ntypedef long long ll;\n typedef pair<long long, long long> ppl;\n int countPaths(int n, vector<vector<int>>& roads) {\n int mod = (1e9+7);\n vector<ll> dist(n,LLONG_MAX);\n vector<int> ways(n,0);\n priority_queue<ppl, vector<ppl>, greater<ppl>> pq;\n \n dist[0] = 0; ... | 10 | 0 | ['C'] | 0 |
number-of-ways-to-arrive-at-destination | C++ Dijkstra Solution O(V^2 LogV) | c-dijkstra-solution-ov2-logv-by-ahsan83-alki | Runtime: 96 ms, faster than 46.70% of C++ online submissions for Number of Ways to Arrive at Destination.\nMemory Usage: 40.5 MB, less than 7.91% of C++ online | ahsan83 | NORMAL | 2021-08-25T12:59:11.427986+00:00 | 2021-08-25T13:03:58.223589+00:00 | 1,347 | false | Runtime: 96 ms, faster than 46.70% of C++ online submissions for Number of Ways to Arrive at Destination.\nMemory Usage: 40.5 MB, less than 7.91% of C++ online submissions for Number of Ways to Arrive at Destination.\n\nNote: Solution taken from other post.\n\n```\nWe can find the shortest distance from any vertex to a... | 10 | 0 | ['Dynamic Programming', 'Graph', 'C'] | 1 |
number-of-ways-to-arrive-at-destination | 1976. Number of Ways to Arrive at Destination [C++] | 1976-number-of-ways-to-arrive-at-destina-lj9w | IntuitionTo find the number of shortest paths from node 0 to node n - 1, we need a way to not only compute the shortest distances but also count how many such p | moveeeax | NORMAL | 2025-03-23T18:36:13.224222+00:00 | 2025-03-23T18:36:13.224222+00:00 | 172 | false |
# Intuition
To find the number of shortest paths from node 0 to node n - 1, we need a way to not only compute the shortest distances but also count how many such paths exist. A modified Dijkstra's algorithm allows us to achieve both goals simultaneously.
# Approach
We represent the graph using an adjacency list and i... | 9 | 0 | ['C++'] | 0 |
number-of-ways-to-arrive-at-destination | Python - Dijkstra's Algorithm | python-dijkstras-algorithm-by-ajith6198-j77u | \nclass Solution:\n def countPaths(self, n: int, roads: List[List[int]]) -> int:\n graph = defaultdict(dict)\n for u, v, w in roads:\n | ajith6198 | NORMAL | 2021-08-21T17:33:21.696448+00:00 | 2021-08-21T17:33:21.696488+00:00 | 1,300 | false | ```\nclass Solution:\n def countPaths(self, n: int, roads: List[List[int]]) -> int:\n graph = defaultdict(dict)\n for u, v, w in roads:\n graph[u][v] = graph[v][u] = w\n dist = {i:float(inf) for i in range(n)}\n ways = {i:0 for i in range(n)}\n dist[0], ways[0] = 0, 1\n ... | 9 | 0 | ['Python'] | 1 |
number-of-ways-to-arrive-at-destination | Simple Djikstra Approach✅✅ | simple-djikstra-approach-by-arunk_leetco-vvge | IntuitionTo count the number of different shortest paths from node 0 to node n - 1, we need more than just the shortest distances.
Dijkstra’s algorithm is ideal | arunk_leetcode | NORMAL | 2025-03-23T05:11:59.791662+00:00 | 2025-03-23T05:11:59.791662+00:00 | 2,027 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
To count the number of different shortest paths from node 0 to node n - 1, we need more than just the shortest distances.
Dijkstra’s algorithm is ideal for finding shortest paths in weighted graphs, and we can enhance it to count the numbe... | 8 | 0 | ['Graph', 'Topological Sort', 'Shortest Path', 'C++'] | 1 |
number-of-ways-to-arrive-at-destination | Optimizing Shortest Paths: Efficient Route Counting with Dijkstra’s Algorithm | 💯✔️ | optimizing-shortest-paths-efficient-rout-wxq3 | IntuitionThe problem is a variation of the shortest path problem in a weighted graph. Since we need to count the number of ways to reach the destination in the | iamanrajput | NORMAL | 2025-03-23T08:52:00.958473+00:00 | 2025-03-23T08:52:00.958473+00:00 | 1,244 | false | # Intuition
The problem is a variation of the shortest path problem in a weighted graph. Since we need to count the number of ways to reach the destination in the shortest time, Dijkstra’s algorithm is a natural choice. By tracking both distances and path counts, we can efficiently determine the result.
# Approach
1. ... | 7 | 0 | ['Java'] | 1 |
number-of-ways-to-arrive-at-destination | ✅ C++ || Dijkstra || Priority_Queue || Easy to understand | c-dijkstra-priority_queue-easy-to-unders-wt06 | \n#define ll long long\nclass Solution {\npublic:\n int MOD = 1e9 + 7;\n int countPaths(int n, vector<vector<int>>& roads) {\n vector<pair<ll,ll>> | indresh149 | NORMAL | 2022-10-07T07:39:21.881492+00:00 | 2022-10-07T07:39:21.881528+00:00 | 1,244 | false | ```\n#define ll long long\nclass Solution {\npublic:\n int MOD = 1e9 + 7;\n int countPaths(int n, vector<vector<int>>& roads) {\n vector<pair<ll,ll>> adj[n];\n for(auto it:roads){\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n }\n \n ... | 7 | 0 | ['C'] | 1 |
number-of-ways-to-arrive-at-destination | Graph, Dijkstra, Shortest Path, Dynamic Programming O((E+V)logV) | graph-dijkstra-shortest-path-dynamic-pro-9u8p | IntuitionTo find the number of ways to reach the destination node n - 1 from node 0 in the shortest possible time, we need more than just the shortest distance | Nyx_owl | NORMAL | 2025-03-23T12:04:25.614573+00:00 | 2025-03-23T12:04:25.614573+00:00 | 753 | false | # Intuition
To find the number of ways to reach the destination node `n - 1` from node `0` in the *shortest* possible time, we need more than just the shortest distance — we must also track **how many different paths** lead to that shortest distance.
A natural fit for shortest path problems is **Dijkstra’s algorithm**... | 6 | 0 | ['Graph', 'Shortest Path', 'Python3'] | 1 |
number-of-ways-to-arrive-at-destination | [C++] Dijkstra | Clean Code | Video Solution with Diagram | c-dijkstra-clean-code-video-solution-wit-ozjy | Complete Video Solution with full explanationIntuitionThe problem requires finding the shortest path from node 0 to node n-1 while also counting how many differ | abhinavbansal19961996 | NORMAL | 2025-03-23T10:16:48.094494+00:00 | 2025-03-23T10:16:48.094494+00:00 | 656 | false | # Complete Video Solution with full explanation
https://youtu.be/qJfun8H8T-A
# Intuition
The problem requires finding the shortest path from node 0 to node n-1 while also counting how many different ways exist to reach the destination in the shortest possible time.
Since the graph consists of weighted edges (time tak... | 6 | 0 | ['C++'] | 1 |
number-of-ways-to-arrive-at-destination | ✅🚀easy Dijkstra+graph+friendly with explain code in all languages | easy-dijkstragraphfriendly-with-explain-94f5j | guys please upvote for support 😊🌟 Intuition and Approach — Shortest Path + Counting Paths1.🏙️ Problem:
We need to find the number of shortest paths from the st | thakur_saheb | NORMAL | 2025-03-23T02:14:23.984140+00:00 | 2025-03-23T17:52:44.841041+00:00 | 1,696 | false | # *guys please upvote for support 😊*
# 🌟 Intuition and Approach — Shortest Path + Counting Paths
# 1.🏙️ **Problem:**
- ###### We need to find the number of shortest paths from the starting node (0) to the destination node (n-1) in a weighted graph.
# 2. 🛣️ Graph Representation:
- ###### The graph is represented... | 6 | 0 | ['Swift', 'Python', 'C++', 'Java', 'Go', 'Rust', 'Ruby', 'Kotlin', 'JavaScript', 'C#'] | 2 |
number-of-ways-to-arrive-at-destination | Dijkstra Pattern | dijkstra-pattern-by-dixon_n-b8co | Important problem\nCheapest flight,minimum effort and more\n# Code\njava []\nclass Solution {\n public int countPaths(int numIntersections, int[][] roads) {\ | Dixon_N | NORMAL | 2024-06-18T00:58:11.775265+00:00 | 2024-06-18T00:58:11.775293+00:00 | 1,108 | false | Important problem\nCheapest flight,minimum effort and more\n# Code\n```java []\nclass Solution {\n public int countPaths(int numIntersections, int[][] roads) {\n ArrayList<ArrayList<Node>> adjacencyList = new ArrayList<>();\n for (int i = 0; i < numIntersections; i++) {\n adjacencyList.add(n... | 6 | 0 | ['Java'] | 5 |
number-of-ways-to-arrive-at-destination | Dijkstra's Algo using Priority queue || C++ Solution | dijkstras-algo-using-priority-queue-c-so-60a2 | \n# Complexity\n- Time complexity: O(E logV)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(V) + O(N)\n Add your space complexity here, e. | aayu_t | NORMAL | 2023-06-18T19:45:07.923053+00:00 | 2023-06-18T19:45:42.424900+00:00 | 2,407 | false | \n# Complexity\n- Time complexity: **O(E logV)**\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: **O(V) + O(N)**\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& a) {\n vector<pair<long ... | 6 | 0 | ['Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'C++'] | 1 |
number-of-ways-to-arrive-at-destination | C++ || Dijkstra algorithm | c-dijkstra-algorithm-by-njyotiprakash189-gxu5 | Time Complexity=O(V+E)\nSpace Complexity=O(V+E)\nV=number of node\nE=number of edges\n\n\n \n #define ll long long\n class Solution {\n public:\n i | njyotiprakash189 | NORMAL | 2022-10-15T14:15:48.204911+00:00 | 2022-10-15T14:15:48.204948+00:00 | 671 | false | **Time Complexity=O(V+E)\nSpace Complexity=O(V+E)**\nV=number of node\nE=number of edges\n\n\n \n #define ll long long\n class Solution {\n public:\n int countPaths(int n, vector<vector<int>>& roads) {\n vector<pair<ll,ll>> adj[n];\n for(auto it:roads){\n adj[it[0]].push_back({it[1... | 6 | 0 | ['Graph', 'C'] | 2 |
number-of-ways-to-arrive-at-destination | Clean Dijkstra implementation || c++ | clean-dijkstra-implementation-c-by-binay-xobx | \n#define ll long long\n#define pi pair<ll , ll>\nconst int mod = 1e9+7;\n\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& roads) {\n | binayKr | NORMAL | 2022-07-16T09:56:58.216080+00:00 | 2022-07-16T09:56:58.216125+00:00 | 433 | false | ```\n#define ll long long\n#define pi pair<ll , ll>\nconst int mod = 1e9+7;\n\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& roads) {\n \n \n vector<pi> adj[n]; // node-> pair< adjNode, distance>\n for(auto &it : roads)\n {\n adj[it[0]].push_b... | 6 | 0 | ['C'] | 0 |
number-of-ways-to-arrive-at-destination | Java, basic minHeap Dijkstra with minor changes | java-basic-minheap-dijkstra-with-minor-c-s1jv | Perform regular Dijkstra with some adjustments: \nadd one more ways[] array alongside to distance[] basic array.\nif there is an adjacent vertex with total time | dimitr | NORMAL | 2021-08-24T11:11:00.662068+00:00 | 2021-08-25T01:47:46.349710+00:00 | 1,190 | false | Perform regular Dijkstra with some adjustments: \nadd one more ways[] array alongside to distance[] basic array.\nif there is an adjacent vertex with total time less than currne time + edge distance, then update best distance and go ahead as usual, by adding edge into minHeap\nif same time already exists, then we have ... | 6 | 0 | [] | 3 |
number-of-ways-to-arrive-at-destination | [Python3] dfs + dp | python3-dfs-dp-by-ye15-bivb | \n\nclass Solution:\n def countPaths(self, n: int, roads: List[List[int]]) -> int:\n graph = {}\n for u, v, time in roads: \n graph. | ye15 | NORMAL | 2021-08-21T16:02:29.266918+00:00 | 2021-08-24T15:28:52.316273+00:00 | 1,807 | false | \n```\nclass Solution:\n def countPaths(self, n: int, roads: List[List[int]]) -> int:\n graph = {}\n for u, v, time in roads: \n graph.setdefault(u, {})[v] = time\n graph.setdefault(v, {})[u] = time\n \n dist = [inf]*n\n dist[-1] = 0\n stack = [(n-1... | 6 | 1 | ['Python3'] | 1 |
number-of-ways-to-arrive-at-destination | Striver's code that passes all TESTCASES | strivers-code-that-passes-all-testcases-2fns3 | Just change everything to long long.
and take mod=1e9+7Complexity
Time complexity: Simple Djkastra algo->ElogV
Space complexity: O(N)
Code | now_now123 | NORMAL | 2024-12-20T04:49:20.216480+00:00 | 2024-12-20T04:49:20.216480+00:00 | 1,396 | false | Just change everything to long long.
and take mod=1e9+7
# Complexity
- Time complexity: Simple Djkastra algo->ElogV
- Space complexity: O(N)
# Code
```cpp []
class Solution {
public:
int countPaths(int n, vector<vector<int>>& roads) {
vector<vector<pair<long long, long long>>> adj(n);
for(a... | 5 | 0 | ['Graph', 'Shortest Path', 'C++'] | 2 |
number-of-ways-to-arrive-at-destination | Well Explained | well-explained-by-aayushagarwal001-ei1p | Intuition\nThe problem involves finding the number of distinct paths from the starting node 0 to the ending node n-1 in an undirected graph with weighted edges. | AayushAgarwal001 | NORMAL | 2024-06-16T13:38:10.961928+00:00 | 2024-06-16T13:38:10.961959+00:00 | 1,095 | false | # Intuition\nThe problem involves finding the number of distinct paths from the starting node `0` to the ending node `n-1` in an undirected graph with weighted edges. Each path\'s weight is calculated as the sum of edge weights along that path. Additionally, we need to keep track of the number of such paths because the... | 5 | 1 | ['Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Shortest Path', 'C++'] | 0 |
number-of-ways-to-arrive-at-destination | [C++] || Dijkstra Algorithm || DP | c-dijkstra-algorithm-dp-by-deleted_user-2vd2 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe minimum cost can be found using Dijkstra Algorithm and we can use DP array to store | deleted_user | NORMAL | 2023-07-26T14:41:53.249478+00:00 | 2023-07-26T14:41:53.249497+00:00 | 827 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe minimum cost can be found using Dijkstra Algorithm and we can use DP array to store the count value.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n-> Use Dijkstra to find the shortest amount of time.\n-> Use ... | 5 | 0 | ['Dynamic Programming', 'Graph', 'C++'] | 0 |
number-of-ways-to-arrive-at-destination | C++ - Dijkstra algorithm || Easy Understanding || Beats 90 percent | c-dijkstra-algorithm-easy-understanding-85pmh | Code\n\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& r) {\n int mod=1e9+7;\n vector<vector<pair<long long,long long>> | anandmohit852 | NORMAL | 2023-01-18T12:03:08.356788+00:00 | 2023-01-18T12:03:08.356828+00:00 | 1,473 | false | # Code\n```\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& r) {\n int mod=1e9+7;\n vector<vector<pair<long long,long long>>>adj(n);\n for(int i=0;i<r.size();i++){\n adj[r[i][0]].push_back({r[i][1],r[i][2]});\n adj[r[i][1]].push_back({r[i][0],r[i][2]... | 5 | 0 | ['C++'] | 0 |
number-of-ways-to-arrive-at-destination | Java Solution using Dijkstra Algorithm | java-solution-using-dijkstra-algorithm-b-lvvj | class Solution {\n \n private int dijkstra(int[][] roads,int n){\n long mod=(int)1e9+7;\n\t\t//PriorityQueue is used for sorting by time\n Q | vaibhavDiwan_1999 | NORMAL | 2022-02-09T15:57:48.387071+00:00 | 2022-02-09T16:05:18.373794+00:00 | 1,103 | false | class Solution {\n \n private int dijkstra(int[][] roads,int n){\n long mod=(int)1e9+7;\n\t\t//PriorityQueue is used for sorting by time\n Queue<long[]> pq = new PriorityQueue<>((l, r) -> Long.compare(l[1], r[1]));\n //Number of ways to reach a vertex from 0 in minimum time\n\t\tlong[] ways=n... | 5 | 0 | ['Java'] | 1 |
number-of-ways-to-arrive-at-destination | Java / C++ Dijkstra Clean Effective Code with Explanation | java-c-dijkstra-clean-effective-code-wit-2qfc | Set up the classic Dijkstra algorithm keeping track of cost for each node and the number of paths with the smallest cost.\n\nA few tricks to make it work and ma | cosmopolitan | NORMAL | 2021-08-25T01:15:28.149082+00:00 | 2021-08-25T13:37:44.985969+00:00 | 1,992 | false | Set up the classic Dijkstra algorithm keeping track of cost for each node and the number of paths with the smallest cost.\n\nA few tricks to make it work and make it effective:\n\n1. Push to the queue only the nodes with the smallest cost. If you encounter the node with the same cost on a different path, update the pat... | 5 | 0 | ['C', 'Java'] | 1 |
number-of-ways-to-arrive-at-destination | Simple Python Solution (Dijkstra algo) | simple-python-solution-dijkstra-algo-by-it17u | \'\'\'\n\n def countPaths(self, n: int, roads: List[List[int]]) -> int:\n \n\t\t//creating adgecency matrix\n mat = [[0] * n for _ in range(n)] | atul_iitp | NORMAL | 2021-08-21T16:33:15.048102+00:00 | 2021-08-21T17:45:37.470001+00:00 | 781 | false | \'\'\'\n\n def countPaths(self, n: int, roads: List[List[int]]) -> int:\n \n\t\t//creating adgecency matrix\n mat = [[0] * n for _ in range(n)]\n for i,j,k in roads:\n mat[i][j]= mat[j][i] = k\n \n\t\t// An array for keeping track of distance of last node from each node\n ... | 5 | 2 | ['Python'] | 1 |
number-of-ways-to-arrive-at-destination | Effective Solution In C (yes, C and not C++) | BEATS 93% | USING DIJKSTRA’S ALGORITHM | | effective-solution-in-c-yes-c-and-not-c-40tbt | Intuition
The problem requires finding the number of shortest paths from node 0 to node n-1 in a weighted graph.
This suggests using Dijkstra’s algorithm to det | Delta7Actual | NORMAL | 2025-03-23T13:24:31.962846+00:00 | 2025-03-23T13:24:31.962846+00:00 | 102 | false | # Intuition
- The problem requires finding the number of shortest paths from node `0` to node `n-1` in a weighted graph.
- This suggests using **Dijkstra’s algorithm** to determine the shortest path and **dynamic programming** to count the number of ways to reach each node optimally.
---
# Approach
1. **Graph Represen... | 4 | 0 | ['Math', 'Dynamic Programming', 'Graph', 'Topological Sort', 'Memoization', 'Ordered Map', 'C', 'Combinatorics', 'Prefix Sum', 'Shortest Path'] | 1 |
number-of-ways-to-arrive-at-destination | C++ Solution || Detailed Explanation | c-solution-detailed-explanation-by-rohit-jwvm | IntuitionThe problem requires us to count the number of ways to reach the last node from the first node using the shortest path. This can be achieved using Dijk | Rohit_Raj01 | NORMAL | 2025-03-23T04:15:57.063280+00:00 | 2025-03-23T04:15:57.063280+00:00 | 625 | false | # Intuition
The problem requires us to count the number of ways to reach the last node from the first node using the shortest path. This can be achieved using Dijkstra's algorithm while maintaining a count of paths leading to each node via the shortest distance.
# Approach
1. **Graph Representation**: Represent the gr... | 4 | 0 | ['Dynamic Programming', 'Graph', 'Shortest Path', 'C++'] | 1 |
number-of-ways-to-arrive-at-destination | Beat 99.5% || Well explained Java Solution with Dijkstra’s Algorithm | beat-995-well-explained-java-solution-wi-hnl6 | This Java program implements Dijkstra’s Algorithm to find the number of shortest paths from node 0 to node n-1 in a weighted undirected graph, where the edges a | princebhayani | NORMAL | 2025-02-02T19:18:14.565475+00:00 | 2025-02-02T19:18:14.565475+00:00 | 760 | false | This Java program implements **Dijkstra’s Algorithm** to find the **number of shortest paths** from node `0` to node `n-1` in a weighted undirected graph, where the edges are given in the form of a `roads` array.
---
## **Step-by-Step Explanation**
### **1. Understanding the Problem**
- The function `countPaths(int ... | 4 | 0 | ['Dynamic Programming', 'Graph', 'Heap (Priority Queue)', 'Shortest Path', 'Java'] | 0 |
number-of-ways-to-arrive-at-destination | 🛣️ Simple 🧠 Python Solution beats 93 % | Dijkstra algo | | simple-python-solution-beats-93-dijkstra-yr6m | \n\n---\n\n## \uD83D\uDEA6 Count Paths from Intersection 0 to n-1 in Shortest Time \u23F1\uFE0F\n\n### \uD83D\uDE80 Problem Statement:\n\nYou are in a city with | sagarsaini_ | NORMAL | 2024-08-21T07:37:48.357448+00:00 | 2024-08-21T07:37:48.357480+00:00 | 606 | false | \n\n---\n\n## \uD83D\uDEA6 Count Paths from Intersection 0 to n-1 in Shortest Time \u23F1\uFE0F\n\n### \uD83D\uDE80 Problem Statement:\n\nYou are in a city with `n` intersections numbered from `0` to `n - 1... | 4 | 0 | ['Graph', 'Shortest Path', 'Python3'] | 0 |
number-of-ways-to-arrive-at-destination | Striver's Approach Passing all test cases | strivers-approach-passing-all-test-cases-o274 | Intuition\n Describe your first thoughts on how to solve this problem. \nWe start at one node (node 0) and want to figure out the best way to reach all other no | Priyanshi31487cs | NORMAL | 2024-05-15T17:24:47.084931+00:00 | 2024-05-15T17:24:47.084975+00:00 | 1,495 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe start at one node (node 0) and want to figure out the best way to reach all other nodes while also keeping track of the number of different paths we can take. To do this, we use a method called Dijkstra\'s algorithm, which helps us fin... | 4 | 0 | ['Breadth-First Search', 'Heap (Priority Queue)', 'Java'] | 2 |
number-of-ways-to-arrive-at-destination | Simple C++ solution | simple-c-solution-by-gcsingh1629-u7lh | Code\n\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& roads) {\n vector<pair<int, int>> adj[n];\n \n for(auto i | gcsingh1629 | NORMAL | 2023-09-02T09:52:01.507971+00:00 | 2023-09-02T09:52:01.507994+00:00 | 570 | false | # Code\n```\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& roads) {\n vector<pair<int, int>> adj[n];\n \n for(auto it : roads)\n {\n adj[it[0]].push_back({it[1], it[2]});\n adj[it[1]].push_back({it[0], it[2]});\n }\n \n p... | 4 | 0 | ['C++'] | 0 |
number-of-ways-to-arrive-at-destination | Python || 96.60% Faster || Easy || Dijkstra's | python-9660-faster-easy-dijkstras-by-pul-u9wo | \ndef countPaths(self, n: int, roads: List[List[int]]) -> int:\n adj=[[] for i in range(n)]\n for u,v,t in roads:\n adj[u].append((v,t) | pulkit_uppal | NORMAL | 2023-04-22T18:44:14.380325+00:00 | 2023-04-22T18:44:14.380376+00:00 | 1,313 | false | ```\ndef countPaths(self, n: int, roads: List[List[int]]) -> int:\n adj=[[] for i in range(n)]\n for u,v,t in roads:\n adj[u].append((v,t))\n adj[v].append((u,t))\n dist=[float(\'inf\')]*n\n ways=[0]*n\n ways[0]=1\n dist[0]=0\n pq=[]\n heapif... | 4 | 0 | ['Graph', 'Python', 'Java', 'Python3'] | 0 |
number-of-ways-to-arrive-at-destination | Best C++ Solution | best-c-solution-by-kumar21ayush03-icvk | Approach\nDijkstra\'s Algorithm\n\n# Complexity\n- Time complexity:\nO(ElogV)\n\n- Space complexity:\nO(V + E)\n\n# Code\n\nclass Solution {\npublic:\n int c | kumar21ayush03 | NORMAL | 2023-03-19T09:05:31.058901+00:00 | 2023-03-19T09:05:31.058933+00:00 | 1,602 | false | # Approach\nDijkstra\'s Algorithm\n\n# Complexity\n- Time complexity:\n$$O(ElogV)$$\n\n- Space complexity:\n$$O(V + E)$$\n\n# Code\n```\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& roads) {\n vector <pair<long long, long long>> adj[n];\n for (auto it : roads) {\n a... | 4 | 0 | ['C++'] | 0 |
number-of-ways-to-arrive-at-destination | [C++]Same as Dijkstra Alogrithm | csame-as-dijkstra-alogrithm-by-account_c-n33r | prerequisite: Dijkstra Algorithm\nvedio link :Dijkstra\'s Algorithm by Striver(Legend)\n\n#define ll long long\nconst int mod = 1e9+7;\nclass Solution {\npublic | account_changed | NORMAL | 2022-12-20T07:35:51.909697+00:00 | 2022-12-20T07:35:51.909734+00:00 | 849 | false | **prerequisite: Dijkstra Algorithm**\nvedio link :[Dijkstra\'s Algorithm by Striver(Legend)](https://youtu.be/V6H1qAeB-l4)\n```\n#define ll long long\nconst int mod = 1e9+7;\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& roads) {\n //First create an adjacency list\n vector<vect... | 4 | 0 | [] | 0 |
number-of-ways-to-arrive-at-destination | Java Solution Dijkstra using Min Heap with extensive Comments. Hope it helps... | java-solution-dijkstra-using-min-heap-wi-gl9k | \tclass Solution {\n\t\tpublic int countPaths(int n, int[][] roads) {\n\t\t\tList[] graph = constructGraph(n, roads); // returns adjacency List for given road[] | fameissrani | NORMAL | 2022-07-16T04:16:23.260099+00:00 | 2022-07-16T04:21:20.053368+00:00 | 515 | false | \tclass Solution {\n\t\tpublic int countPaths(int n, int[][] roads) {\n\t\t\tList<Edge>[] graph = constructGraph(n, roads); // returns adjacency List for given road[][]\n\n\t\t\tPriorityQueue<Pair> pq = new PriorityQueue<>();\n\t\t\tint[] dist = new int[n]; // dist array stores the min. cost/weight/time to reach from s... | 4 | 0 | [] | 0 |
number-of-ways-to-arrive-at-destination | [C++] : Using dikstra + toposort(DAG) + DP | c-using-dikstra-toposortdag-dp-by-zanhd-vd8x | \n#define ll long long int\nconst ll M = 1e9 + 7;\n#define MOD_ADD(a,b,m) ((a % m) + (b % m)) % m\n\nclass Solution {\npublic:\n \n static bool compare(pa | zanhd | NORMAL | 2022-04-15T16:30:56.466156+00:00 | 2022-04-15T16:30:56.466215+00:00 | 468 | false | ```\n#define ll long long int\nconst ll M = 1e9 + 7;\n#define MOD_ADD(a,b,m) ((a % m) + (b % m)) % m\n\nclass Solution {\npublic:\n \n static bool compare(pair<ll,ll> a, pair<ll,ll> b)\n {\n return a.second > b.second; // min heap\n }\n \n vector<ll> dikstra(ll src, vector<vector<pair<ll,ll>>> ... | 4 | 0 | ['Dynamic Programming', 'Topological Sort'] | 0 |
number-of-ways-to-arrive-at-destination | C++ || O(mlogn) || Approach Explained || Two solutions - i) Dijkstra ii) Dijkstra + DP | c-omlogn-approach-explained-two-solution-qxmm | I figured out Solution ii) first and then got to know that only Dijkstra would suffice and got Solution i) after seeing discussions. Both have same time complex | niksparmar22 | NORMAL | 2021-10-22T14:21:26.277551+00:00 | 2021-10-22T14:39:04.568212+00:00 | 326 | false | I figured out Solution ii) first and then got to know that only Dijkstra would suffice and got Solution i) after seeing discussions. Both have same time complexity and both passed all test cases.\n\nSolution i)\n\nApproach - Apply Dijkstra from n-1. Suppose waysToReachN1[i] denotes # of ways to reach n-1 from i. Our an... | 4 | 0 | [] | 0 |
number-of-ways-to-arrive-at-destination | TestCases Wrong | testcases-wrong-by-lagahuahubro-ymqf | I am able to give custom test cases with time = 0. But in the constraints it is given\n1 <= timei <= 10^9.\nplease fix it.\n | lagaHuaHuBro | NORMAL | 2021-09-09T12:29:43.295410+00:00 | 2021-09-09T12:29:43.295455+00:00 | 129 | false | I am able to give custom test cases with time = 0. But in the constraints it is given\n```1 <= timei <= 10^9```.\nplease fix it.\n | 4 | 0 | [] | 0 |
number-of-ways-to-arrive-at-destination | C++ Dijkstra Two Solutions | c-dijkstra-two-solutions-by-shtanriverdi-5feu | Time Complexity: O(V^2 log V) where V is the number of node and E is the edges. \nSince we push each node to the minheap only once, that why we say log(V)\nSpac | shtanriverdi | NORMAL | 2021-08-31T17:10:39.367150+00:00 | 2021-08-31T17:19:18.450111+00:00 | 693 | false | **Time Complexity: O(V^2 log V)** where V is the number of node and E is the edges. \nSince we push each node to the minheap only once, that why we say log(V)\n**Space Complexity: O(V+ E)**\n\n**Optimized Solution**\n```\nclass Solution {\npublic:\n int countPaths(int n, vector<vector<int>>& roads) {\n // Bui... | 4 | 0 | ['C'] | 1 |
number-of-ways-to-arrive-at-destination | JAVA SOLUTION USING DIJKSTRA AND DP | java-solution-using-dijkstra-and-dp-by-s-fnsn | The basic idea is to dijkstra algorithm and find the minimum path from 0 to (n - 1). The catch is that while traversing from one node to another if we encounter | Subhankar752 | NORMAL | 2021-08-26T06:21:29.492755+00:00 | 2021-08-26T06:21:29.492803+00:00 | 1,502 | false | The basic idea is to dijkstra algorithm and find the minimum path from 0 to (n - 1). The catch is that while traversing from one node to another if we encounter a node with more distance then we will initialise the number of ways to reach that node. Similarly, if we encounter a node with same distance as of previous co... | 4 | 1 | ['Dynamic Programming', 'Java'] | 4 |
number-of-ways-to-arrive-at-destination | 0 ms C/C++, 1 ms JS. BFS and Dijkstra. Beats 100.00% | 0-ms-cc-1-ms-js-bfs-and-dijkstra-beats-1-kr5z | Approach
BFS 1 ms in JavaScript.
Dijkstra's Algorithm 40 ms in JavaScript.
Complexityv - vertices, e - edges.
Time complexity: BFS O(v3), Dijkstra O((v+e)logv) | nodeforce | NORMAL | 2025-03-24T03:48:57.130697+00:00 | 2025-03-24T03:51:12.938519+00:00 | 48 | false | # Approach
1. BFS `1 ms` in JavaScript.
2. Dijkstra's Algorithm `40 ms` in JavaScript.


', 'Shortest Path', 'C++', 'TypeScript', 'JavaScript'] | 1 |
number-of-ways-to-arrive-at-destination | Dijkstra N log(n) | Greedy Logic | dijkstra-n-logn-greedy-logic-by-1_b3-d7p6 | IntuitionWe can observe that this is a shortest path problem. So Dijkstra or similar algorithm comes quickly to intuition. We will be using Dijkstra.
We can als | 1_b3 | NORMAL | 2025-03-23T10:30:13.336251+00:00 | 2025-03-23T10:30:13.336251+00:00 | 387 | false | # Intuition
We can observe that this is a shortest path problem. So Dijkstra or similar algorithm comes quickly to intuition. We will be using Dijkstra.
We can also notice one more thing , that all the ways which go from 0 to n-1 have same weighted distance which , overall is the shortest path from 0 to n-1.
<!-- Des... | 3 | 0 | ['Greedy', 'Shortest Path', 'C++', 'Java', 'Python3'] | 0 |
number-of-ways-to-arrive-at-destination | ✅✅ Dijkstra's Algorithm || Beginner Friendly || Easiest Code | dijkstras-algorithm-beginner-friendly-ea-ibtp | Approach1. Graph Representation
The given graph is an undirected weighted graph.
Construct an adjacency list adj using an unordered map.
2. Dijkstra’s Algorithm | Karan_Aggarwal | NORMAL | 2025-03-23T10:02:28.615192+00:00 | 2025-03-23T10:02:28.615192+00:00 | 171 | false | # Approach
### **1. Graph Representation**
- The given graph is an **undirected weighted graph**.
- Construct an **adjacency list** `adj` using an unordered map.
### **2. Dijkstra’s Algorithm**
- **Priority queue (Min-Heap)** is used to always process the node with the smallest distance first.
- Maintain a **`time[]`... | 3 | 0 | ['Breadth-First Search', 'Graph', 'Shortest Path', 'C++'] | 0 |
number-of-ways-to-arrive-at-destination | 🎓Wave Relaxation Algorithm Explanation | 5~17ms (Beats 98~100) O(n×(n+m)) | 62.8~65.5 O(n+m) | wave-relaxation-algorithm-explanation-51-n7zt | IntuitionThe problem requires calculating the number of "shortest paths" from the starting node 0 to the destination node n - 1, with the final answer taken mod | whats2000 | NORMAL | 2025-03-23T09:15:32.743656+00:00 | 2025-03-24T01:33:24.257483+00:00 | 96 | false | # Intuition
The problem requires calculating the number of "shortest paths" from the starting node `0` to the destination node `n - 1`, with the final answer taken modulo $10^9+7$. We can visualize the problem as a map where:
- Each **node (intersection)** represents a junction.
- Each **edge (road)** represents a pat... | 3 | 0 | ['Dynamic Programming', 'Graph', 'Shortest Path', 'TypeScript', 'JavaScript'] | 2 |
number-of-ways-to-arrive-at-destination | Simple C++ | Beats 100% | Dijkstra Algo | Easy to Understand | simple-c-beats-100-dijkstra-algo-easy-to-356b | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | AK200199 | NORMAL | 2025-03-23T09:12:29.353871+00:00 | 2025-03-23T09:12:29.353871+00:00 | 240 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 3 | 0 | ['C++'] | 0 |
number-of-ways-to-arrive-at-destination | 🔥 Dijkstra's Algorithm | 🚀 Priority Queue | ⏱️ TC: O(E log V) 🎯 | dijkstras-algorithm-priority-queue-tc-oe-9m57 | IntuitionWe use Dijkstra's algorithm to find the shortest paths and simultaneously count how many different ways we can reach each node with the current shortes | Ashok_Kumar_25 | NORMAL | 2025-03-23T08:20:48.010089+00:00 | 2025-03-23T08:20:48.010089+00:00 | 362 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We use **Dijkstra's algorithm** to find the shortest paths and simultaneously count how many different ways we can reach each node with the current shortest distance.
# Approach
<!-- Describe your approach to solving the problem. -->
1. Bui... | 3 | 0 | ['Dynamic Programming', 'Graph', 'Shortest Path', 'Python3'] | 0 |
number-of-ways-to-arrive-at-destination | Dijkstra with a Twist: A Beginner-Friendly Editorial Guide to Count Shortest Paths 🛤️😏 | dijkstra-with-a-twist-a-beginner-friendl-lqs2 | Dijkstra with a Twist: A Beginner-Friendly Guide to Count Shortest Paths 🛤️😏Oh look, another graph problem where we need to find the shortest paths—how original | Ansh_Ghawri | NORMAL | 2025-03-23T07:12:59.124437+00:00 | 2025-03-23T07:22:03.703011+00:00 | 131 | false | # Dijkstra with a Twist: A Beginner-Friendly Guide to Count Shortest Paths 🛤️😏
Oh look, another graph problem where we need to find the shortest paths—how *original*! 🙄 This time, we’re tasked with counting the number of shortest paths from node 0 to node \(n-1\) in a graph, because apparently just finding the shor... | 3 | 0 | ['Dynamic Programming', 'Graph', 'Shortest Path', 'C++'] | 0 |
number-of-ways-to-arrive-at-destination | Ultimate Graph Solution: Dijkstra + BFS-style + Path Counting + Min-Heap | Count All Shortest Paths | ultimate-graph-solution-dijkstra-bfs-sty-uv11 | Intuition
We want to find the number of different shortest paths from node 0 to node (n - 1).
This is a classic graph problem where we compute the shortest path | alperensumeroglu | NORMAL | 2025-03-23T00:20:22.416112+00:00 | 2025-03-23T00:20:22.416112+00:00 | 93 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1. We want to find the number of *different shortest paths* from node 0 to node (n - 1).
2. This is a classic graph problem where we compute the shortest path using Dijkstra's algorithm,
3. but we also count how many different ways we can ... | 3 | 0 | ['Dynamic Programming', 'Greedy', 'Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'Heap (Priority Queue)', 'Prefix Sum', 'Shortest Path', 'Python3'] | 0 |
number-of-ways-to-arrive-at-destination | I was here | i-was-here-by-akuma-greyy-57ku | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Akuma-Greyy | NORMAL | 2024-06-20T16:52:44.422981+00:00 | 2024-06-20T16:52:44.423014+00:00 | 857 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 3 | 0 | ['Dynamic Programming', 'Graph', 'Topological Sort', 'Shortest Path', 'Python3'] | 0 |
number-of-ways-to-arrive-at-destination | Efficient Shortest Path Computation and Path Counting using Dijkstra's Algorithm | efficient-shortest-path-computation-and-szxvl | Intuition\nWe use Dijkstra\'s algorithm to find the shortest paths from a given source node to all other nodes in a weighted undirected graph.\n\n# Approach\n1. | Stella_Winx | NORMAL | 2024-05-20T10:37:18.960252+00:00 | 2024-05-20T10:37:18.960285+00:00 | 1,330 | false | # Intuition\nWe use Dijkstra\'s algorithm to find the shortest paths from a given source node to all other nodes in a weighted undirected graph.\n\n# Approach\n1. Graph Representation: The graph is represented using an adjacency list, which is a collection of lists (in this case, implemented using an unordered map) whe... | 3 | 0 | ['Graph', 'Shortest Path', 'C++'] | 0 |
number-of-ways-to-arrive-at-destination | Striver's Easy C++ Approach | Solution | strivers-easy-c-approach-solution-by-ish-r11k | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem involves finding the number of different shortest paths from the source nod | ishajangir2002 | NORMAL | 2024-03-22T10:28:00.458239+00:00 | 2024-03-22T10:28:00.458262+00:00 | 528 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem involves finding the number of different shortest paths from the source node to the destination node in a graph with weighted edges. We can use Dijkstra\'s algorithm to find the shortest paths and keep track of the number of w... | 3 | 0 | ['C++'] | 1 |
number-of-ways-to-arrive-at-destination | Easy To Understand C++ Solution || Dijkstra | easy-to-understand-c-solution-dijkstra-b-4x49 | Intuition\nUse Dijkstra Algorithm to find the shortest distance between source node and destination node.Mean while maintain a seperate array/vector which takes | kashyap_25 | NORMAL | 2023-07-16T12:40:32.861808+00:00 | 2023-07-16T12:40:32.861830+00:00 | 1,501 | false | # Intuition\nUse Dijkstra Algorithm to find the shortest distance between source node and destination node.Mean while maintain a seperate array/vector which takes a note of number of shortest path to that particular node.\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nExcept for m... | 3 | 0 | ['Breadth-First Search', 'Graph', 'C++'] | 1 |
number-of-ways-to-arrive-at-destination | C++ BFS Dijkastra 🔥🔥🔥 | c-bfs-dijkastra-by-abhishek6487209-ez71 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Abhishek6487209 | NORMAL | 2023-05-24T14:31:22.626468+00:00 | 2024-04-10T16:10:11.667746+00:00 | 1,604 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 3 | 0 | ['Breadth-First Search', 'C++'] | 1 |
number-of-ways-to-arrive-at-destination | Dijkstra + Top Down DP C++ ✌️ | dijkstra-top-down-dp-c-by-convexchull-m7xl | Intuition\nApplying dijkstra to find shortest distance then using a dfs to find number of paths having this shortest distance.\n\n\n# Approach\nFirst apply dijk | ConvexChull | NORMAL | 2022-10-26T14:26:37.250678+00:00 | 2022-10-26T14:26:37.250710+00:00 | 631 | false | # Intuition\nApplying dijkstra to find shortest distance then using a dfs to find number of paths having this shortest distance.\n\n\n# Approach\nFirst apply dijkstra from n-1 node then use the distance array generated in a dfs function which is memoized for optimization.\n\n\n# Complexity\n- Time complexity: O(ElogV) ... | 3 | 0 | ['Dynamic Programming', 'Depth-First Search', 'Graph', 'Shortest Path', 'C++'] | 1 |
number-of-ways-to-arrive-at-destination | C++ | Dijkstra | Number of ways to arrive at destination | c-dijkstra-number-of-ways-to-arrive-at-d-syh0 | \nclass Solution {\npublic:\n const int MOD = 1e9+7;\n int countPaths(int n, vector<vector<int>>& roads) {\n vector<long long> dist(n,1e18), path(n | bits_069 | NORMAL | 2022-07-23T10:22:47.238441+00:00 | 2022-07-23T10:22:47.238488+00:00 | 433 | false | ```\nclass Solution {\npublic:\n const int MOD = 1e9+7;\n int countPaths(int n, vector<vector<int>>& roads) {\n vector<long long> dist(n,1e18), path(n,0);\n vector<vector<pair<int,int>>> g(n);\n for(int i=0; i<roads.size(); i++){\n g[roads[i][0]].push_back({roads[i][1],roads[i][2]}... | 3 | 0 | ['Math', 'C'] | 0 |
number-of-ways-to-arrive-at-destination | ✅✅C++ Dijkstra || BFS || | c-dijkstra-bfs-by-smilyface_123-7fqr | If Helpful Please Upvoke\n\n\n#define ll long long\nclass Solution{\n public:\n int mod = 1e9 + 7;\n int countPaths(int n, vector<vector < int>> &r | smilyface_123 | NORMAL | 2022-06-20T05:31:56.435271+00:00 | 2022-06-20T05:31:56.435309+00:00 | 354 | false | **If Helpful Please Upvoke**\n\n```\n#define ll long long\nclass Solution{\n public:\n int mod = 1e9 + 7;\n int countPaths(int n, vector<vector < int>> &roads){\n priority_queue<pair<ll, ll>, vector< pair<ll, ll>>, greater<pair<ll, ll>>> pq;\n pq.push({ 0,0 });\n vector<ll> dist(n, LLO... | 3 | 0 | [] | 0 |
number-of-ways-to-arrive-at-destination | [C++] | Dijkstra | c-dijkstra-by-makhonya-dueo | \nclass Solution {\npublic:\n int count = 0, MOD = 1e9 + 7;\n int countPaths(int n, vector<vector<int>>& r) {\n vector<pair<long long, long long>> | makhonya | NORMAL | 2022-06-15T05:51:48.568312+00:00 | 2022-06-15T05:51:48.568356+00:00 | 212 | false | ```\nclass Solution {\npublic:\n int count = 0, MOD = 1e9 + 7;\n int countPaths(int n, vector<vector<int>>& r) {\n vector<pair<long long, long long>> A[n];\n vector<long long> dist(n, LONG_MAX), ways(n);\n ways[0] = 1;\n priority_queue<pair<long long, long long>, vector<pair<long long,... | 3 | 0 | ['C', 'C++'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.