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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
network-delay-time | Dijkstra's algorithm solution explanation (with Python 3) | dijkstras-algorithm-solution-explanation-0ld1 | Since the graph of network delay times is a weighted, connected graph (if the graph isn\'t connected, we can return -1) with non-negative weights, we can find t | enmingliu | NORMAL | 2020-05-17T04:19:08.330246+00:00 | 2020-05-17T04:19:08.330282+00:00 | 13,183 | false | Since the graph of network delay times is a weighted, connected graph (if the graph isn\'t connected, we can return -1) with non-negative weights, we can find the shortest path from root node K into any other node using Dijkstra\'s algorithm. If we want to find how long it will take for all nodes to receive the signal,... | 33 | 0 | ['Queue', 'Heap (Priority Queue)', 'Ordered Set', 'Python', 'Python3'] | 7 |
network-delay-time | Clean JavaScript Bellman-Ford solution | clean-javascript-bellman-ford-solution-b-0s9d | Introduction to Bellman-Ford https://www.youtube.com/watch?v=obWXjtg0L64\n\n\nconst networkDelayTime = (times, N, K) => {\n const time = Array(N + 1).fill(Infi | hongbo-miao | NORMAL | 2019-10-28T06:44:12.569384+00:00 | 2020-09-02T15:48:27.248283+00:00 | 2,746 | false | Introduction to Bellman-Ford https://www.youtube.com/watch?v=obWXjtg0L64\n\n```\nconst networkDelayTime = (times, N, K) => {\n const time = Array(N + 1).fill(Infinity);\n time[K] = 0;\n for (let i = 0; i < N; i++) {\n for (const [u, v, t] of times) {\n if (time[u] === Infinity) continue;\n if (time[v] >... | 29 | 0 | ['JavaScript'] | 3 |
network-delay-time | c++ dijkstra with priority queue | c-dijkstra-with-priority-queue-by-kelvin-qgft | \nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n // build graph \n vector<vector<pair<int, int> | kelvinshcn | NORMAL | 2019-07-21T18:16:11.913404+00:00 | 2019-07-21T18:16:11.913436+00:00 | 2,359 | false | ```\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n // build graph \n vector<vector<pair<int, int> > > graph(N+1);\n for (auto edge : times) {\n int fr_node = edge[0];\n int to_node = edge[1];\n int cost = edge[2];\... | 24 | 0 | ['C', 'Heap (Priority Queue)'] | 2 |
network-delay-time | Shortest Path Faster Algorithm (SPFA) - Java 26ms beats 86.85% | shortest-path-faster-algorithm-spfa-java-e50b | SPFA is an improvement on top of Bellman-Ford, and prabably easier to understand than Dijkstra. It is popular with students who take part in NOIP and ACM-ICPC. | xiong6 | NORMAL | 2019-03-04T00:59:59.481689+00:00 | 2019-03-04T00:59:59.481733+00:00 | 2,467 | false | SPFA is an improvement on top of Bellman-Ford, and prabably easier to understand than Dijkstra. It is popular with students who take part in NOIP and ACM-ICPC. The key points are\n1. We use a FIFO queue to store vertices that are about to be relaxed.\n2. Vertices should be reinserted into the queue whenever its distan... | 22 | 0 | [] | 2 |
network-delay-time | [Java] | 🔥 100% | Dijkstra | Bellman Ford | SPFA | Floyd-Warshall | java-100-dijkstra-bellman-ford-spfa-floy-wwj8 | Dijkstra\n- TC: O(E + Elog(E))\n- SC: O(V+E)\n- 8 ms\n## Two different ways\njava []\nclass Solution {\n record Node(int i, int t) {}\n public int network | byegates | NORMAL | 2023-01-16T07:22:17.948276+00:00 | 2023-03-05T07:04:17.304909+00:00 | 4,259 | false | # Dijkstra\n- TC: O(E + Elog(E))\n- SC: O(V+E)\n- [8 ms](https://leetcode.com/problems/network-delay-time/submissions/879004707/)\n## Two different ways\n```java []\nclass Solution {\n record Node(int i, int t) {}\n public int networkDelayTime(int[][] times, int n, int k) {\n // create graph\n List<... | 20 | 1 | ['Dynamic Programming', 'Java'] | 3 |
network-delay-time | DFS / BFS / Dijkstra / Bellman Ford / Floyd Warshall easy to understand [Python] | dfs-bfs-dijkstra-bellman-ford-floyd-wars-54ca | ```\nclass Solution:\n \n def BellmanFord(self, times, N, K):\n \n # Bellman Ford\n cost = {i:float(\'inf\') for i in range(1, N+1)}\ | prabhjyot28 | NORMAL | 2020-06-24T16:07:49.908541+00:00 | 2020-06-24T16:24:18.531546+00:00 | 2,118 | false | ```\nclass Solution:\n \n def BellmanFord(self, times, N, K):\n \n # Bellman Ford\n cost = {i:float(\'inf\') for i in range(1, N+1)}\n cost[K] = 0\n for i in range(N-1):\n update = False\n for u, v, c in times:\n if cost[u]+c<cost[v]:\n ... | 19 | 0 | ['Depth-First Search', 'Breadth-First Search', 'Python3'] | 2 |
network-delay-time | JAVA Djikstra's Solution | java-djikstras-solution-by-wssx12138-n61i | Someone would use Queue instead of PriorityQueue.\n\n public int networkDelayTime(int[][] times, int N, int K) {\n if (times == null || times.length = | wssx12138 | NORMAL | 2017-12-13T02:53:07.755000+00:00 | 2018-10-21T15:27:18.475589+00:00 | 3,919 | false | Someone would use Queue instead of PriorityQueue.\n```\n public int networkDelayTime(int[][] times, int N, int K) {\n if (times == null || times.length == 0 || times[0].length == 0) {\n return -1;\n }\n int[][] grid = new int[N + 1][N + 1];\n for (int[] arr : grid) {\n A... | 19 | 4 | [] | 4 |
network-delay-time | Java || best question to understand Dijkastras | java-best-question-to-understand-dijkast-o6ca | \nclass Solution {\n public int networkDelayTime(int[][] times, int n, int K) {\n int[][] graph = new int[n][n];\n for(int i = 0; i < n ; i++) | achyutav | NORMAL | 2022-05-14T01:17:44.392245+00:00 | 2022-05-18T09:52:48.096798+00:00 | 3,736 | false | ```\nclass Solution {\n public int networkDelayTime(int[][] times, int n, int K) {\n int[][] graph = new int[n][n];\n for(int i = 0; i < n ; i++) Arrays.fill(graph[i], Integer.MAX_VALUE);\n for( int[] rows : times) graph[rows[0] - 1][rows[1] - 1] = rows[2]; \n \n int[] dist... | 16 | 0 | ['Java'] | 3 |
network-delay-time | Straightforward Python Dijkstra's | straightforward-python-dijkstras-by-yang-p2fw | Nothing fancy, just apply Dijkstra's algorithm to the input. The only pitfall is that you have to check that all nodes are reachable from source node, else retu | yangshun | NORMAL | 2017-12-10T06:37:18.770000+00:00 | 2022-03-18T01:01:22.136449+00:00 | 5,046 | false | Nothing fancy, just apply Dijkstra's algorithm to the input. The only pitfall is that you have to check that all nodes are reachable from source node, else return -1.\n\n*- Yangshun*\n\n```\nclass Solution(object):\n def networkDelayTime(self, times, N, K):\n from collections import defaultdict\n nodes... | 16 | 3 | [] | 3 |
network-delay-time | Simple Java Solution using BFS (similar to dijkstra's shortest path algorithm) with explanation | simple-java-solution-using-bfs-similar-t-dffd | The idea is to find the time to reach every other node from given node K\nThen, to check if all nodes can be reached and if it can be reached then return the ti | ashish53v | NORMAL | 2017-12-10T04:02:52.038000+00:00 | 2018-09-26T05:34:41.934968+00:00 | 6,912 | false | The idea is to find the time to reach every other node from given node K\nThen, to check if all nodes can be reached and if it can be reached then return the time taken to reach the farthest node (node which take longest to get the signal).\nAs the signal traverses concurrently to all nodes, we have to find the maximum... | 16 | 4 | [] | 9 |
network-delay-time | Simple Dijkstra's Solution in Java along with great intuition using Priority Queue | simple-dijkstras-solution-in-java-along-oai2g | Intuition\nUsing the simple generic Dijkstras algorithm with little tweak to solve the problem.\nData Structures to be used here is:\n1. Array: to store distanc | sarja830 | NORMAL | 2022-11-09T14:44:53.191414+00:00 | 2024-05-02T12:08:41.347082+00:00 | 1,728 | false | # Intuition\nUsing the simple generic Dijkstras algorithm with little tweak to solve the problem.\nData Structures to be used here is:\n1. **Array**: to store distance from source\n*In the code*: d - to store distance of each vertex from source node.\nInitially make it infinity for all the vertex except source.\nFor so... | 15 | 0 | ['Greedy', 'Graph', 'Heap (Priority Queue)', 'Java'] | 0 |
network-delay-time | Easy C++ Solution | Dijkstras Algo | Explained | easy-c-solution-dijkstras-algo-explained-rzqu | \nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n vector <vector<pair<int, int>>> neighs(n+1); // | ahanavish | NORMAL | 2022-02-08T17:52:03.766911+00:00 | 2022-05-15T08:02:57.031163+00:00 | 1,376 | false | ```\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n vector <vector<pair<int, int>>> neighs(n+1); //to store the neighbors and weights corresponding to each vertices\n for(auto t: times) //pushing vertex, neighbor, wei... | 13 | 1 | ['Graph', 'C', 'Heap (Priority Queue)', 'C++'] | 3 |
network-delay-time | Java Simple Bellman-Ford Algorithm Solution - 2 Approaches with Explanation | java-simple-bellman-ford-algorithm-solut-e38l | 1) This approach shows that we can use the times array given to us as number of edges and perform Bellman-Ford Algorithm to be able to also detect any negative | algosolver | NORMAL | 2020-04-13T02:28:05.773969+00:00 | 2020-04-13T02:28:05.774019+00:00 | 1,374 | false | 1) This approach shows that we can use the times array given to us as number of edges and perform Bellman-Ford Algorithm to be able to also detect any negative cycles.\n```\nclass Solution {\n public int networkDelayTime(int[][] times, int N, int K) {\n //create distance array and set them to MAX_VALUE except... | 13 | 0 | ['Java'] | 1 |
network-delay-time | c++ dijkstra concise | c-dijkstra-concise-by-laiden-7yc9 | \nclass Solution {\npublic:\n vector<int> dijkstra(vector<vector<pair<int,int>>>& g, int src){\n int n = g.size();\n vector<int> ret(n, -1);\n | laiden | NORMAL | 2018-04-25T19:20:30.052890+00:00 | 2018-10-20T16:55:06.404394+00:00 | 2,047 | false | ```\nclass Solution {\npublic:\n vector<int> dijkstra(vector<vector<pair<int,int>>>& g, int src){\n int n = g.size();\n vector<int> ret(n, -1);\n \n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<void>> q;\n q.push({0,src});\n\n while(!q.empty()){\n ... | 13 | 0 | [] | 3 |
network-delay-time | Dijkstra's Algorithm, but it's shortest time instead of shortest distance. | dijkstras-algorithm-but-its-shortest-tim-72wx | IntuitionBasically using Dijsktra's algorithm but instead of distance and weight, its just using time.ApproachUse exact ditto-copy paste of dijsktra algorithm.. | akhi_101 | NORMAL | 2025-02-18T14:32:57.623383+00:00 | 2025-02-18T14:32:57.623383+00:00 | 1,743 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Basically using Dijsktra's algorithm but instead of distance and weight, its just using time.
# Approach
<!-- Describe your approach to solving the problem. -->
Use exact ditto-copy paste of dijsktra algorithm... But,
the distance we usuall... | 12 | 0 | ['Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Shortest Path', 'Java'] | 6 |
network-delay-time | Javascript Using Dijikstra Algorithm and Priority Queue (faster than 88.14% of js submissions) | javascript-using-dijikstra-algorithm-and-tj9g | Based on Dijikstra Algorithm (using Priority Queue). Finding distance from source node K\n\n\nclass QElement { \n constructor(element, priority) \n { \n | sanketnitk | NORMAL | 2020-09-25T13:41:25.040145+00:00 | 2020-09-25T13:44:45.192783+00:00 | 1,735 | false | Based on Dijikstra Algorithm (using Priority Queue). Finding distance from source node K\n\n```\nclass QElement { \n constructor(element, priority) \n { \n this.element = element; \n this.priority = priority; \n } \n}\n\nclass PriorityQueue {\n constructor() {\n this.items = [];\n }\... | 12 | 0 | ['Graph', 'Heap (Priority Queue)', 'JavaScript'] | 3 |
network-delay-time | Java DFS | java-dfs-by-fllght-xkxl | java\nprivate final Map<Integer, List<Node>> connected = new HashMap<>();\n\n public int networkDelayTime(int[][] times, int n, int k) {\n for (int[] | FLlGHT | NORMAL | 2022-05-14T07:22:07.956850+00:00 | 2022-05-14T07:22:07.956891+00:00 | 1,735 | false | ```java\nprivate final Map<Integer, List<Node>> connected = new HashMap<>();\n\n public int networkDelayTime(int[][] times, int n, int k) {\n for (int[] time : times) {\n connected.putIfAbsent(time[0], new ArrayList<>());\n connected.get(time[0]).add(new Node(time[2], time[1]));\n ... | 11 | 0 | ['Depth-First Search', 'Java'] | 1 |
network-delay-time | Very very Simple | C++ | BFS | very-very-simple-c-bfs-by-megamind-zt6a | Initialize the queue with the node currNode as k and store the corresponding time required in signal vector as 0. The signal from node currNode will travel to e | megamind_ | NORMAL | 2022-05-14T02:12:35.471420+00:00 | 2022-05-14T02:12:35.471481+00:00 | 2,775 | false | Initialize the queue with the node currNode as k and store the corresponding time required in signal vector as 0. The signal from node currNode will travel to every adjacent node. Iterate over every adjacent node neighborNode. We will add each adjacent node to the queue only if the signal from currNode via the current ... | 11 | 0 | ['Breadth-First Search'] | 4 |
network-delay-time | [C++] Djikstra's Algorithm || Bellman Ford || Concise and very easy to understand | c-djikstras-algorithm-bellman-ford-conci-p79t | Approach : Dijkstra\'s Shortest Path Algorithm (Using Priority queue)\n\nFirst, from the given input vector, we have to make the adjacency list for the required | devrajsingh | NORMAL | 2022-05-14T05:22:52.041591+00:00 | 2022-05-14T05:22:52.041621+00:00 | 1,786 | false | ***Approach : Dijkstra\'s Shortest Path Algorithm (Using Priority queue)***\n\nFirst, from the given input vector, we have to make the adjacency list for the required directed weighted graph for Dijkstra\'s Algorithm\n\nTo calculate the minimum distance to all other nodes from given "k" node. For minimum distance , we ... | 9 | 0 | ['Graph', 'C', 'C++'] | 0 |
network-delay-time | python 10 line Optimized Djikstra solution & 8 line Bellman Ford | python-10-line-optimized-djikstra-soluti-c0mp | Solution 1: Djikstra O(NlogN + len(times)) \npython\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], N: int, K: int) -> int:\n gr | jason003 | NORMAL | 2019-03-09T14:00:04.002165+00:00 | 2019-06-11T11:43:45.500495+00:00 | 571 | false | Solution 1: Djikstra O(NlogN + len(times)) \n```python\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], N: int, K: int) -> int:\n graph, seen, heap = collections.defaultdict(dict), set(), [(0, K)]\n for u, v, w in times:\n graph[u][v] = w\n while heap:\n ... | 9 | 0 | [] | 1 |
network-delay-time | Simple Solution with Diagrams in Video - JavaScript, C++, Java, Python | simple-solution-with-diagrams-in-video-j-0w6m | Video\nPlease upvote here so others save time too!\n\nLike the video on YouTube if you found it useful\n\nClick here to subscribe on YouTube:\nhttps://www.youtu | danieloi | NORMAL | 2024-12-04T16:36:05.759520+00:00 | 2024-12-04T16:36:05.759550+00:00 | 1,759 | false | # Video\nPlease upvote here so others save time too!\n\nLike the video on YouTube if you found it useful\n\nClick here to subscribe on YouTube:\nhttps://www.youtube.com/@mayowadan?sub_confirmation=1\n\nThanks!\n\nhttps://youtu.be/mJT48XM9g9g?si=l_zKDD8aCgzvo5vi\n\n```Javascript []\n/**\n * @param {number[][]} times\n *... | 8 | 0 | ['Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 0 |
network-delay-time | Easy classic DIJKSTRA C++ | easy to understand :) | easy-classic-dijkstra-c-easy-to-understa-s4p5 | Intuition\nshortest path / distance nikalna ho jaha bhi sidha dijkstra lagado..\nwe get the distance from node k to every node sabse kam length ka.\nphir check | sach_code | NORMAL | 2023-07-31T18:51:19.490410+00:00 | 2023-08-01T20:33:29.026826+00:00 | 538 | false | # Intuition\nshortest path / distance nikalna ho jaha bhi sidha dijkstra lagado..\nwe get the distance from node k to every node sabse kam length ka.\nphir check karlo dist m konsa sabse dur hai..\nutna hi time lagega max spread hone m..\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach... | 8 | 0 | ['Breadth-First Search', 'Heap (Priority Queue)', 'C++'] | 1 |
network-delay-time | 3 APPROACHES || DIFFERENCE BETWEEN DIJKSTRA | BELMAN FORD | FLOYDD WARSHELL || C++ | 3-approaches-difference-between-dijkstra-e0qd | DIJKSTRA ALGORITHM\n\n HELPS TO FIND SSSP ( SINGLE SOURCE SHORTEST PATH ) TO EVERY OTHER NODES\n CAN BE IMPLEMENTED BY BOTH PRIORITY QUEUES AND SETS\n\nAD | dikshant_sh | NORMAL | 2023-03-30T10:03:14.767829+00:00 | 2023-03-30T10:15:19.532409+00:00 | 803 | false | **DIJKSTRA ALGORITHM**\n\n* HELPS TO FIND SSSP ( **SINGLE SOURCE SHORTEST PATH** ) TO EVERY OTHER NODES\n* CAN BE IMPLEMENTED BY BOTH PRIORITY QUEUES AND SETS\n\n*ADVANTAGES*\n1. T.C - O( ElogV )\n\n*DISADVANTAGES*\n1. IT WON\'T WORKS FOR THE NEGATIVE EDGES\n2. UNABLE TO IDENTIFY NEGATIVE CYCLES\n```\nclass So... | 8 | 0 | ['Graph', 'C'] | 2 |
network-delay-time | Java Dijkstra With Clean and Commented Solution 100% | java-dijkstra-with-clean-and-commented-s-cx0e | \nclass Solution {\n \n public int total = 0; // to return the max value\n \n public class Edge // As graph is arrayList of edges so firstly creati | sandeepbk01 | NORMAL | 2022-05-14T02:40:50.553925+00:00 | 2023-06-06T17:45:50.320661+00:00 | 1,088 | false | ```\nclass Solution {\n \n public int total = 0; // to return the max value\n \n public class Edge // As graph is arrayList of edges so firstly creating an edge class\n {\n int src; // source\n int nbr; // its destination or source\'s neighbour\n int wt; // corresponding edge weigh... | 8 | 0 | ['Heap (Priority Queue)', 'Java'] | 2 |
network-delay-time | Python 3 | Different 4 Methods | No Explanation | python-3-different-4-methods-no-explanat-llts | Approach \#1. Dijkstra\npython\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:\n dp = [sys.maxsize] * n\ | idontknoooo | NORMAL | 2021-12-06T06:30:38.975330+00:00 | 2021-12-06T07:07:41.616163+00:00 | 1,153 | false | ### Approach \\#1. Dijkstra\n```python\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:\n dp = [sys.maxsize] * n\n dp[k-1] = 0\n graph = collections.defaultdict(list)\n for s, e, w in times:\n graph[s].append((e, w))\n visited... | 8 | 1 | ['Python', 'Python3'] | 0 |
network-delay-time | Understanding Djikstra Algorithm for Beginners - Java Solution 9ms ✨ | understanding-djikstra-algorithm-for-beg-okxd | Approach\n- Find shortest path (minimum time) to reach all the nodes from node \'k\'\n- Find the max of all the minimum time\n- keep track of number of visited | anurag0608 | NORMAL | 2021-06-14T10:57:19.323000+00:00 | 2023-11-22T11:34:38.922462+00:00 | 1,036 | false | # Approach\n- Find shortest path (minimum time) to reach all the nodes from node \'k\'\n- Find the max of all the minimum time\n- keep track of number of visited nodes\n- if you ae able to reach all the nodes from \'k\' then minimum time to reach all the nodes is the maxmimum of all the reaching times.\n\nIf time taken... | 8 | 0 | ['Greedy', 'Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Shortest Path', 'Java'] | 2 |
network-delay-time | Java Simple Djikstra | java-simple-djikstra-by-hobiter-1v37 | 1, based on Djikstra\n2, check shortes dist from origin for each node. Once found the shortest, put it in vs to avoid duplicate. before put in set, compare to r | hobiter | NORMAL | 2020-07-03T00:52:31.040961+00:00 | 2020-07-03T00:52:31.040989+00:00 | 717 | false | 1, based on Djikstra\n2, check shortes dist from origin for each node. Once found the shortest, put it in vs to avoid duplicate. before put in set, compare to res, and record the longest node to reach\n3, nit: check if all nodes could be reachable.\n\n```\n public int networkDelayTime(int[][] times, int N, int K) {\... | 8 | 1 | [] | 1 |
network-delay-time | BFS | 99 % beats | Java | bfs-99-beats-java-by-eshwaraprasad-fe02 | \n\n\n# Approach\n Describe your approach to solving the problem. \nApproach is very simple, Instead of using any Priorityqueue or any normal queue, we can simp | eshwaraprasad | NORMAL | 2024-08-30T06:43:46.308085+00:00 | 2024-08-30T06:43:46.308117+00:00 | 631 | false | > \n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nApproach is very simple, Instead of using any Priorityqueue or any normal queue, we can simply traverse through given edges and e... | 7 | 0 | ['Java'] | 0 |
network-delay-time | Javascript | Priority Queue | javascript-priority-queue-by-shekhar90-w4pu | \nvar networkDelayTime = function (times, n, k) {\n const edges = [];\n for (let [u, v, w] of times) {\n if (!edges[u]) edges[u] = [];\n edg | shekhar90 | NORMAL | 2022-05-22T15:27:36.061296+00:00 | 2022-05-22T15:27:36.061341+00:00 | 705 | false | ```\nvar networkDelayTime = function (times, n, k) {\n const edges = [];\n for (let [u, v, w] of times) {\n if (!edges[u]) edges[u] = [];\n edges[u].push([v, w]);\n }\n\n function bfs() {\n const pQueue = new MinPriorityQueue({ compare: (a, b) => a[1] > b[1] });\n const visit = n... | 7 | 0 | ['Queue', 'Heap (Priority Queue)', 'JavaScript'] | 0 |
network-delay-time | C++ | Dijkstra's Shortest Path Algorithm Explained | 99.61% Faster | c-dijkstras-shortest-path-algorithm-expl-o503 | Firstly, from the given input vector, we have to make the adjacency list for the required directed weighted graph. \n\nA corner condition: If node k has no outg | cyber-venom003 | NORMAL | 2021-09-24T06:35:03.478649+00:00 | 2021-09-24T06:35:03.478696+00:00 | 1,307 | false | Firstly, from the given input vector, we have to make the adjacency list for the required **directed weighted graph**. \n\nA corner condition: If node k has no outgoing connections, then it is impossible for signal to reach to all nodes, we return -1 in this case.\n\n### Approach : Dijkstra\'s Shortest Path Algorithm (... | 7 | 0 | ['C', 'C++'] | 1 |
network-delay-time | Bellman Ford and Dijkstra / short and Easy to understand | bellman-ford-and-dijkstra-short-and-easy-kuvg | ** Bellmann ford\n\n \nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n int n = times.size();\n\t\t\tif ( | rmn_8743 | NORMAL | 2021-09-16T05:00:29.827079+00:00 | 2021-09-16T05:07:26.388411+00:00 | 460 | false | ** Bellmann ford**\n```\n \nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n int n = times.size();\n\t\t\tif (!n) return 0;\n\t\t\t\n\t\t\tvector<int>dist(N+1, INT_MAX);\n\t\t\tint res = 0;\n\t\t\t\n\t\t\tdist[K] = 0;\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tf... | 7 | 0 | ['C'] | 1 |
network-delay-time | Dijkstra | Bellman Ford | Floyd Warshall | dijkstra-bellman-ford-floyd-warshall-by-i7kku | Time Complexity\nDijkstra - V + ElogE\nBellman Ford - VE\nFloyd Warshall - V^3\n\nDijkstra\n\n\nclass Solution {\n public int networkDelayTime(int[][] times, | i18n | NORMAL | 2021-01-23T06:35:45.970619+00:00 | 2021-01-23T06:35:45.970659+00:00 | 253 | false | **Time Complexity**\nDijkstra - V + ElogE\nBellman Ford - VE\nFloyd Warshall - V^3\n\n**Dijkstra**\n\n```\nclass Solution {\n public int networkDelayTime(int[][] times, int N, int K) {\n List<int[]>[] adj = new ArrayList[N];\n for (int i = 0; i < N; i++) {\n adj[i] = new ArrayList<>();\n ... | 7 | 0 | [] | 0 |
network-delay-time | Go Dijkstra with Heap | go-dijkstra-with-heap-by-waydi1-15tt | \nimport "container/heap"\n\ntype Distance struct {\n W int\n V int\n}\n\ntype DistanceHeap []Distance\n\nfunc (h DistanceHeap) Len() int { return len(h) | waydi1 | NORMAL | 2021-01-04T09:01:43.837529+00:00 | 2021-01-04T09:01:43.837558+00:00 | 535 | false | ```\nimport "container/heap"\n\ntype Distance struct {\n W int\n V int\n}\n\ntype DistanceHeap []Distance\n\nfunc (h DistanceHeap) Len() int { return len(h) }\nfunc (h DistanceHeap) Less(i, j int) bool { return h[i].W < h[j].W }\nfunc (h DistanceHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }\n\nfunc (h *Distanc... | 7 | 0 | ['Go'] | 0 |
network-delay-time | Java | Dijkstra's algorithm & Fibonacci Heap explained | java-dijkstras-algorithm-fibonacci-heap-gwkeb | This question is a classic example for using Dijkstra\'s single-source shortest path finiding algorithm. But why is that?\n\nIntuition\nThe problem statement ma | levimor | NORMAL | 2020-10-29T12:20:47.007345+00:00 | 2020-10-29T12:20:47.007378+00:00 | 1,548 | false | This question is a classic example for using Dijkstra\'s single-source shortest path finiding algorithm. But why is that?\n\n**Intuition**\nThe problem statement makes it clear that this is a graph problem, all we need to do is to decied which algorithm to use in order to solve it.\nSince we are dealling with weighted ... | 7 | 1 | ['Heap (Priority Queue)', 'Java'] | 0 |
network-delay-time | Java BFS Solution | java-bfs-solution-by-jianhuilin1124-ll1z | \nclass Solution {\n public int networkDelayTime(int[][] times, int N, int K) {\n Map<Integer, Map<Integer, Integer>> map = new HashMap<>();\n | jianhuilin1124 | NORMAL | 2020-09-07T22:14:29.692762+00:00 | 2020-09-07T22:14:29.692871+00:00 | 803 | false | ```\nclass Solution {\n public int networkDelayTime(int[][] times, int N, int K) {\n Map<Integer, Map<Integer, Integer>> map = new HashMap<>();\n for (int[] t : times) {\n int from = t[0];\n int to = t[1];\n int weight = t[2];\n map.putIfAbsent(from, new Hash... | 7 | 0 | ['Java'] | 1 |
network-delay-time | Swift solution with comments, very concise | swift-solution-with-comments-very-concis-mr3o | It uses a standard BFS and doesn\'t appear to need a priority queue. Please enlighten me if in any case a priority queue will help reduce the time. \nI love Swi | wds8807 | NORMAL | 2019-04-23T01:18:53.687571+00:00 | 2019-04-23T01:18:53.687601+00:00 | 380 | false | It uses a standard BFS and doesn\'t appear to need a priority queue. Please enlighten me if in any case a priority queue will help reduce the time. \nI love Swift language dealing with hashmaps in such a concise manner.\n```\nclass Solution {\n\tfunc networkDelayTime(_ times: [[Int]], _ N: Int, _ K: Int) -> Int {\n\t\t... | 7 | 0 | [] | 2 |
network-delay-time | Solution using Bellman-Ford shortest path algorithm | solution-using-bellman-ford-shortest-pat-iip1 | My solution using Bellman-Ford algorithm to find the shortest paths. The max of the shortest path is the time it takes to reach all the nodes.\n\n\nclass Soluti | arvindrs | NORMAL | 2019-01-17T02:12:40.869865+00:00 | 2019-01-17T02:12:40.869905+00:00 | 15,444 | false | My solution using Bellman-Ford algorithm to find the shortest paths. The max of the shortest path is the time it takes to reach all the nodes.\n\n```\nclass Solution {\n // TC = O(T * N), SC = O(N), T-> length of times\n // Using Bellman-Ford to find shortest paths from node K\n public int networkDelayTime(int... | 7 | 1 | [] | 5 |
network-delay-time | ✅C++ || Bellman Ford || Easy Explanation || 🗓️ Daily LeetCoding Challenge May, Day 14 | c-bellman-ford-easy-explanation-daily-le-tkff | Please Upvote If It Helps\n\n\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) \n {\n // just created a | mayanksamadhiya12345 | NORMAL | 2022-05-14T17:20:06.765467+00:00 | 2022-05-14T17:23:02.748595+00:00 | 405 | false | **Please Upvote If It Helps**\n\n```\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) \n {\n // just created a dis vector that will contain the distance for reaching nodes\n // and make dik[k] initially 0 because we will start dearching from k \n vec... | 6 | 0 | [] | 0 |
network-delay-time | ✅ [python] | Simple BFS approach | python-simple-bfs-approach-by-addejans-0rry | The Algorithm:\n Create an adjacency list from source to target nodes along with the weight of their edges\n Create a dictionary to keep track of the current sh | addejans | NORMAL | 2022-05-14T03:34:49.553554+00:00 | 2022-05-14T03:34:49.553608+00:00 | 832 | false | **The Algorithm:**\n* Create an adjacency list from source to target nodes along with the weight of their edges\n* Create a dictionary to keep track of the current shortest time to traverse to each node in the graph (starting with infinity)\n* In a breadth first search (BFS) fashion, traverse neighbors starting at `k` ... | 6 | 0 | ['Breadth-First Search', 'Python'] | 0 |
network-delay-time | WITH EXPLAINATION POSSIBLE 2 SOLUTIONS IN c++ | with-explaination-possible-2-solutions-i-846k | 1.bellman Ford solution\n\n // Solution1: Bellman Ford or dfs\n // TC: O(nE), E = no. of edges\n // SC: O(n)\n int bellmanFord(vector<vector<int>>& ti | kkg2002 | NORMAL | 2022-05-14T00:32:14.959001+00:00 | 2022-05-14T00:35:10.293121+00:00 | 623 | false | 1.bellman Ford solution\n```\n // Solution1: Bellman Ford or dfs\n // TC: O(nE), E = no. of edges\n // SC: O(n)\n int bellmanFord(vector<vector<int>>& times, int n, int k) {\n // delay[i] = time to reach kth node\n vector<int> delay(n+1, INT_MAX);\n // we start from node kth node as sour... | 6 | 0 | ['Depth-First Search', 'C'] | 0 |
network-delay-time | JavaScript Solution - Dijkstra's algorithm | javascript-solution-dijkstras-algorithm-7bshl | Runtime: 100 ms, faster than 92.92% of JavaScript online submissions for Network Delay Time.\nMemory Usage: 47.1 MB, less than 53.54% of JavaScript online submi | godscode | NORMAL | 2021-12-21T13:07:50.043815+00:00 | 2021-12-21T13:07:50.043856+00:00 | 1,133 | false | Runtime: 100 ms, faster than 92.92% of JavaScript online submissions for Network Delay Time.\nMemory Usage: 47.1 MB, less than 53.54% of JavaScript online submissions for Network Delay Time.\n\n```\nvar networkDelayTime = function(times, n, k) {\n let graph = {};\n let costs = {};\n let parents = {};\n let ... | 6 | 0 | ['JavaScript'] | 1 |
network-delay-time | Need help with a test case, what am I missing? [[1,2,1],[2,1,3]] 2 2 | need-help-with-a-test-case-what-am-i-mis-5r5u | Greetings,\n\nI want to understand this specific test case. The expected return value is 3, but from where I sit, I think it should be 4.\n\n\n[[1,2,1],[2,1,3]] | TGPSKI | NORMAL | 2021-04-06T22:38:36.311099+00:00 | 2021-04-06T22:40:11.150732+00:00 | 131 | false | Greetings,\n\nI want to understand this specific test case. The expected return value is 3, but from where I sit, I think it should be 4.\n\n```\n[[1,2,1],[2,1,3]]\n2\n2\n```\n\nThis adj list describes a network of two nodes, 1 and 2. \n\n1 -> 2 at a delay of 1, and 2 -> 1 at a delay of 3. The signal input node is 2, a... | 6 | 0 | [] | 2 |
network-delay-time | JavaScript Clean, Easy Bellman-Ford 97% | 91% | javascript-clean-easy-bellman-ford-97-91-36io | \n\n\n\nfunction networkDelayTime(times, N, K) {\n //Initialize array to track times to each node from start node.\n const time = Array(N).fill(Infinity);\n | casmith1987 | NORMAL | 2021-03-11T16:24:24.696440+00:00 | 2021-09-24T22:32:06.231757+00:00 | 427 | false | \n\n\n```\nfunction networkDelayTime(times, N, K) {\n //Initialize array to track times to each node from start node.\n const time = Array(N).fill(Infinity);\n //Initialize Start node to be 0 since signal be... | 6 | 0 | ['JavaScript'] | 0 |
network-delay-time | C++ // DIJKSTRA // PRIORITY_QUEUE nothing more than that | c-dijkstra-priority_queue-nothing-more-t-f9rb | \nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n // nodes from 1 to N\n\t vector<vector<pair<int,int>>> | seonwoo960000 | NORMAL | 2021-01-04T04:28:53.223956+00:00 | 2021-01-04T04:28:53.223980+00:00 | 494 | false | ```\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n // nodes from 1 to N\n\t vector<vector<pair<int,int>>> graph(N+1);\n\t // table is to store time it takes from node K \n vector<int> table(N+1, INT_MAX);\n // starts from K\n\t table[K] = 0;\n \... | 6 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 1 |
network-delay-time | Djikstra : CLRS Implementation : O((E+V) Log V) | djikstra-clrs-implementation-oev-log-v-b-u6zz | I came across several implementaiton of the Djikstra\'s while browsing through LeetCode disccuss. Most of the people have implemented Djikstra which is very sim | codiberal | NORMAL | 2020-06-14T11:45:58.277264+00:00 | 2020-06-14T11:45:58.277305+00:00 | 579 | false | I came across several implementaiton of the Djikstra\'s while browsing through LeetCode disccuss. Most of the people have implemented Djikstra which is very similar to BFS but is different from the version mentioned in CLRS. Also, that implementation involves enqueuing element more than once in priority queue, though t... | 6 | 0 | [] | 2 |
network-delay-time | C++ | Dijkstra's Algorithm | c-dijkstras-algorithm-by-rohitmahajan281-02su | \nclass Solution {\n\tpublic:\n\t\t int networkDelayTime(vector<vector<int>>& times, int N, int K) {\t\n\t\t // smallest element will be on top (as we require | rohitmahajan2810 | NORMAL | 2020-06-11T20:23:15.142411+00:00 | 2020-06-13T15:58:25.307635+00:00 | 422 | false | ```\nclass Solution {\n\tpublic:\n\t\t int networkDelayTime(vector<vector<int>>& times, int N, int K) {\t\n\t\t // smallest element will be on top (as we require to choose next smallest distace node to select)\n\t\t // Node (u,v,w) : u=>v with weight as w\n\t\t // pq(min_distace of vertex v, v)\n\t\t priority_queu... | 6 | 0 | [] | 0 |
network-delay-time | Readable Dijkstra's - Java - Pure template based | readable-dijkstras-java-pure-template-ba-877o | What is Dijkstra\'s Algorithm (we call it D.A here) and why do we care here ?\n\n1. D.A is an algorithm to find hte shortest distance from 1 ROOT NODE to ALL OT | bordoisila | NORMAL | 2020-04-24T15:17:46.919062+00:00 | 2020-04-24T18:54:08.111205+00:00 | 694 | false | **What is Dijkstra\'s Algorithm (we call it D.A here) and why do we care here ?**\n\n1. D.A is an algorithm to find hte shortest distance from 1 ROOT NODE to ALL OTHER ROOT NODES in a GRAPH. \n2. Think about finding the shortest distance from San Jose to San Francisco, Los Angeles and Fremont in a Graph of 4 Cities [Sa... | 6 | 0 | [] | 1 |
network-delay-time | [Java] DijkstraSP using IndexMinPQ with time complexity O(ElogV) | java-dijkstrasp-using-indexminpq-with-ti-fjws | If you use a built-in PriorityQueue to implements dijkstra shortest path algorithm, the time complexity will be O(ElogE), since you may add several edges with d | zmy3324 | NORMAL | 2020-04-08T12:28:58.216281+00:00 | 2020-04-08T12:28:58.216330+00:00 | 497 | false | If you use a built-in PriorityQueue to implements dijkstra shortest path algorithm, the time complexity will be O(ElogE), since you may add several edges with different distances. By using the indexMinPQ, you could avoid the duplicates and get a O(ElogV). The runtime also improves from [31ms](https://leetcode.com/prob... | 6 | 0 | [] | 1 |
network-delay-time | Python - Dijkstra | python-dijkstra-by-cool_shark-6g3h | py\n\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], N: int, K: int) -> int:\n \n\t\t# build graph\n g = collections.defa | cool_shark | NORMAL | 2020-02-13T15:18:14.416485+00:00 | 2020-02-13T15:31:12.275228+00:00 | 698 | false | ```py\n\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], N: int, K: int) -> int:\n \n\t\t# build graph\n g = collections.defaultdict(list)\n for u, v, cost in times:\n g[u].append((cost,v))\n \n min_heap = [(0, K)] # cost, u\n visited = set()\... | 6 | 0 | [] | 2 |
network-delay-time | [Python] Dijkstra || Bellman-Ford || Floyd-Warshall | python-dijkstra-bellman-ford-floyd-warsh-73ei | Dijkstra\nTime: O(ElogV)\nSpace: O(V+E)\n\n- Single Source Shortest Path\n- Finds the shortest path from one node to all other nodes. \n- A greedy algorithm th | teampark | NORMAL | 2020-02-10T23:25:38.227426+00:00 | 2020-02-10T23:29:17.810948+00:00 | 540 | false | **Dijkstra**\nTime: ```O(ElogV)```\nSpace: ```O(V+E)```\n\n- Single Source Shortest Path\n- Finds the shortest path from one node to all other nodes. \n- A greedy algorithm that works by always exploring the shortest available path first. \n```\nclass Solution(object):\n\n def networkDelayTime(self, times, N, K):\n... | 6 | 0 | [] | 0 |
network-delay-time | Simple Python BFS solution | simple-python-bfs-solution-by-otoc-2yvc | \n def networkDelayTime(self, times: List[List[int]], N: int, K: int) -> int:\n graph = [dict() for _ in range(N + 1)]\n for u, v, w in times:\ | otoc | NORMAL | 2019-09-25T17:52:09.284494+00:00 | 2019-09-25T17:52:09.284542+00:00 | 572 | false | ```\n def networkDelayTime(self, times: List[List[int]], N: int, K: int) -> int:\n graph = [dict() for _ in range(N + 1)]\n for u, v, w in times:\n graph[u][v] = w\n finished = [float(\'inf\') for _ in range(N + 1)]\n # BFS visit\n curr_level = {K}\n finished[0], ... | 6 | 0 | [] | 0 |
network-delay-time | Dijkstra’s Algorithm || Priority Queue || BFS || Explanation || Complexities | dijkstras-algorithm-priority-queue-bfs-e-wmen | IntuitionWe need to determine the shortest time required for a signal to reach all nodes in a network. This problem is similar to finding the shortest path in a | Anurag_Basuri | NORMAL | 2025-02-01T08:14:14.603242+00:00 | 2025-02-01T08:14:14.603242+00:00 | 1,363 | false | ## **Intuition**
We need to determine the shortest time required for a signal to reach all nodes in a network. This problem is similar to finding the **shortest path** in a weighted graph, where each edge represents the travel time.
The best approach to solve this problem is **Dijkstra’s Algorithm**, which efficiently... | 5 | 0 | ['Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Shortest Path', 'C++', 'Java', 'Python3'] | 0 |
network-delay-time | 90.1 (Approach 1: Dijkstra's algorithm) | O(E * log V)✅ | Python & C++(Step by step explanation)✅ | 901-approach-1-dijkstras-algorithm-oe-lo-1qg6 | Intuition\nThe problem can be approached using Dijkstra\'s algorithm, which is a popular algorithm for finding the shortest paths between nodes in a graph. Here | monster0Freason | NORMAL | 2024-02-18T11:01:31.309441+00:00 | 2024-02-18T11:01:31.309476+00:00 | 671 | false | # Intuition\nThe problem can be approached using Dijkstra\'s algorithm, which is a popular algorithm for finding the shortest paths between nodes in a graph. Here, each node represents a point in the network, and the edges represent the time it takes for a signal to travel between two points.\n\n# Approach\n1. **Build ... | 5 | 0 | ['Graph', 'Heap (Priority Queue)', 'C++', 'Python3'] | 2 |
network-delay-time | C++ || Dijkstra✅ + Bellman Ford✅ + (Some idea on Floyd-Warshall)✅ || Easy💡 and Fast🔥 | c-dijkstra-bellman-ford-some-idea-on-flo-joyg | Here question asks to return minimum time it takes for all the n nodes to receive the signal. Which means it wants to say that find the shortest time to reach a | UjjwalAgrawal | NORMAL | 2023-06-02T11:05:46.683087+00:00 | 2023-06-02T11:05:46.683123+00:00 | 1,220 | false | Here question asks to return minimum time it takes for all the n nodes to receive the signal. Which means it wants to say that find the shortest time to reach all the nodes and then return maximum time out of it.\n\nBasically there is some node which will take more time then other nodes. So have to minimize that time.\... | 5 | 0 | ['Breadth-First Search', 'Heap (Priority Queue)', 'Shortest Path', 'C++'] | 0 |
network-delay-time | Dijkstra's Algorithms | dijkstras-algorithms-by-ganjinaveen-wmnk | Dijkstra\'s Algorithm\n\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:\n edges=defaultdict(list)\n | GANJINAVEEN | NORMAL | 2023-04-30T13:05:17.958975+00:00 | 2023-04-30T13:05:17.959010+00:00 | 1,536 | false | # Dijkstra\'s Algorithm\n```\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:\n edges=defaultdict(list)\n for u, v, w in times:\n #graph[u-1].append((v-1, w))\n edges[u].append((v,w))\n minheap=[(0,k)]\n visit=set()\n ... | 5 | 0 | ['Python3'] | 1 |
network-delay-time | Java | using MinHeap | java-using-minheap-by-venkat089-qrtk | 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 | Venkat089 | NORMAL | 2023-02-16T05:37:16.860536+00:00 | 2023-02-16T05:37:16.860582+00:00 | 817 | 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)$$ --... | 5 | 0 | ['Java'] | 0 |
network-delay-time | ✅C++ || CLEAN && Easy to Understand CODE || Dijkstra's Algo | c-clean-easy-to-understand-code-dijkstra-hrg4 | \n\nLogic - > No Logic! Strightforward question, just Apply Dijkstra\'s or Bellman Ford and you are good to go!\n\nT-> O(E log V) && S->O(V)\n\n\n\tclass Soluti | abhinav_0107 | NORMAL | 2022-12-30T15:00:24.976446+00:00 | 2022-12-30T15:01:46.401321+00:00 | 601 | false | \n\n***Logic - > No Logic! Strightforward question, just Apply Dijkstra\'s or Bellman Ford and you are good to go!***\n\n**T-> O(E log V) && S->O(V)**\n\n\n\tclass Solution {\n\t\tpublic:\n\t\t\tint networkDela... | 5 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 1 |
network-delay-time | ✅ [Python] propagation through all paths using Dijkstra's Algorithm (with detailed comments) | python-propagation-through-all-paths-usi-70v4 | \u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.\n*\nThis solution employs Dijkstra\'s algorithm to propagate signal through the network. \n\n*Comment. To get m | stanislav-iablokov | NORMAL | 2022-11-03T18:14:00.422947+00:00 | 2022-11-03T18:17:11.982517+00:00 | 455 | false | **\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n****\nThis solution employs Dijkstra\'s algorithm to propagate signal through the network. \n\n**Comment**. To get minimal signal arrival time for each node, we propagate through all paths using double-ended queue. On each iteration, we send signal from a source nod... | 5 | 0 | [] | 3 |
network-delay-time | 📍 C++ Solution with Pattern for future Questions | c-solution-with-pattern-for-future-quest-doyq | \uD83D\uDD25 Please Upvote It is FREE from your side\n\nWhere this Approach can be used [Pattern]\n- Whenever we want to find max or min cost path from a source | AlphaDecodeX | NORMAL | 2022-09-06T06:09:08.553575+00:00 | 2022-09-06T06:09:29.659420+00:00 | 446 | false | \uD83D\uDD25 Please **Upvote** It is **FREE** from your side\n\n**Where this Approach can be used** [Pattern]\n- Whenever we want to find max or min cost path from a source to destination. \n- It will also work if the nodes are disconnected means more than one graph present which are not connected with each other\n- We... | 5 | 0 | ['C', 'C++'] | 0 |
network-delay-time | ✅C++ | ✅Use Bellman Ford Algorithm | c-use-bellman-ford-algorithm-by-yash2arm-amzq | \nclass Solution {\npublic:\n \n // I\'m going to use Bellman Ford Algorithm\n int networkDelayTime(vector<vector<int>>& times, int n, int k) \n {\n | Yash2arma | NORMAL | 2022-05-14T19:12:23.117230+00:00 | 2022-05-14T19:12:23.117272+00:00 | 395 | false | ```\nclass Solution {\npublic:\n \n // I\'m going to use Bellman Ford Algorithm\n int networkDelayTime(vector<vector<int>>& times, int n, int k) \n {\n // just created a dis vector that will store the distance for reaching the node\n // and assign dis[k]=0 because we will start searching from ... | 5 | 0 | ['Graph', 'C', 'C++'] | 0 |
network-delay-time | Simple Java, Dijkstra, heap, COMMENTS, | simple-java-dijkstra-heap-comments-by-fo-o4ff | I could not find many solutions with comments so I decieded to write one up. I hope this helps someone. I am using Dijkstra\'s Algorithm.\n\n\nclass Solution {\ | fourgates | NORMAL | 2022-01-16T04:54:26.151827+00:00 | 2022-01-16T04:54:26.151856+00:00 | 437 | false | I could not find many solutions with comments so I decieded to write one up. I hope this helps someone. I am using Dijkstra\'s Algorithm.\n\n```\nclass Solution {\n public int networkDelayTime(int[][] times, int n, int k) {\n // init\n Map<Integer, List<int[]>> graph = new HashMap<>();\n \n ... | 5 | 0 | ['Heap (Priority Queue)', 'Java'] | 0 |
network-delay-time | [Java] Dijkstra's Algo with Heap | java-dijkstras-algo-with-heap-by-jocelyn-7mub | Runtime: 17ms (beat 62%)\nMemory Usage: 42MB(beat 83.23%)\n\n\nclass Solution {\n public int networkDelayTime(int[][] times, int n, int k) {\n Map<Int | jocelyn23 | NORMAL | 2021-07-29T03:49:35.262719+00:00 | 2021-07-29T03:49:55.016555+00:00 | 480 | false | Runtime: 17ms (beat 62%)\nMemory Usage: 42MB(beat 83.23%)\n\n```\nclass Solution {\n public int networkDelayTime(int[][] times, int n, int k) {\n Map<Integer, List<Cell>> graph = new HashMap<>();\n for (int[] edge: times) {\n graph.computeIfAbsent(edge[0], v->new ArrayList<>()).add(new Cell(... | 5 | 0 | ['Java'] | 2 |
network-delay-time | C# Belman-Ford implementation | c-belman-ford-implementation-by-and85-5mgn | \npublic class Solution\n{\n\tpublic int NetworkDelayTime(int[][] times, int n, int k)\n\t{\n\t\t// implementation of Belman-Ford Algorithm\n\t\t// https://www. | and85 | NORMAL | 2021-01-30T17:22:53.334634+00:00 | 2021-01-30T17:25:19.831676+00:00 | 427 | false | ```\npublic class Solution\n{\n\tpublic int NetworkDelayTime(int[][] times, int n, int k)\n\t{\n\t\t// implementation of Belman-Ford Algorithm\n\t\t// https://www.youtube.com/watch?v=FtN3BYH2Zes \n\t\t// run relaxation of each vertex exactly n - 1 times\n\t\t// source vertex should have 0 cost to visit, all other vert... | 5 | 0 | [] | 1 |
network-delay-time | Comparison between standard Dijlstra and BFS solution, kind for beginners. | comparison-between-standard-dijlstra-and-9pz4 | The goal is to compute the shorhest path from one single node to all nodes in directed weighted graph.\nWe can do this in both Dijlstra\'s Algorithm and BFS. \n | green077 | NORMAL | 2019-10-17T05:46:44.742620+00:00 | 2019-10-17T05:46:44.742670+00:00 | 1,108 | false | The goal is to compute the shorhest path from one single node to all nodes in directed weighted graph.\nWe can do this in both Dijlstra\'s Algorithm and BFS. \nMy solution is not the quickest, but it\'s easy to understand and standard. \nFor Dijlstra: \n1. put node number and temporary distance into priority queue. \n2... | 5 | 0 | ['Breadth-First Search', 'Java'] | 3 |
network-delay-time | 经典Dijkstra + 优先队列优化Dijkstra + 经典Bellman-Ford | jing-dian-dijkstra-you-xian-dui-lie-you-e6dyp | solution 1 \u7ECF\u5178Dijkstra\njava\n public int networkDelayTime(int[][] times, int N, int K) {\n int maxValue=6005;\n int[][] graph = new i | greatgeek | NORMAL | 2019-08-24T09:22:49.621691+00:00 | 2019-08-24T09:22:49.621739+00:00 | 597 | false | **solution 1 \u7ECF\u5178Dijkstra**\n```java\n public int networkDelayTime(int[][] times, int N, int K) {\n int maxValue=6005;\n int[][] graph = new int[N+1][N+1];\n for(int i=0;i<graph.length;i++){\n for(int j=0;j<graph[i].length;j++){\n graph[i][j]=maxValue;\n ... | 5 | 0 | ['Java'] | 0 |
network-delay-time | [3 Ways to Solve Java]Floyd Warshall && Dijkstra && Bellman Ford | 3-ways-to-solve-javafloyd-warshall-dijks-o3dy | It\'s kind of brute force. Floyd Warshall:\n\nclass Solution {\n public int networkDelayTime(int[][] times, int N, int K) {\n int[][] M = new int[N + | flusteredying | NORMAL | 2018-03-30T00:09:24.110658+00:00 | 2018-03-30T00:09:24.110658+00:00 | 643 | false | It\'s kind of brute force. Floyd Warshall:\n```\nclass Solution {\n public int networkDelayTime(int[][] times, int N, int K) {\n int[][] M = new int[N + 1][N + 1];\n for(int[] row : M){\n Arrays.fill(row, 10000);\n }\n for(int[] t : times){\n int v1 = t[0];\n ... | 5 | 0 | [] | 3 |
network-delay-time | Simple Python solution using Djikstra's | simple-python-solution-using-djikstras-b-lkqx | BFS is used to iterate through the nodes, where next node is determined using priority queue ordered by its distance from starting node K.\n\n def networkDel | incog | NORMAL | 2017-12-10T04:04:12.617000+00:00 | 2017-12-10T04:04:12.617000+00:00 | 1,295 | false | BFS is used to iterate through the nodes, where next node is determined using priority queue ordered by its distance from starting node K.\n```\n def networkDelayTime(self, times, N, K):\n pq = []\n adj = [[] for _ in range(N+1)]\n for time in times:\n adj[time[0]].append((time[1], ti... | 5 | 2 | [] | 2 |
network-delay-time | ✅BEST | GRAPH | JAVA | Explained🔥🔥🔥 | best-graph-java-explained-by-adnannshaik-1quu | Intuition
The problem requires us to determine the time it takes for a signal to reach all nodes in a directed weighted graph. Since this is a shortest path pro | AdnanNShaikh | NORMAL | 2025-02-17T02:04:57.891759+00:00 | 2025-02-17T02:04:57.891759+00:00 | 331 | false | **Intuition**
The problem requires us to determine the time it takes for a signal to reach all nodes in a directed weighted graph. Since this is a shortest path problem where we need to find the minimum time from a source node to all other nodes, Dijkstra's algorithm is a natural fit because it efficiently finds the sh... | 4 | 0 | ['Java'] | 0 |
network-delay-time | DFS C++ SOLUTION | dfs-c-solution-by-jeffrin2005-c876 | 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 | Jeffrin2005 | NORMAL | 2024-07-04T03:49:50.172902+00:00 | 2024-07-04T03:49:50.172922+00:00 | 288 | 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)$$ --... | 4 | 0 | ['C++'] | 0 |
network-delay-time | Dijkstra's BFS C++ SOLUTION | dijkstras-bfs-c-solution-by-jeffrin2005-mmen | 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 | Jeffrin2005 | NORMAL | 2024-07-04T03:46:54.561749+00:00 | 2024-07-04T03:46:54.561781+00:00 | 758 | 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)$$ --... | 4 | 0 | ['C++'] | 0 |
network-delay-time | Dijkstra's Algorithm || Simple C++ Solution || | dijkstras-algorithm-simple-c-solution-by-fkrz | Code\n\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n vector<vector<pair<int,int>>> adj(n+1,vector<pa | abhijeet5000kumar | NORMAL | 2023-12-19T22:53:55.243370+00:00 | 2023-12-19T22:53:55.243386+00:00 | 1,228 | false | # Code\n```\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n vector<vector<pair<int,int>>> adj(n+1,vector<pair<int,int>>{} );\n for(auto x:times){\n adj[x[0]].push_back({x[1],x[2]});\n }\n\n vector<int> dist(n+1,1e9);\n dist... | 4 | 0 | ['Depth-First Search', 'Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Shortest Path', 'C++'] | 0 |
network-delay-time | Best O(ElogV) Solution | best-oelogv-solution-by-kumar21ayush03-riod | 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 n | kumar21ayush03 | NORMAL | 2023-03-18T13:54:58.048732+00:00 | 2023-03-18T13:54:58.048778+00:00 | 246 | 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 networkDelayTime(vector<vector<int>>& times, int n, int k) {\n vector <pair<int, int>> adj[n+1];\n for (auto it: times) \n ... | 4 | 0 | ['C++'] | 0 |
network-delay-time | Java || Dijkstra || PriorityQueue (Heap) || Fast | java-dijkstra-priorityqueue-heap-fast-by-kjwv | An leetcode a day, doctors are always on the way.\n\n\n\nclass Solution {\n public int networkDelayTime(int[][] times, int n, int k) {\n \n //R | yining_xu | NORMAL | 2022-08-30T23:56:06.418600+00:00 | 2022-08-30T23:56:06.418637+00:00 | 357 | false | An leetcode a day, doctors are always on the way.\n\n```\n\nclass Solution {\n public int networkDelayTime(int[][] times, int n, int k) {\n \n //Represente the graph using adjacency list\n List<int[]>[] graph = new List[n + 1];\n for(int i = 0; i <= n; i++){\n graph[i] = new Ar... | 4 | 0 | ['Java'] | 0 |
network-delay-time | Using Dijkstra Algorithm, [C++] | using-dijkstra-algorithm-c-by-akashsahuj-41is | Implementation\n\nUsing Dijkstra Algorithm\nTime Complexity = O(N + ElogN)\nSpace Complexity = (O(N+E) + O(N) + O(N)) => O(N+E)\nWhere N is the nunber of vertic | akashsahuji | NORMAL | 2022-06-02T18:17:38.817723+00:00 | 2022-06-02T18:17:38.817768+00:00 | 273 | false | Implementation\n\n**Using Dijkstra Algorithm\nTime Complexity = O(N + ElogN)\nSpace Complexity = (O(N+E) + O(N) + O(N)) => O(N+E)\nWhere N is the nunber of vertices in the graph and E is the number of edges**\n\n```\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n ... | 4 | 0 | ['Graph', 'C', 'Heap (Priority Queue)', 'Shortest Path'] | 0 |
network-delay-time | Python Solution - Dijkstra's Shortest Path Algorithm using minHeap | python-solution-dijkstras-shortest-path-9qb1z | \n# Implement Dijkstra\'s Shortest Path Algorithm\n\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:\n # | SamirPaulb | NORMAL | 2022-05-23T05:35:20.166134+00:00 | 2022-05-23T05:44:37.106873+00:00 | 789 | false | ```\n# Implement Dijkstra\'s Shortest Path Algorithm\n\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:\n # create Adjacency List \n adjList = {i:[] for i in range(1, n+1)}\n for u, v, w in times:\n adjList[u].append((v, w))\n \n ... | 4 | 0 | ['Heap (Priority Queue)', 'Python', 'Python3'] | 2 |
network-delay-time | All Three Approaches | Easy Solution | Commented Explanation | | all-three-approaches-easy-solution-comme-g1h1 | Upvote if you like it and finds helpful !\n\nApproach 1 : DFS\n\n Time complexity: O((N - 1)! + ElogE\n Space complexity: O(N + E)O(N+E)\n\n\n\nclass Solution | nitin_05 | NORMAL | 2022-05-14T09:21:08.130690+00:00 | 2022-05-14T09:35:54.818406+00:00 | 431 | false | ***Upvote if you like it and finds helpful !***\n\n**Approach 1 : DFS**\n\n ***Time complexity: O((N - 1)! + ElogE***\n ***Space complexity: O(N + E)O(N+E)***\n\n\n```\nclass Solution {\npublic:\n static bool sortbysec ( const pair<int,int>&a , const pair<int,int>&b )\n {\n return a.second < b.second ;\n... | 4 | 0 | ['Depth-First Search', 'C'] | 1 |
network-delay-time | C++ Dijkstra | c-dijkstra-by-midnightsimon-1zu9 | Solved live on stream. Link in profile\n\n\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n using pii | midnightsimon | NORMAL | 2022-05-14T01:28:48.804232+00:00 | 2022-05-14T01:28:48.804256+00:00 | 556 | false | Solved live on stream. Link in profile\n\n```\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n using pii = pair<int,int>;\n vector<vector<pii>> adjList(n);\n priority_queue<pii, vector<pii>, greater<pii>> pq;\n for(auto& time : times) {\n ... | 4 | 0 | [] | 0 |
network-delay-time | C++ | Code Explained With Proper Comment | Dijkstra Algorithm | c-code-explained-with-proper-comment-dij-z8uv | \n// 1. DijkstraAlgorithm => TC O(nlogn) | SC O(n)\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n pri | itsmdasifraza | NORMAL | 2022-02-10T17:10:57.591698+00:00 | 2022-02-10T17:10:57.591747+00:00 | 254 | false | ```\n// 1. DijkstraAlgorithm => TC O(nlogn) | SC O(n)\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq; // min heap\n pq.push({0, k});\n vector<vector<pair<int, int>>> adj... | 4 | 0 | ['C++'] | 0 |
network-delay-time | Python DFS vs BFS vs Djikstra's(Flavor or BFS) | python-dfs-vs-bfs-vs-djikstrasflavor-or-8y3kz | \nfrom collections import defaultdict\nimport heapq\nfrom collections import deque\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], n: i | ashm4478 | NORMAL | 2021-11-08T03:32:45.378929+00:00 | 2021-11-08T03:32:45.378962+00:00 | 558 | false | ```\nfrom collections import defaultdict\nimport heapq\nfrom collections import deque\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:\n\t\n # Common code for all\n\t\t\n graph = defaultdict(list)\n for u, v , w in times:\n graph[u].append(... | 4 | 0 | ['Depth-First Search', 'Breadth-First Search', 'Recursion', 'Python'] | 0 |
network-delay-time | C++ || Dijkstra's Algorithm || priority_queue || Time:-O(NlogN) || space:-O(N) + O(N) | c-dijkstras-algorithm-priority_queue-tim-sqv3 | Time :- O((N+E)*logN) =O(NlogN)\nSpace:-O(N) {for dist arrays } + O(N) {for priority_queue}\n\nclass Solution {\npublic:\n int networkDelayTime(vector<vector | Pitbull_45 | NORMAL | 2021-11-03T22:27:14.985086+00:00 | 2021-11-03T22:27:14.985126+00:00 | 155 | false | *Time* :- O((N+E)*logN) =O(NlogN)\nSpace:-O(N) {for dist arrays } + O(N) {for priority_queue}\n```\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n int m=times.size();\n vector<pair<int,int>>graph[n+1];\n for(int i=0;i<m;i++)\n {\n ... | 4 | 0 | [] | 0 |
network-delay-time | c++ solution | BFS | c-solution-bfs-by-xor09-qd5p | \nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n int size=times.size();\n int max_time=0, des, | xor09 | NORMAL | 2021-03-05T15:24:11.928231+00:00 | 2021-03-05T15:24:35.425558+00:00 | 343 | false | ```\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n int size=times.size();\n int max_time=0, des, time; \n vector<pair<int,int>>graph[n+1];\n vector<int> t(n+1,INT_MAX);\n \n for(int i=0;i<size;i++){\n graph[times[i]... | 4 | 2 | ['Breadth-First Search', 'C'] | 0 |
network-delay-time | Two algorithms JS Solution | two-algorithms-js-solution-by-hbjorbj-5v05 | \nvar networkDelayTime = function(times, N, K) {\n // Converting data into adjacency list\n let adjList = new Array(N).fill(0).map(() => []);\n for (le | hbjorbj | NORMAL | 2020-10-28T08:41:08.597780+00:00 | 2020-10-29T06:43:22.249881+00:00 | 444 | false | ```\nvar networkDelayTime = function(times, N, K) {\n // Converting data into adjacency list\n let adjList = new Array(N).fill(0).map(() => []);\n for (let edge of times) {\n adjList[edge[0]-1].push([edge[1]-1,edge[2]]);\n }\n \n let travelTime = new Array(N).fill(Infinity);\n travelTime[K-1... | 4 | 0 | ['JavaScript'] | 0 |
network-delay-time | C++ Dijkstra Algorithm and BFS | c-dijkstra-algorithm-and-bfs-by-dj55427-ifjo | Solution 1: Dijkstra Algorithm\n\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n \n vector<vect | dj55427 | NORMAL | 2020-10-05T05:18:26.418571+00:00 | 2020-10-05T07:25:48.306789+00:00 | 532 | false | Solution 1: Dijkstra Algorithm\n```\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n \n vector<vector<pair<int,int>>> G(N);\n for(auto itr: times)\n G[itr[0]-1].push_back({itr[1]-1,itr[2]});\n \n vector<int> timetaken(N,INT_... | 4 | 0 | ['C', 'Heap (Priority Queue)'] | 0 |
network-delay-time | Java Solution - Dijkstra Algorithm (Inbuilt min-heap trick) | java-solution-dijkstra-algorithm-inbuilt-laow | Since the inbuilt implementation of priorty queue in java does not support updating the keys once they are inserted, we could insert duplicate nodes in the queu | itsmastersam | NORMAL | 2020-04-25T15:54:31.951961+00:00 | 2020-04-25T15:58:20.432657+00:00 | 228 | false | Since the inbuilt implementation of priorty queue in java does not support updating the keys once they are inserted, we could insert duplicate nodes in the queue. Once we have visited a node, we can discard all of its duplicates whenever they appear.\n\n```\nclass Solution {\n int ans = 0;\n \n public int netw... | 4 | 0 | [] | 1 |
network-delay-time | C++ concise solution | c-concise-solution-by-jasperjoe-7d51 | \tclass Solution {\n\tpublic:\n\t\tint networkDelayTime(vector>& times, int N, int K) {\n\t\t\tint MAX=100101;\n\t\t\tvector dp(N+1,MAX);\n\t\t\tdp[0]=0;\n\t\t\ | jasperjoe | NORMAL | 2020-01-02T10:43:34.075032+00:00 | 2020-01-02T10:43:34.075065+00:00 | 619 | false | \tclass Solution {\n\tpublic:\n\t\tint networkDelayTime(vector<vector<int>>& times, int N, int K) {\n\t\t\tint MAX=100*101;\n\t\t\tvector<int> dp(N+1,MAX);\n\t\t\tdp[0]=0;\n\t\t\tdp[K]=0;\n\t\t\tfor(int i=0;i<N;i++){\n\t\t\t\tfor(auto v:times){\n\t\t\t\t\tint a=v[0];\n\t\t\t\t\tint b=v[1];\n\t\t\t\t\tdp[b]=min(dp[b],dp... | 4 | 1 | ['C', 'C++'] | 0 |
successful-pairs-of-spells-and-potions | ✔️✔️Easy Solutions in Java ✔️✔️, Python ✔️, and C++ ✔️🧐Look at once 💻 with Exaplanation | easy-solutions-in-java-python-and-c-look-gzvy | Intuition\n Describe your first thoughts on how to solve this problem. \nFor each spell, we need to find the number of potions that can form a successful pair w | Vikas-Pathak-123 | NORMAL | 2023-04-02T00:58:19.785541+00:00 | 2023-04-02T01:16:07.236021+00:00 | 35,211 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor each spell, we need to find the number of potions that can form a successful pair with it. A pair is successful if the product of their strengths is at least the given success value. To find the number of successful pairs for each spe... | 342 | 1 | ['Array', 'Binary Search', 'Python', 'C++', 'Java'] | 23 |
successful-pairs-of-spells-and-potions | [JavaC++/Python] Straignt Forward with Explantion | javacpython-straignt-forward-with-explan-ciws | Explanation\nFor each spell,\nit needs ceil integer of need = success * 1.0 / spell.\n\nBinary search the index of first potion >= need in the sorted potions.\n | lee215 | NORMAL | 2022-06-11T16:02:03.039386+00:00 | 2022-06-11T16:17:53.490459+00:00 | 18,207 | false | # **Explanation**\nFor each `spell`,\nit needs ceil integer of `need = success * 1.0 / spell`.\n\nBinary search the `index` of first `potion >= need` in the sorted `potions`.\nThe number of potions that are successful are `potions.length - index`\n\nAccumulate the result `res` and finally return it.\n<br>\n\n# **Comple... | 109 | 3 | ['C', 'Python', 'Java'] | 18 |
successful-pairs-of-spells-and-potions | C++ | Clean | Easy ✅ | c-clean-easy-by-ritik_pcl-p6sf | \u2764 Please Upvote if you find helpful \u2764\n\nExplanation (Step by Step)\n\nStep 1. \nThe function starts by initializing the vector v with zeros and then | ritik_pcl | NORMAL | 2022-06-11T16:06:28.477177+00:00 | 2023-04-02T07:50:18.083439+00:00 | 8,829 | false | \u2764 Please Upvote if you find helpful \u2764\n\n**Explanation (Step by Step)**\n\n**Step 1.** \nThe function starts by initializing the vector `v` with `zeros` and then `sorting` the vector `p` in `non-decreasing` order.\n\n**Step 2.** \nFor each element `s[i]` in vector `s`, a `binary search` is performed on vector... | 75 | 3 | ['Binary Search', 'C', 'C++'] | 4 |
successful-pairs-of-spells-and-potions | Image Explanation🏆- [Binary Search with & without Inbuild Libraries] - C++/Java/Python | image-explanation-binary-search-with-wit-4asr | Video Solution (Aryan Mittal) - Link in LeetCode Profile\nSuccessful Pairs of Spells and Potions by Aryan Mittal\n\n\n# Approach & Intution\n\n\n\n\n\n\n\n\n\n\ | aryan_0077 | NORMAL | 2023-04-02T01:05:37.488111+00:00 | 2023-04-02T02:27:09.694000+00:00 | 14,068 | false | # Video Solution (`Aryan Mittal`) - Link in LeetCode Profile\n`Successful Pairs of Spells and Potions` by `Aryan Mittal`\n\n\n# Approach & Intution\n\n {\n int n = potions.size(), bestIdx = n | mohakharjani | NORMAL | 2023-04-02T01:11:29.188166+00:00 | 2023-04-02T01:19:07.303627+00:00 | 6,981 | false | \n\n\n```\nclass Solution {\npublic:\n int getPairCount(vector<int>& potions, int& spell, long lon... | 50 | 4 | ['C', 'Binary Tree', 'C++'] | 6 |
successful-pairs-of-spells-and-potions | ✅ Java | Easy Solution with Detailed Explaination and Similar problems 📝 | Binary Search | java-easy-solution-with-detailed-explain-wj1w | Intuition\nQuestion reduces to finding no of potions for each spell which have \nproduct greater than success where product is (each spell * potions[i])\n\nNow | nikeMafia | NORMAL | 2023-04-02T03:37:43.811014+00:00 | 2023-04-02T07:30:19.087866+00:00 | 3,318 | false | # Intuition\nQuestion reduces to finding no of potions for each spell which have \n***product greater than success*** where product is (each spell * potions[i])\n\nNow decision is whether to keep the potions array sorted or not.\n\n- ***NON-SORTED*** Another is to traverse entire array of potions and count no of produc... | 32 | 0 | ['Binary Search', 'Java'] | 1 |
successful-pairs-of-spells-and-potions | Prefix/Postfix sum C++ | 99% Faster in time | prefixpostfix-sum-c-99-faster-in-time-by-yrpi | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem asks us to find out the number of potion values that has product with a spe | HenryNguyen101 | NORMAL | 2023-04-02T03:42:14.109940+00:00 | 2023-04-02T03:42:14.109966+00:00 | 5,239 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem asks us to find out the number of potion values that has product with a specific spell value which is greater than (or equal to) a threshold.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSince we hav... | 28 | 0 | ['C++'] | 2 |
successful-pairs-of-spells-and-potions | Binary Search | binary-search-by-kamisamaaaa-ppn5 | \nIf ith potion is successful then all the potions after will be successful.\n So find the first potion which is successful using Binary Search.\n\nclass Sol | kamisamaaaa | NORMAL | 2022-06-11T16:01:56.128551+00:00 | 2022-06-11T16:15:28.284463+00:00 | 3,311 | false | \n***If ith potion is successful then all the potions after will be successful.\n So find the first potion which is successful using Binary Search.***\n```\nclass Solution {\npublic:\n vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n \n vector<int> res;\n... | 26 | 1 | ['C', 'Binary Tree'] | 4 |
successful-pairs-of-spells-and-potions | ✅✅Python🔥Simple Solution🔥Easy to Understand🔥 | pythonsimple-solutioneasy-to-understand-1uxta | Please UPVOTE \uD83D\uDC4D\n\n!! BIG ANNOUNCEMENT !!\nI am currently Giving away my premium content well-structured assignments and study materials to clear int | cohesk | NORMAL | 2023-04-02T13:53:21.909086+00:00 | 2023-04-02T13:53:21.909128+00:00 | 3,138 | false | # Please UPVOTE \uD83D\uDC4D\n\n**!! BIG ANNOUNCEMENT !!**\nI am currently Giving away my premium content well-structured assignments and study materials to clear interviews at top companies related to computer science and data science to my current Subscribers this week. I planned to give for next 10,000 Subscribers a... | 22 | 1 | ['Array', 'Binary Search', 'Python', 'Python3'] | 1 |
successful-pairs-of-spells-and-potions | [Java/Python 3] Sort and Binary search w/ brief explanation and analysis. | javapython-3-sort-and-binary-search-w-br-qitd | Q & A\n\nQ1: Why and how do we need to compute the factor?\nA1: \n1) We need a factor from potions to multiply with current spells[i] in order to get a product | rock | NORMAL | 2022-06-11T16:02:52.895284+00:00 | 2022-06-13T16:53:15.037791+00:00 | 3,240 | false | **Q & A**\n\nQ1: Why and how do we need to compute the factor?\nA1: \n1) We need a factor from `potions` to multiply with current `spells[i]` in order to get a product at least `success`. Therefore, computing before hand will obtain a key (the factor) for binary search.\n2) `(success + s) // s = success / s + 1`, which... | 19 | 0 | ['Binary Search', 'Sorting', 'Java', 'Python3'] | 7 |
successful-pairs-of-spells-and-potions | Binary Search vs. Two Pointers | binary-search-vs-two-pointers-by-votruba-jev0 | In the first approach, we sort potions, and use binary search to find the position of the weakest potion that produces a success. All potions to the right would | votrubac | NORMAL | 2022-06-11T16:46:39.681160+00:00 | 2022-06-11T17:44:28.458594+00:00 | 2,738 | false | In the first approach, we sort `potions`, and use binary search to find the position of the weakest potion that produces a success. All potions to the right would work also.\n\nIn the second approach, we sort both `potions` and `spells` (we actually sort indexes `idx` to preserve the order of spells). Then, we use two ... | 17 | 0 | ['C'] | 4 |
successful-pairs-of-spells-and-potions | ✅ Java | Sorting + Binary Search Approach | java-sorting-binary-search-approach-by-p-t2fl | \n// Approach 2: Sorting + Binary Search (Lower Bound)\n\n// Time complexity: O((m + n) log m)\n// Space complexity: O(log m)\n\npublic int[] successfulPairs(i | prashantkachare | NORMAL | 2023-04-02T05:48:08.556994+00:00 | 2023-04-02T06:14:53.023709+00:00 | 1,533 | false | ```\n// Approach 2: Sorting + Binary Search (Lower Bound)\n\n// Time complexity: O((m + n) log m)\n// Space complexity: O(log m)\n\npublic int[] successfulPairs(int[] spells, int[] potions, long success) {\n\tint n = spells.length;\n\tint m = potions.length;\n\tint[] pairs = new int[n];\n\n\tArrays.sort(potions); // m... | 15 | 0 | ['Sorting', 'Binary Tree', 'Java'] | 1 |
successful-pairs-of-spells-and-potions | Linear Solution c++ | linear-solution-c-by-user5376zt-2v7z | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. Find maximum Spell power.\n2. Create an array counts of length max spe | user5376Zt | NORMAL | 2023-04-02T05:42:05.845796+00:00 | 2023-04-02T05:42:05.845843+00:00 | 947 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Find maximum Spell power.\n2. Create an array `counts` of length `max spell power` filled with zeros.\n3. For each potion calculate minimum required spell. If required spell <= maximum spell power, increment counts of req... | 13 | 0 | ['C++'] | 4 |
successful-pairs-of-spells-and-potions | 🔥 C++ Beginner Friendly Explanation - Brute Force to Optimized Intuition 🤔 | c-beginner-friendly-explanation-brute-fo-ulk4 | Brute Force [Time Limit Exceeded]\n\n## Intuition\nInitially, it sounds like we can just multiply each spell for each potion, but this is not fast enough.\n\n## | hotpotmaster | NORMAL | 2023-04-02T02:50:04.157798+00:00 | 2023-04-02T02:52:51.670892+00:00 | 2,480 | false | # Brute Force [Time Limit Exceeded]\n\n## Intuition\nInitially, it sounds like we can just multiply each `spell` for each `potion`, but this is not fast enough.\n\n## Algorithm Design\n- Loop for each `spell`\n - Loop for each `potion`\n - Increase count if the product is $$>=$$ `success`\n\n## Code\n```cpp\ncl... | 13 | 0 | ['Two Pointers', 'Binary Search', 'Sorting', 'C++'] | 2 |
successful-pairs-of-spells-and-potions | Day 92 || Binary Search || Easiest Beginner Friendly Sol | day-92-binary-search-easiest-beginner-fr-xhid | NOTE - PLEASE READ INTUITION AND APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITELY UNDERSTAND THE CODE LINE BY LINE AFTER SEEING THE APPROACH.\n \nNOTE 2 - | singhabhinash | NORMAL | 2023-04-02T00:51:35.880659+00:00 | 2023-04-02T01:19:24.160785+00:00 | 4,697 | false | **NOTE - PLEASE READ INTUITION AND APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITELY UNDERSTAND THE CODE LINE BY LINE AFTER SEEING THE APPROACH.**\n \n**NOTE 2 - I WILL HIGHLY RECOMMEND YOU GUYS BEFORE SOLVING THIS PROBLEM PLEASE SOLVE BINARY SEARCH PROBLEM.**\n\n**704. Binary Search Problem -** https://leetcode.co... | 13 | 1 | ['Array', 'Binary Search', 'C++', 'Java', 'Python3'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.