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
course-schedule-iv
C++ | DFS | Memoization
c-dfs-memoization-by-wh0ami-9lkc
\nclass Solution {\n vector<vector<int>>dp;\n bool dfs(unordered_map<int, vector<int>>& mp, int a, int b) {\n \n if (dp[a][b] != -1)\n
wh0ami
NORMAL
2020-05-30T16:25:22.671052+00:00
2020-05-31T06:30:06.329296+00:00
7,802
false
```\nclass Solution {\n vector<vector<int>>dp;\n bool dfs(unordered_map<int, vector<int>>& mp, int a, int b) {\n \n if (dp[a][b] != -1)\n return dp[a][b];\n \n for (int i = 0; i < mp[a].size(); i++) {\n if (mp[a][i] == b || dfs(mp, mp[a][i], b))\n r...
58
4
[]
7
course-schedule-iv
Simple Unordered map Number Linking
simple-unordered-map-link-by-sumeet_shar-4d5l
IntuitionThis problem is about understanding and navigating a dependency graph, where: Each course is represented as a node. Each prerequisite relationship is r
Sumeet_Sharma-1
NORMAL
2025-01-27T01:02:50.174372+00:00
2025-01-27T01:19:38.626724+00:00
9,483
false
# Intuition This problem is about understanding and navigating a dependency graph, where: - Each course is represented as a node. - Each prerequisite relationship is represented as a directed edge from one course to another (e.g., if course `a` is a prerequisite for course `b`, there's an edge from `a` to `b`). The go...
55
1
['Ordered Map', 'C++']
8
course-schedule-iv
[C++] Easy to understand BFS solution
c-easy-to-understand-bfs-solution-by-him-vj3o
Step1: Create adjaceny list.\nStep2: Perform BFS on each node ignoring already visted path.\nStep3: Answer each query using isReachable[i][j] which denotes if t
himsingh11
NORMAL
2020-05-30T17:24:15.084940+00:00
2020-06-02T17:38:22.356991+00:00
4,662
false
Step1: Create adjaceny list.\nStep2: Perform BFS on each node ignoring already visted path.\nStep3: Answer each query using `isReachable[i][j]` which denotes if there is a path from `i` to `j`\n\n```cpp\nvector<bool> checkIfPrerequisite(int n, vector<vector<int>>& prerequisites, vector<vector<int>>& queries) \n{\n ...
41
1
['Breadth-First Search', 'C']
3
course-schedule-iv
Topological Sorting | Bitset | With Explanation | 100% BEATS
topological-sorting-bitset-with-explanat-1k8u
Problem Understanding:We need to determine if course u is a direct or indirect prerequisite for course v for multiple queries. Courses and prerequisites form a
shubham6762
NORMAL
2025-01-27T03:44:02.758678+00:00
2025-01-27T03:44:02.758678+00:00
7,018
false
## **Problem Understanding:** We need to determine if course `u` is a direct or indirect prerequisite for course `v` for multiple queries. Courses and prerequisites form a directed acyclic graph (DAG), where an edge `A → B` means "A is a prerequisite for B." ### **Key Insight:** For each course, track all its prer...
30
3
['Breadth-First Search', 'Graph', 'Topological Sort', 'Python', 'C++', 'Java']
7
course-schedule-iv
Clean Python 3, topological sort and set O(P * N)
clean-python-3-topological-sort-and-set-9902v
Just use a set to save all prerequisites of current course and pass all of them to those courses which take it as prerequisite while performing topological sort
lenchen1112
NORMAL
2020-05-30T17:40:45.846048+00:00
2020-05-31T15:58:34.116913+00:00
3,511
false
Just use a set to save all prerequisites of current course and pass all of them to those courses which take it as prerequisite while performing topological sort.\nTime: `O(P * N)`, N for topological sort and P for passing all prerequisites.\nSpace: `O(N^2)` for all sets.\n```\nimport collections\nclass Solution:\n d...
27
1
[]
5
course-schedule-iv
Kahn's Alg+ array over bitset vs DFS||C++100% Py3 97.9%
kahns-alg-array-over-bitsetc100-by-anwen-6364
IntuitionAgain use topo sort, i.e. Kahn's algorithm. For a directed edge (a, b) in G, a is a prerequisite course for b. For any query (u, v) being in G or not,
anwendeng
NORMAL
2025-01-27T00:41:22.197839+00:00
2025-01-27T07:48:09.206844+00:00
2,916
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Again use topo sort, i.e. Kahn's algorithm. For a directed edge `(a, b)` in $G$, `a` is a prerequisite course for `b`. For any query `(u, v)` being in $G$ or not, it is constructed a container `rpath[v][u]` by using an array of bitsets to k...
26
2
['Bit Manipulation', 'Depth-First Search', 'Breadth-First Search', 'Topological Sort', 'C++']
4
course-schedule-iv
Most Optimal Solution with Topological Sort | C++| Java | Python | JavaScript
most-optimal-solution-with-topological-s-84x3
⬆️Upvote if it helps ⬆️Connect with me on Linkedin [Bijoy Sing]🧠 IntuitionThink of courses like a family tree! 👨‍👩‍👧‍👦 Each course can have "parent" courses (pr
BijoySingh7
NORMAL
2025-01-27T03:53:36.149917+00:00
2025-01-27T03:53:36.149917+00:00
5,799
false
# ⬆️Upvote if it helps ⬆️ --- ## Connect with me on Linkedin [Bijoy Sing] --- ```cpp [] class Solution { public: vector<bool> checkIfPrerequisite(int numCourses, vector<vector<int>>& prerequisites, vector<vector<int>>& queries) { vector<vector<int>> adj(numCourses); vector<int> indegree(numCours...
24
0
['Graph', 'Topological Sort', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']
1
course-schedule-iv
[python3][Topological Sort][BFS] Clear solution with comments
python3topological-sortbfs-clear-solutio-zr9d
Summary: the idea is to use topological sort to create a prerequisite lookup dictionary. \n\nSince this method is query-intensive, so we need to have O(1) time
chenhanxiong1990
NORMAL
2021-09-24T05:10:32.838692+00:00
2022-01-05T19:54:31.250889+00:00
2,669
false
Summary: the idea is to use topological sort to create a prerequisite lookup dictionary. \n\nSince this method is query-intensive, so we need to have O(1) time for query. In this case, we need to create a dictionary with each course as the key and the value is a set including all the prerequisites of this course. This ...
23
0
['Breadth-First Search', 'Topological Sort', 'Python', 'Python3']
5
course-schedule-iv
Multiple Approaches || BFS and DFS || C++ Clean Code
multiple-approaches-bfs-and-dfs-c-clean-m32jr
This problem can be solved using multiple approaches. In this post I have included two of such appoach, one using DFS , and another using BFS (Topo Sort). \n# A
i_quasar
NORMAL
2021-10-30T05:51:40.150992+00:00
2021-10-30T05:51:40.151039+00:00
2,313
false
This problem can be solved using multiple approaches. In this post I have included two of such appoach, one using DFS , and another using BFS (Topo Sort). \n# Approach 1 : using DFS\n * Idea here is to iterate over all nodes taking it as source, \n * and then find all reachable nodes from source. Mark all those nodes a...
22
0
['Depth-First Search', 'Breadth-First Search', 'Topological Sort']
2
course-schedule-iv
Python | DFS + Caching
python-dfs-caching-by-underoos16-myva
\nclass Solution:\n def checkIfPrerequisite(self, n: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n from collections
underoos16
NORMAL
2020-05-30T17:57:11.786643+00:00
2020-06-06T02:50:47.814435+00:00
2,233
false
```\nclass Solution:\n def checkIfPrerequisite(self, n: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n from collections import defaultdict\n adj_list = defaultdict(list)\n\n for a,b in prerequisites:\n adj_list[a].append(b)\n\n from functools im...
15
0
[]
7
course-schedule-iv
Easy & Detailed Approch💡| Normal DFS Only ✅ | All Languages 🔥
easy-detailed-approch-normal-dfs-only-al-ek3y
IntuitionThe problem can be visualized as a directed graph, where each course is a node and each prerequisite pair represents a directed edge from one course to
himanshu_dhage
NORMAL
2025-01-27T03:31:18.267222+00:00
2025-01-27T03:31:18.267222+00:00
1,681
false
# Intuition The problem can be visualized as a **directed graph**, where each course is a node and each prerequisite pair represents a directed edge from one course to another. The goal is to determine if one course is a prerequisite for another based on the given queries. To achieve this, we need to identify all...
14
0
['Array', 'Hash Table', 'Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'Ordered Set', 'C++', 'Java', 'Python3']
0
course-schedule-iv
Python-Easy to understand Topological sort , beats 100%
python-easy-to-understand-topological-so-3h36
If you find it useful, please upvote it so that others can find it easily.\n# Complexity\n- Time complexity:\no(n(p+n)q)\n# please upvote if found helpful\n# Co
charant587
NORMAL
2023-06-30T12:40:59.932396+00:00
2023-07-12T18:40:38.310762+00:00
1,298
false
# If you find it useful, please upvote it so that others can find it easily.\n# Complexity\n- Time complexity:\no(n(p+n)q)\n# please upvote if found helpful\n# Code\n```\nclass Solution(object):\n def checkIfPrerequisite(self, numCourses, prerequisites, queries):\n adj={i:[] for i in range(numCourses)}\n\n ...
13
0
['Topological Sort', 'Python', 'Python3']
1
course-schedule-iv
Java simple DFS better than 94%. O(n^2) for building and O(1) for queries
java-simple-dfs-better-than-94-on2-for-b-rlov
The idea here is to fill a nxn boolean matrix with either the second node is reachable from the first or not (even through an indirect way). Why am I doing this
tarkhan
NORMAL
2021-02-10T20:38:08.240732+00:00
2021-03-04T16:16:18.675878+00:00
2,169
false
The idea here is to fill a nxn boolean matrix with either the second node is reachable from the first or not (even through an indirect way). Why am I doing this? because we have multiple queries and the number of these queries most likely will be more than the length of the prerequisites we have so we can save a lot of...
13
1
['Depth-First Search', 'Java']
2
course-schedule-iv
DFS Memo Solution - Python
dfs-memo-solution-python-by-richyrich200-gozy
IntuitionApproachComplexity Time complexity: Space complexity: Code
RichyRich2004
NORMAL
2025-01-27T00:26:21.938520+00:00
2025-01-27T00:26:21.938520+00:00
1,767
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 `...
11
0
['Python3']
2
course-schedule-iv
C++ DFS Solution, O(q*N)
c-dfs-solution-oqn-by-pooja0406-6c5m
```\nclass Solution {\npublic:\n vector checkIfPrerequisite(int n, vector>& prerequisites, vector>& queries) {\n \n if(queries.size() == 0)\n
pooja0406
NORMAL
2020-09-01T14:31:59.482094+00:00
2020-09-01T14:31:59.482161+00:00
1,606
false
```\nclass Solution {\npublic:\n vector<bool> checkIfPrerequisite(int n, vector<vector<int>>& prerequisites, vector<vector<int>>& queries) {\n \n if(queries.size() == 0)\n return {};\n \n vector<vector<int>> adj(n);\n for(auto it : prerequisites)\n {\n ...
11
0
['Depth-First Search', 'C']
4
course-schedule-iv
[C++] Simple solution using DFS.
c-simple-solution-using-dfs-by-vinaykash-wrhp
\nclass Solution {\npublic:\n void dfs_new(vector<vector<int>> &graph, vector<bool> &vis, int source, int c){\n if(source != c){\n graph[so
vinaykashyap
NORMAL
2020-05-30T16:05:06.717736+00:00
2020-05-30T16:14:19.158014+00:00
2,243
false
```\nclass Solution {\npublic:\n void dfs_new(vector<vector<int>> &graph, vector<bool> &vis, int source, int c){\n if(source != c){\n graph[source][c] = 1;\n }\n if(!vis[c]){\n vis[c] = true;\n for(int i = 0; i < graph[c].size(); i++){\n if(graph[c...
11
2
['Depth-First Search', 'C']
3
course-schedule-iv
✅ Three Simple Lines of Code
three-simple-lines-of-code-by-mikposp-lzc3
Code #1RefCode #2Ref
MikPosp
NORMAL
2025-01-27T13:00:06.488916+00:00
2025-01-27T21:18:19.292304+00:00
859
false
# Code #1 <!-- Time complexity: $$O(n^2+q)$$. Space complexity: $$O(n^2)$$. --> ```python3 class Solution: def checkIfPrerequisite(self, _: int, p: List[List[int]], q: List[List[int]]) -> List[bool]: g = {v:[*zip(*w)][1] for v,w in groupby(p,itemgetter(0))} f = cache(lambda v:{v}.union(*map(f,g.get(...
10
0
['Depth-First Search', 'Graph', 'Python', 'Python3']
4
course-schedule-iv
✅Effortless and Efficient Solution by Kanishka✅|| 🔥🔥Beats 100% in Java🚀🚀
effortless-and-efficient-solution-by-kan-ib3u
🧠 IntuitionMy first thought is to use Depth-First Search (DFS) to determine if there is a path from one course to another, which would indicate a prerequisite r
kanishka21535
NORMAL
2025-01-27T00:10:51.078776+00:00
2025-01-27T00:10:51.078776+00:00
2,337
false
# 🧠 Intuition My first thought is to use Depth-First Search (DFS) to determine if there is a path from one course to another, which would indicate a prerequisite relationship. # 🔍 Approach Here's the approach step-by-step: 1. **Graph Representation**: Represent the courses and prerequisites using an adjacency list. ...
10
0
['Java']
1
course-schedule-iv
[Python] Floyd-Warshall V.S. Topological Sort
python-floyd-warshall-vs-topological-sor-amjn
Solution 1\nstandard floyd-warshall algorithm, works not only for DAGs but also on general graphs.\n\n\ndef checkIfPrerequisite(numCourses: int, prerequisites:
jacoboy
NORMAL
2022-07-01T02:16:17.889873+00:00
2022-07-01T02:17:43.222514+00:00
1,105
false
### Solution 1\nstandard [floyd-warshall algorithm](https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm), works not only for DAGs but also on general graphs.\n\n```\ndef checkIfPrerequisite(numCourses: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n \'\'\'\n Problem: All...
10
0
['Breadth-First Search', 'Topological Sort', 'Python']
1
course-schedule-iv
Course Schedule IV [C++]
course-schedule-iv-c-by-moveeeax-85u8
IntuitionThe problem requires checking if a course is a prerequisite for another course. A natural way to approach this is by representing the problem as a dire
moveeeax
NORMAL
2025-01-27T07:33:52.760186+00:00
2025-01-27T07:33:52.760186+00:00
580
false
# Intuition The problem requires checking if a course is a prerequisite for another course. A natural way to approach this is by representing the problem as a directed graph where an edge from course `u` to `v` indicates that `u` is a prerequisite for `v`. Using this graph representation, we can efficiently determine w...
9
0
['C++']
0
course-schedule-iv
TOPOLOGICAL SORT 99% FASTER
topological-sort-99-faster-by-the_moonli-y4hc
\t// time O(ev + queries.size()) , e == # of edges , v = #of vertices\n\t/ approach :\n\t\t --> visit vertices on topological sorting order\n\t\t --> create
the_moonLight
NORMAL
2021-01-16T11:50:37.144118+00:00
2021-01-16T11:50:37.144143+00:00
1,840
false
\t// time O(e*v + queries.size()) , e == # of edges , v = #of vertices\n\t/* approach :\n\t\t --> visit vertices on topological sorting order\n\t\t --> create a 2d boolean array of size n*n where array[i][j]==true means i has a pre req of j\n\t\t --> find all prereq of a course .\n\t\t --> prereq of current course...
9
0
[]
1
course-schedule-iv
super simple approach, Floyd Warshall with added YouTube video explanation
super-simple-approach-floyd-warshel-by-v-hmjy
YouTube Solution Intuition and approachbefore solution, we know to pass 12Th standard we need to first pass high school exam , also to pass Graduation course w
vinod_aka_veenu
NORMAL
2025-01-27T00:55:40.844140+00:00
2025-01-27T02:05:34.841752+00:00
1,347
false
# YouTube Solution https://youtu.be/2iuUNAhdR0Y?si=0xlGv_tXpIuZvwap # Intuition and approach before solution, we know to pass **12Th standard** we need to first pass **high school** exam , also to pass **Graduation course** we need to pass the **12th class Exam** so we can also say that to pass the graduation we have ...
8
0
['Array', 'Depth-First Search', 'Breadth-First Search', 'Python', 'C++', 'Java', 'C#']
3
course-schedule-iv
Short and clean solution according to the Hints
short-and-clean-solution-according-to-th-rcas
Just use the Hints from the Problem description:💡 Hint 1 Imagine if the courses are nodes of a graph. We need to build an array isReachable[i][j].💡 Hint 2 Start
charnavoki
NORMAL
2025-01-27T00:26:22.116356+00:00
2025-01-27T00:27:16.538933+00:00
652
false
Just use the Hints from the Problem description: 💡 Hint 1 Imagine if the courses are nodes of a graph. We need to build an array isReachable[i][j]. 💡 Hint 2 Start a bfs from each course i and assign for each course j you visit isReachable[i][j] = True. 💡 Hint 3 Answer the queries from the isReachable array. ``...
7
0
['JavaScript']
1
course-schedule-iv
[C++] straightfwd solution using Toposort and BFS w/ comments!
c-straightfwd-solution-using-toposort-an-hv30
\n# Code\n\nclass Solution {\npublic:\n\n bool canvisit(int node, int target, vector<int> adj[], int n){ // to find if we can visit the other node!\n\n
KingShuK17
NORMAL
2023-07-26T12:11:01.386622+00:00
2023-07-26T12:11:01.386642+00:00
1,002
false
\n# Code\n```\nclass Solution {\npublic:\n\n bool canvisit(int node, int target, vector<int> adj[], int n){ // to find if we can visit the other node!\n\n queue<int> q;\n vector<int> vis(n,0);\n vis[node]=1;\n q.push({node});\n\n while(!q.empty()){\n int num = q.front();...
7
0
['Breadth-First Search', 'Topological Sort', 'C++']
2
course-schedule-iv
Beats 100.0% | Floyd-Warshall algorithm | C
beats-1000-floyd-warshall-algorithm-c-by-si9i
IntuitionSince prerequisites can be indirect, we need to compute whether there exists a path from one course to another in this directed graph. Precomputing thi
aash24
NORMAL
2025-01-27T05:01:39.212483+00:00
2025-01-27T05:01:39.212483+00:00
210
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Since prerequisites can be indirect, we need to compute whether there exists a path from one course to another in this directed graph. Precomputing this information allows us to efficiently answer multiple queries. # Approach <!-- Describe...
6
0
['C']
0
course-schedule-iv
DFS and BFS solution || Kahn's algorithm || Explanation
dfs-and-bfs-solution-kahns-algorithm-exp-3rnu
1. DFS-Based ApproachIntuitionTo determine if one course is a prerequisite for another, we can represent the courses and their dependencies as a directed graph.
Anurag_Basuri
NORMAL
2024-12-30T08:25:26.199378+00:00
2024-12-30T08:25:26.199378+00:00
587
false
# 1. DFS-Based Approach ## Intuition To determine if one course is a prerequisite for another, we can represent the courses and their dependencies as a directed graph. If there's a directed path from one course to another, then the first course is a prerequisite for the second. We use **Depth-First Search (DFS)** to e...
6
0
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'C++', 'Python3']
0
course-schedule-iv
[C++] 2 Solutions - BFS , Flyod Warshall
c-2-solutions-bfs-flyod-warshall-by-apar-o4cj
The only logic :\nThere can be a path between 2 nodes either directly or indirectly. \nif \'A\' is prerequisite of \'B\' then \'A\' is also a prerequisite of al
aparna_g
NORMAL
2021-08-01T12:38:27.029833+00:00
2021-08-01T13:35:40.441508+00:00
744
false
The only logic :\nThere can be a path between 2 nodes either directly or indirectly. \n**if \'A\' is prerequisite of \'B\' then \'A\' is also a prerequisite of all courses with \'B\' as prerequisite**\n**Solution 1: BFS**\n```\nclass Solution {\npublic:\n vector<bool> checkIfPrerequisite(int n, vector<vector<int>>& ...
6
0
['Breadth-First Search', 'C', 'C++']
0
course-schedule-iv
Java Floyd-Warshal alg
java-floyd-warshal-alg-by-hobiter-al40
Detail in: https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm\n\npublic List<Boolean> checkIfPrerequisite(int n, int[][] prqs, int[][] qs) {\n
hobiter
NORMAL
2020-05-31T18:10:25.550952+00:00
2020-05-31T18:10:25.550990+00:00
619
false
Detail in: https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm\n```\npublic List<Boolean> checkIfPrerequisite(int n, int[][] prqs, int[][] qs) {\n boolean[][] prq = new boolean[n][n];\n for (int[] c : prqs) prq[c[0]][c[1]] = true;\n for (int i = 0; i < n; i++) {\n for (int j =...
6
0
[]
0
course-schedule-iv
DFS with cache Python Clean + Commented Code
dfs-with-cache-python-clean-commented-co-3oup
\ndef checkIfPrerequisite(self, n: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n \n # 3. mainly use DFS with Cac
uttam1728
NORMAL
2020-05-30T16:11:01.609278+00:00
2020-05-30T16:11:39.101488+00:00
825
false
```\ndef checkIfPrerequisite(self, n: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n \n # 3. mainly use DFS with Cache\n def path(s,e):\n if (s,e) in self.cache: #if in cache\n return (self.cache[(s,e)])\n if s == e: # edge ...
6
0
['Depth-First Search', 'Python']
1
course-schedule-iv
Easy Solution 🚀🚀🚀🚀🚀🚀🚀🚀
easy-solution-by-sharvil_karwa-6qyg
Code
Sharvil_Karwa
NORMAL
2025-01-27T04:10:53.517562+00:00
2025-01-27T04:10:53.517562+00:00
727
false
# Code ```cpp [] class Solution { public: bool dfs(unordered_map<int,vector<int>> &m, int node, vector<int> &vis, int target){ if(node==target) return true; vis[node] = 1; for(auto i:m[node]){ if(vis[i]==-1){ if(dfs(m,i,vis,target)) return true; } ...
5
0
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'Python', 'C++', 'Java']
0
course-schedule-iv
Transitive Closure Expansion using Floyd-Warshall Algorithm
transitive-closure-expansion-using-floyd-2iys
IntuitionTo handle direct and indirect prerequisites, we can use Floyd-Warshall to compute the transitive closure of the prerequisite graph.Approach Initializa
anand_shukla1312
NORMAL
2025-01-27T04:07:55.360629+00:00
2025-01-27T04:07:55.360629+00:00
132
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> To handle direct and indirect prerequisites, we can use Floyd-Warshall to compute the transitive closure of the prerequisite graph. # Approach <!-- Describe your approach to solving the problem. --> 1. **Initialization:** - A 2D list r...
5
0
['Python3']
0
course-schedule-iv
✅Effortless and Efficient Solution by Dhandapani✅|| 🔥🔥Beats 100% in Java🚀🚀
effortless-and-efficient-solution-by-dha-g3rm
🧠 IntuitionMy first thought is to use Depth-First Search (DFS) to determine if there is a path from one course to another, which would indicate a prerequisite r
Dhandapanimaruthasalam
NORMAL
2025-01-27T00:07:40.885733+00:00
2025-01-27T00:07:40.885733+00:00
498
false
# 🧠 Intuition My first thought is to use Depth-First Search (DFS) to determine if there is a path from one course to another, which would indicate a prerequisite relationship. # 🔍 Approach Here's the approach step-by-step: 1. **Graph Representation**: Represent the courses and prerequisites using an adjacency list. ...
5
1
['Java']
1
course-schedule-iv
Java BFS soluion
java-bfs-soluion-by-motorix-7lkq
The question is to check if two nodes are connected in a directed acyclic graph.\n\n1. Build all the edges\n2. BFS to check every query if two nodes are connect
motorix
NORMAL
2020-05-30T16:47:46.989573+00:00
2020-05-30T16:49:45.365183+00:00
278
false
The question is to check if two nodes are connected in a directed acyclic graph.\n\n1. Build all the edges\n2. BFS to check every query if two nodes are connected\n\n**Java**\n```\nclass Solution {\n public List<Boolean> checkIfPrerequisite(int n, int[][] pre, int[][] queries) {\n // Build adjacency list\n ...
5
0
[]
0
course-schedule-iv
[Python] DP simple solution
python-dp-simple-solution-by-ligt-0nb1
\nclass Solution:\n def checkIfPrerequisite(self, n: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n preqs = [set() fo
ligt
NORMAL
2020-05-30T16:01:38.216863+00:00
2020-05-31T00:54:06.441799+00:00
1,148
false
```\nclass Solution:\n def checkIfPrerequisite(self, n: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n preqs = [set() for _ in range(n)]\n reverse_preqs = [set() for _ in range(n)]\n for preq in prerequisites:\n preqs[preq[0]].add(preq[1])\n ...
5
1
[]
2
course-schedule-iv
✅ Easy to Understand | Graph Theory - Floyd Warshall Algorithm | Detailed Video Explanation🔥
easy-to-understand-graph-theory-floyd-wa-t8qq
IntuitionThe problem is essentially about determining whether one course is a prerequisite for another, either directly or indirectly. The task can be visualize
sahilpcs
NORMAL
2025-01-27T10:29:27.963693+00:00
2025-01-27T10:29:27.963693+00:00
142
false
# Intuition The problem is essentially about determining whether one course is a prerequisite for another, either directly or indirectly. The task can be visualized as a graph problem, where courses are nodes, and prerequisites are directed edges. The key is to compute the transitive closure of the graph, which tells u...
4
0
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'Java']
1
course-schedule-iv
C++ Solution || Easy to Understand || Topological Sorting
c-solution-easy-to-understand-topologica-fhnj
ApproachIntuitionThe problem can be solved using a graph traversal approach where: The courses are represented as nodes in a directed graph. The prerequisites d
Rohit_Raj01
NORMAL
2025-01-27T10:25:35.334093+00:00
2025-01-27T10:25:35.334093+00:00
429
false
# Approach ### Intuition The problem can be solved using a graph traversal approach where: 1. The courses are represented as nodes in a directed graph. 2. The prerequisites define directed edges between nodes. We can use a topological sorting approach and keep track of all prerequisites for each course using a `vecto...
4
0
['Breadth-First Search', 'Graph', 'Topological Sort', 'C++']
1
course-schedule-iv
Python | DFS and Memo | O(n+q), O(n+q) | Beats 99%
python-dfs-and-memo-code-w-notes-by-2pil-so1m
CodeComplexity Time complexity: O(n+q). Visit each course and query once. Space complexity: O(n+q). Creates multiple objects of len(numCourses) and a single
2pillows
NORMAL
2025-01-27T01:47:03.237414+00:00
2025-01-28T04:59:57.777604+00:00
92
false
# Code ```python3 [] class Solution: def checkIfPrerequisite(self, numCourses: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]: direct_reqs = [set() for _ in range(numCourses)] # collect direct required courses from [req, course] pairs for req, course in prerequisites: ...
4
0
['Depth-First Search', 'Topological Sort', 'Memoization', 'Python3']
1
course-schedule-iv
Functional / iterator approach with successors | 2ms
functional-iterator-approach-with-succes-6ari
IntuitionBFS / Kahn's to create the is_prereqApproachDuring processing, we can use std::iter::successors to make the code more functional. Also since the constr
stevenylai
NORMAL
2025-01-18T06:57:27.152396+00:00
2025-01-18T06:57:27.152396+00:00
71
false
# Intuition BFS / Kahn's to create the `is_prereq` # Approach During processing, we can use `std::iter::successors` to make the code more functional. Also since the constrains is max of 100 courses, we can use an 128-bit int # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Sp...
4
0
['Rust']
1
course-schedule-iv
Cpp Easy Solution Using Dfs
cpp-easy-solution-using-dfs-by-sanket_ja-hxct
```\nclass Solution {\npublic:\n bool func(int i,int j,vector>&edge,vector&vis){\n if(i==j)return true;\n vis[i]=1;\n \n for(auto
Sanket_Jadhav
NORMAL
2022-08-29T11:25:49.485542+00:00
2022-08-29T11:25:49.485578+00:00
770
false
```\nclass Solution {\npublic:\n bool func(int i,int j,vector<vector<int>>&edge,vector<int>&vis){\n if(i==j)return true;\n vis[i]=1;\n \n for(auto ele:edge[i]){\n if(!vis[ele]){\n if(func(ele,j,edge,vis))return true;\n }\n }\n \n r...
4
0
['Depth-First Search', 'C++']
1
course-schedule-iv
✔Java Solution Using Floyd Warshall Algorithm💯
java-solution-using-floyd-warshall-algor-mdc0
Preprocessing is O(n\xB3)\nEach Query in O(1)\n\nhttps://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm\n\nFloyd warshall is little bit modified here, I
harshu175
NORMAL
2021-07-29T20:25:07.130046+00:00
2021-07-29T20:25:07.130078+00:00
317
false
**Preprocessing is O(n\xB3)**\n**Each Query in O(1)**\n\n[https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm](http://)\n\n**Floyd warshal**l is little bit modified here, In real algo we find shortest path between i & j, but now we will **store a boolean value to tell us that is there a path exist between i ...
4
2
['Java']
0
course-schedule-iv
Java Simple and easy to understand DFS solution, clean code with comments
java-simple-and-easy-to-understand-dfs-s-myyl
PLEASE UPVOTE IF YOU LIKE THIS SOLUTION\n\n\n\n\nclass Solution {\n public List<Boolean> checkIfPrerequisite(int numCourses, int[][] prerequisites, int[][] q
satyaDcoder
NORMAL
2021-05-05T08:36:03.421116+00:00
2021-05-05T08:36:03.421144+00:00
379
false
**PLEASE UPVOTE IF YOU LIKE THIS SOLUTION**\n\n\n\n```\nclass Solution {\n public List<Boolean> checkIfPrerequisite(int numCourses, int[][] prerequisites, int[][] queries) {\n \n //adj[i] -> list of all course dependent by course<i>\n ArrayList<Integer>[] adj = new ArrayList[numCourses];\n ...
4
0
['Java']
0
course-schedule-iv
99% beat Java | short and easy | No Floyd-Warshall | O(EV)
99-beat-java-short-and-easy-no-floyd-war-trdz
I think there is no need to explain, as code explained everything itself.\nI am not clear related to complexity, which I think O(V + EV) ~ O(EV), but if you fe
agarwalaarrav
NORMAL
2020-12-24T18:59:22.581615+00:00
2020-12-25T23:29:13.065268+00:00
590
false
I think there is no need to explain, as code explained everything itself.\nI am not clear related to complexity, which I think O(V + EV) ~ O(EV), but if you fell I am wrong, please comment.\n```\n public void dfs(int node, int n, ArrayList<Integer>[] gr, boolean[] vis, boolean[][] mat){\n\t\n if( vis[node]) ...
4
0
['Depth-First Search', 'Graph', 'Memoization', 'Java']
2
course-schedule-iv
300ms Beat 100% ! C++ Bit Manipulation
300ms-beat-100-c-bit-manipulation-by-xxx-q2i3
I use cache[i] (bitset<100>) to store all reachable nodes for i. In the recursion, node i collects (by | operation) reachable nodes only once, return cache[i]
xxx1123
NORMAL
2020-07-26T13:34:52.805906+00:00
2020-07-27T03:06:56.450118+00:00
431
false
**I use cache[i] (bitset<100>) to store all reachable nodes for i. In the recursion, node i collects (by ```|``` operation) reachable nodes only once, return cache[i] if it already exists.\nThe time complexity is almost O(N + E).**\n\n```\nvector<bool> checkIfPrerequisite(int n, vector<vector<int>>& prerequisites, vec...
4
0
[]
1
course-schedule-iv
java dfs 97%
java-dfs-97-by-atwjsw-381g
class Solution {\n \n List[] adj; // adjcency list\n boolean[][] isReachable;\n \n public List checkIfPrerequisite(int n, int[][] prerequisites,
atwjsw
NORMAL
2020-07-18T18:59:15.068524+00:00
2020-07-18T19:12:08.564341+00:00
260
false
class Solution {\n \n List<Integer>[] adj; // adjcency list\n boolean[][] isReachable;\n \n public List<Boolean> checkIfPrerequisite(int n, int[][] prerequisites, int[][] queries) {\n \n adj = new List[n];\n isReachable = new boolean[n][n];\n \n for (int i = 0; i < n; i...
4
0
[]
1
course-schedule-iv
C++ optimal approach beats 100%
c-optimal-approach-beats-100-by-sakshaml-yff1
ApproachInstead of checking for every 2 nodes in queries , we can check for which node the selected node is prerequisite. This works because numCourses can only
LeviLovesToSolve
NORMAL
2025-01-28T16:20:30.897164+00:00
2025-01-28T16:20:30.897164+00:00
18
false
# Approach <!-- Describe your approach to solving the problem. --> Instead of checking for every 2 nodes in queries , we can check for which node the selected node is prerequisite. This works because numCourses can only be 100 while size of queries vector is 10000. # Complexity - Time complexity:O(N^3 + Q) <!-- Add ...
3
0
['Hash Table', 'C++']
0
course-schedule-iv
Optimised + Floyd Warshall
optimised-floyd-warshall-by-saurav_kumar-l3co
IntuitionThe problem can be modeled as a graph problem where we need to determine if there is a path (direct or indirect) between two nodes. Using the Floyd-War
Saurav_kumar_10
NORMAL
2025-01-27T20:09:15.680990+00:00
2025-01-27T20:09:15.680990+00:00
81
false
# Intuition The problem can be modeled as a graph problem where we need to determine if there is a path (direct or indirect) between two nodes. Using the **Floyd-Warshall algorithm**, we can efficiently compute the transitive closure of the graph, which allows us to answer each query in constant time. # Approach 1. *...
3
0
['C++', 'Java', 'Python3', 'JavaScript']
0
course-schedule-iv
-------JAVA-------
java-by-aysha3211-dr6u
Code
Aysha3211
NORMAL
2025-01-27T16:28:56.272500+00:00
2025-01-27T16:28:56.272500+00:00
86
false
# Code ```java [] class Solution { public List<Boolean> checkIfPrerequisite(int numCourses, int[][] prerequisites, int[][] queries) { boolean mat[][] = new boolean[numCourses][numCourses]; for(int i=0;i<prerequisites.length;i++){ int s = prerequisites[i][0]; int d = prerequ...
3
0
['Java']
0
course-schedule-iv
DFS-Based Solution for Course Schedule IV | Beats 85% 🔥 | Intuitive + Clean Code 💡
dfs-based-solution-for-course-schedule-i-1mqc
IntuitionThe problem is about determining whether one course is a prerequisite for another. This can be viewed as a graph problem, where courses are nodes, and
atharva_kalbande
NORMAL
2025-01-27T15:58:48.896750+00:00
2025-01-27T15:58:48.896750+00:00
20
false
# Intuition The problem is about determining whether one course is a prerequisite for another. This can be viewed as a graph problem, where courses are nodes, and prerequisites are directed edges. The goal is to figure out if there's a path from one node (course) to another in the graph # Approach - Graph Representati...
3
0
['Python']
0
course-schedule-iv
---------JAVA---------
java-by-ayeshakhan7-nc6z
ApproachKahn's AlgorithmComplexity Time complexity: O(V^2 + V + E) -> Processing Nodes (each node pushed once in queue) = O(V), Processing edges = O(E), Inserti
ayeshakhan7
NORMAL
2025-01-27T15:20:41.605551+00:00
2025-01-27T15:20:41.605551+00:00
80
false
# Approach <!-- Describe your approach to solving the problem. --> Kahn's Algorithm # Complexity - Time complexity: O(V^2 + V + E) -> Processing Nodes (each node pushed once in queue) = O(V), Processing edges = O(E), Inserting prerequisites (each node can have ~V prerequisites in worst case): O(V^2) <!-- Add your t...
3
0
['Java']
0
course-schedule-iv
✅✅Beats 100%🔥C++🔥Python|| 🚀🚀Super Simple and Efficient Solution🚀🚀||🔥Python🔥C++✅✅
beats-100cpython-super-simple-and-effici-41vz
Complexity Time complexity: O(n3) Space complexity: O(n2) ⬆️👇⬆️UPVOTE it⬆️👇⬆️Code⬆️👇⬆️UPVOTE it⬆️👇⬆️
shobhit_yadav
NORMAL
2025-01-27T14:41:31.600408+00:00
2025-01-27T14:41:31.600408+00:00
162
false
# Complexity - Time complexity: $$O(n^3)$$ <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: $$O(n^2)$$ <!-- Add your space complexity here, e.g. $$O(n)$$ --> ⬆️👇⬆️UPVOTE it⬆️👇⬆️ # Code ```cpp [] class Solution { public: vector<bool> checkIfPrerequisite(int numCourses, vector<vector<int>>...
3
0
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'C++', 'Python3']
0
course-schedule-iv
simple py solution
simple-py-solution-by-noam971-60rf
IntuitionApproachComplexity Time complexity: Space complexity: Code
noam971
NORMAL
2025-01-27T08:33:43.399273+00:00
2025-01-27T08:33:43.399273+00:00
141
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
['Python3']
1
course-schedule-iv
C# Solution for Course Schedule IV Problem
c-solution-for-course-schedule-iv-proble-14ld
IntuitionThe problem involves checking whether one course is a prerequisite for another, either directly or indirectly. This can be represented as a directed gr
Aman_Raj_Sinha
NORMAL
2025-01-27T03:47:50.651612+00:00
2025-01-27T03:47:50.651612+00:00
128
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> The problem involves checking whether one course is a prerequisite for another, either directly or indirectly. This can be represented as a directed graph, where courses are nodes and prerequisites are directed edges. The goal is to answer ...
3
0
['C#']
0
course-schedule-iv
Simple Unordered Map And Queue C++ || Beats 99% of Users || Dynamic Programming
simple-unordered-map-and-queue-c-beats-9-tcch
IntuitionApproachComplexity Time complexity: Space complexity: Code
Mohit-Kumawat04
NORMAL
2025-01-27T01:32:25.080677+00:00
2025-03-21T04:48:26.704586+00:00
390
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
['Hash Table', 'Linked List', 'Dynamic Programming', 'Greedy', 'Depth-First Search', 'Breadth-First Search', 'C++']
1
course-schedule-iv
UMPIRE-style solution
umpire-style-solution-by-espertusnu-bmva
This solution uses CodePath\'s UMPIRE interview strategy.\n\nThis is a slight modification to my Course Schedule II solution.\n\n# 1: U-nderstand\n\nThere are a
espertusnu
NORMAL
2024-06-16T19:49:46.897053+00:00
2024-06-16T19:49:46.897079+00:00
524
false
This solution uses [CodePath\'s UMPIRE interview strategy](https://guides.codepath.com/compsci/UMPIRE-Interview-Strategy).\n\nThis is a slight modification to my [Course Schedule II solution](https://leetcode.com/problems/course-schedule-ii/solutions/5323750/umpire-style-solution/).\n\n# 1: U-nderstand\n\nThere are a t...
3
0
['Java', 'Python3']
0
course-schedule-iv
( ͡° ͜ʖ ͡°)👉|| Beats 97.99%|| JAVA|| PYTHON||EASY SOLUTION💯☑️
deg-deg-beats-9799-java-pythoneasy-solut-y3xk
If you find it useful, please upvote so that others can find it easily.\n# Code\nJava []\nclass Solution {\n public void fillGraph(boolean[][] graph, int i,
Pratheek08
NORMAL
2023-08-31T05:09:57.983245+00:00
2023-08-31T05:11:17.426365+00:00
205
false
# If you find it useful, please upvote so that others can find it easily.\n# Code\n```Java []\nclass Solution {\n public void fillGraph(boolean[][] graph, int i, boolean[] visited){\n if (visited[i])\n return;\n visited[i] = true;\n for (int j=0;j<graph[i].length;j++){\n if...
3
0
['Python', 'Java', 'Python3']
1
course-schedule-iv
IIT | TOPO-LOGICAL SORT | 99 % FASTER
iit-topo-logical-sort-99-faster-by-robbe-xc18
Intuition\nTotal number of pairs of unique queries can be n^2. So, to avoid doing repetitive calculations, we will store these n^2 pairs.\nOur approach in this
robberkr
NORMAL
2023-06-26T19:20:05.636798+00:00
2023-06-26T19:20:05.636822+00:00
746
false
# Intuition\nTotal number of pairs of unique queries can be n^2. So, to avoid doing repetitive calculations, we will store these n^2 pairs.\nOur approach in this question will be in this way, if we know that Node A is a prerequisite of B, then all the prerequisites of Node A are also prerequisite of B. So, we will keep...
3
2
['C++']
2
course-schedule-iv
C++ Solution || Adjacency List and DFS || Easy to understand
c-solution-adjacency-list-and-dfs-easy-t-k1yf
\nvoid dfs(vector<int> adj[], int src, int& des, bool& temp, vector<bool>& vis) {\n if(vis[src]) return;\n vis[src] = true;\n \n if(
pranjal_gaur
NORMAL
2023-06-03T08:46:46.610336+00:00
2023-06-03T08:46:46.610389+00:00
938
false
```\nvoid dfs(vector<int> adj[], int src, int& des, bool& temp, vector<bool>& vis) {\n if(vis[src]) return;\n vis[src] = true;\n \n if(src == des) {\n temp = true;\n return;\n }\n \n for(auto it : adj[src]) dfs(adj, it, des, temp, vis);\n }\n ...
3
0
['Depth-First Search', 'C']
0
course-schedule-iv
C++ | Both 100% | Warshall + bitset speedup | explanation
c-both-100-warshall-bitset-speedup-expla-ea6q
\nclass Solution {\npublic:\n vector<bool> checkIfPrerequisite(int numCourses, vector<vector<int>>& prerequisites, vector<vector<int>>& queries){\n in
SunGod1223
NORMAL
2022-09-08T08:44:54.572769+00:00
2022-09-12T03:55:09.545778+00:00
1,178
false
```\nclass Solution {\npublic:\n vector<bool> checkIfPrerequisite(int numCourses, vector<vector<int>>& prerequisites, vector<vector<int>>& queries){\n int n=numCourses;\n bitset <100> and_mask(1),dp[n];\n vector <bool> rt(queries.size());\n for(int i=0;i<prerequisites.size();++i)\n ...
3
0
['C']
1
course-schedule-iv
C++ || Kahns algorithm || Topological Sort
c-kahns-algorithm-topological-sort-by-__-1jdg
\nclass Solution {\npublic:\n vector<bool> checkIfPrerequisite(int n , vector<vector<int>> &p , vector<vector<int>>& qr) {\n vector<int> indegree(n ,
__shinigami__
NORMAL
2022-07-26T06:54:41.938090+00:00
2022-07-26T06:54:41.938131+00:00
547
false
```\nclass Solution {\npublic:\n vector<bool> checkIfPrerequisite(int n , vector<vector<int>> &p , vector<vector<int>>& qr) {\n vector<int> indegree(n , 0) , adj[n];\n for(int i=0 ; i<p.size() ; i++) {\n int u = p[i][0];\n int v = p[i][1];\n indegree[v]++;\n ...
3
0
['Breadth-First Search', 'Topological Sort', 'C']
0
course-schedule-iv
Python. Topology Sort + DP. Time beats 90%. Complexity is O(N^2)
python-topology-sort-dp-time-beats-90-co-cd8j
The idea is to first do a topology sort, O(n + e). Then do a DP, O(n^2), on the reversed topology order. Then for every node v, you will know all the nodes it c
caitao
NORMAL
2020-09-05T20:28:06.716516+00:00
2020-09-05T20:34:38.192081+00:00
187
false
The idea is to first do a topology sort, O(n + e). Then do a DP, O(n^2), on the reversed topology order. Then for every node v, you will know all the nodes it can reach. Here n is the number of nodes, e is the number of edges, O(e) = O(n^2). \n\n```\nclass Solution:\n def checkIfPrerequisite(self, n: int, prerequisi...
3
0
[]
0
course-schedule-iv
Python DFS with simple explanation
python-dfs-with-simple-explanation-by-ab-fcdx
Overall approach is the following -\n Construct the initial adjacency list using the prerequisites array. Eg- if 1-->2-->3 (1 is prereq of 2, 2 is prereq of 3)
abhijitt
NORMAL
2020-05-30T17:26:47.041085+00:00
2020-05-30T17:28:03.518540+00:00
359
false
Overall approach is the following -\n* Construct the initial adjacency list using the `prerequisites` array. Eg- if 1-->2-->3 (1 is prereq of 2, 2 is prereq of 3) then - adjlist[3]=[2] & adjlist[2]=[1].\n* Maintain a list of visited nodes\n* Perform DFS on unvisited nodes to enhance our initial adjacency list to includ...
3
0
[]
0
course-schedule-iv
Simple Java DFS with memoization
simple-java-dfs-with-memoization-by-sumi-hg44
\nclass Solution {\n public List<Boolean> checkIfPrerequisite(int n, int[][] pr, int[][] queries) {\n \n List<List<Integer>> graph = new ArrayL
sumitk23
NORMAL
2020-05-30T16:15:08.266187+00:00
2020-05-31T06:57:35.806988+00:00
559
false
```\nclass Solution {\n public List<Boolean> checkIfPrerequisite(int n, int[][] pr, int[][] queries) {\n \n List<List<Integer>> graph = new ArrayList<>();\n for(int i = 0; i < n; i++) {\n graph.add(new ArrayList<Integer>());\n }\n \n for(int[] p : pr) {\n ...
3
0
['Depth-First Search', 'Memoization', 'Java']
1
course-schedule-iv
[Python3] Simple DFS + Caching
python3-simple-dfs-caching-by-manparvesh-4vvo
python\nclass Solution:\n def checkIfPrerequisite(self, n: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n if not prer
manparvesh
NORMAL
2020-05-30T16:09:47.860992+00:00
2020-05-30T16:09:47.861025+00:00
318
false
```python\nclass Solution:\n def checkIfPrerequisite(self, n: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n if not prerequisites:\n return [False]*len(queries)\n graph = collections.defaultdict(list)\n for u, v in prerequisites:\n graph[u]....
3
0
[]
1
course-schedule-iv
Elegant C++ solution with explanation
elegant-c-solution-with-explanation-by-s-yqrv
Brief C++ solution. Use Floyd Warshall.\n\n- Convert given prerequisites into a DAG (Directed Acyclic Graph)\n- For every two vertices, check every intermediate
shivankacct
NORMAL
2020-05-30T16:07:33.219471+00:00
2020-05-30T16:13:07.356634+00:00
477
false
Brief C++ solution. Use Floyd Warshall.\n\n- Convert given prerequisites into a DAG (Directed Acyclic Graph)\n- For every two vertices, check every intermediate vertex to see if a path is possible through it. Store this in a matrix. This takes O(n^3) time which is fine since n <= 100;\n- Queries can be done in O(1) tim...
3
0
[]
2
course-schedule-iv
Floyd Warshall soln || simple || C++ 🔥 🚀
floyd-warshall-soln-simple-c-by-manyug-4y1g
IntuitionWe need to see if there exists a path from i to j in queriesApproachFor path we have floyd warshall which tells us about path from one node to other di
manyuMG
NORMAL
2025-01-28T19:32:03.302389+00:00
2025-01-28T19:32:03.302389+00:00
12
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> We need to see if there exists a path from i to j in queries # Approach <!-- Describe your approach to solving the problem. --> For path we have floyd warshall which tells us about path from one node to other directly or via another node ...
2
0
['C++']
0
course-schedule-iv
Easy DFS solution.
easy-dfs-solution-by-kashyap_lokesh-nakk
IntuitionFirst we will make the Adjacency matrix from the given prerequisite vector. Then to answer each query, whether u is prerequisite of v or not, we can ju
kashyap_lokesh
NORMAL
2025-01-27T19:32:06.368756+00:00
2025-01-27T19:32:06.368756+00:00
30
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> First we will make the Adjacency matrix from the given prerequisite vector. Then to answer each query, whether u is prerequisite of v or not, we can just apply dfs on u. If starting from u we can reach v then u is prerequisite for v otherwi...
2
0
['C++']
0
course-schedule-iv
Simple DFS Solution | Java | Beats 90%
simple-dfs-solution-java-beats-90-by-har-kuy0
Approach Try to do DFS, starting from every node, see what all nodes can be visited - these nodes are the prerequisites we can directly get the answer for each
HarivardhanK
NORMAL
2025-01-27T18:29:32.407858+00:00
2025-01-27T18:29:32.407858+00:00
38
false
# Approach - Try to do DFS, starting from every node, see what all nodes can be visited - these nodes are the prerequisites - we can directly get the answer for each query by constant look-up from the boolean matrix # Complexity - Time complexity: O(N*N) - Space complexity: O(N*N) # Code ```java [] class Solution { ...
2
0
['Depth-First Search', 'Graph', 'Java']
0
course-schedule-iv
EASY SOLUTION | JAVA | (Clean Code)
easy-solution-java-clean-code-by-siddhar-89lo
Code
Siddharth_Bahuguna
NORMAL
2025-01-27T12:59:22.092694+00:00
2025-01-27T12:59:22.092694+00:00
131
false
# Code ```java [] class Solution { public List<Boolean> checkIfPrerequisite(int numCourses, int[][] prerequisites, int[][] queries) { boolean mat[][]=new boolean[numCourses][numCourses]; //fill the adjancency matrix based on prerequisites for(int i=0;i<prerequisites.length;i++){ ...
2
0
['Java']
0
course-schedule-iv
Kahn's Algorithm || Using Set and Map || Beats 100% Users ||
kahns-algorithm-using-set-and-map-beats-2sadm
IntuitionApproachComplexity Time complexity: Space complexity: Code
Heisenberg_wc
NORMAL
2025-01-27T10:53:04.656240+00:00
2025-01-27T10:53:04.656240+00:00
88
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 `...
2
0
['C++']
0
course-schedule-iv
Very Simple C++ [Floyd-Warshall]
very-simple-c-floyd-warshall-by-caffeine-u8r0
IntuitionThe problem involves determining if one course is a prerequisite of another in a directed graph of courses. Essentially, we want to check if there is a
caffeinekeyboard
NORMAL
2025-01-27T08:50:26.567328+00:00
2025-01-27T08:50:26.567328+00:00
144
false
# Intuition The problem involves determining if one course is a prerequisite of another in a directed graph of courses. Essentially, we want to check if there is a path from one node (course) to another. A simple way to handle multiple such checks (queries) is to find the *transitive closure* of this graph: if we know ...
2
0
['C++']
0
course-schedule-iv
Floyd Warshall | Easy Solution | Java
floyd-warshall-easy-solution-java-by-dee-iqiq
IntuitionThe problem is to determine if one course is a prerequisite for another based on a list of prerequisites. This can be modeled as a directed graph, wher
deepakkumars11022005
NORMAL
2025-01-27T08:19:22.079953+00:00
2025-01-27T08:35:42.555263+00:00
106
false
### **Intuition** The problem is to determine if one course is a prerequisite for another based on a list of prerequisites. This can be modeled as a directed graph, where each course is a node, and prerequisites are directed edges. The goal is to determine reachability between nodes, i.e., whether there exists a path f...
2
0
['Bit Manipulation', 'Shortest Path', 'Java']
0
course-schedule-iv
leetcodedaybyday - Beats 98.27% with C++ and Beats 86.50% with Python3
leetcodedaybyday-beats-9827-with-c-and-b-8ztl
IntuitionThe problem requires determining if one course is a prerequisite for another based on a list of prerequisites. By leveraging the transitive property of
tuanlong1106
NORMAL
2025-01-27T07:40:49.703597+00:00
2025-01-27T07:40:49.703597+00:00
77
false
# Intuition The problem requires determining if one course is a prerequisite for another based on a list of prerequisites. By leveraging the transitive property of prerequisites, we can process the input to deduce indirect relationships between courses. This can be achieved through a graph-based approach. # Approach 1...
2
0
['Graph', 'C++', 'Python3']
0
course-schedule-iv
DFS on Inverted/Reversed Graph O(N^2)
dfs-on-invertedreversed-graph-on2-by-uda-9z1r
IntuitionI thought of the inverted graph directly as the elements that comes further in the inverted graph are the dependencies to the elements that come earlie
uday_k02
NORMAL
2025-01-27T06:55:12.847501+00:00
2025-01-27T06:55:12.847501+00:00
6
false
# Intuition I thought of the **inverted graph** directly as the elements that comes further in the inverted graph are the dependencies to the elements that come earlier. Note: Inverted graph, not the actual graph. I reversed the directions of edges. Now, courses point to their prerequisites. If we start from the node...
2
0
['C++']
0
course-schedule-iv
Easy Java Solution
easy-java-solution-by-surajsharma15-im5v
IntuitionApproachBFSComplexity Time complexity: O(N+E) Space complexity: O(N+E) Code
surajsharma15
NORMAL
2025-01-27T04:30:59.886114+00:00
2025-01-27T04:30:59.886114+00:00
8
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach BFS # Complexity - Time complexity: O(N+E) - Space complexity: O(N+E) # Code ```java [] class Solution { public List<Boolean> checkIfPrerequisite(int numCourses, int[][] prerequisites, int[][] queries) { List<Boo...
2
0
['Java']
0
course-schedule-iv
100% (3ms) | Time: O(N^2 + Q) | Space: O(N^2)
100-26ms-time-on2-space-on2-by-rojas-6s9z
Table of ContentsFrom slowest to fastest: Memoized DFS Kahn's Algorithm Memoized DFS + Bit Manipulation Kahn's Algorithm + Bit Manipulation Appendix B
rojas
NORMAL
2025-01-27T03:28:08.038875+00:00
2025-01-28T16:44:16.851368+00:00
55
false
# Table of Contents From slowest to fastest: [toc] # Memoized DFS - Time complexity: $$O(N^3 + Q)$$ - Space complexity: $$O(N^2)$$ 15ms: [TypeScript](https://leetcode.com/problems/course-schedule-iv/submissions/1522435782/) 16ms: [JavaScript](https://leetcode.com/problems/course-schedule-iv/submissions/1522436347...
2
0
['Bit Manipulation', 'Depth-First Search', 'Graph', 'TypeScript', 'JavaScript']
0
course-schedule-iv
[Python3] Topological Sorting + Bit manipulation - O(n^2)
python3-topological-sorting-bit-manipula-zr9b
IntuitionGiven n courses where any two courses can be a preqrequisite of another, we a efficient way answer whether course a is a prerequisite of course b, or e
CabbageBoiii
NORMAL
2025-01-27T03:26:55.989703+00:00
2025-01-27T03:26:55.989703+00:00
226
false
# Intuition Given *n* courses where any two courses can be a preqrequisite of another, we a efficient way answer whether course *a* is a prerequisite of course *b*, or equivalently, *b* has *a* as a prerequisite. # Approach We can store the required information by in a 2D boolean array of size *N*, hasPrereq. Where h...
2
0
['Python3']
1
course-schedule-iv
C++ $O(N^2)$ time and space
on2-time-and-space-by-przemysaw2-e0jv
IntuitionUse bitset. For algorithms requiring O(N3) bitset is a great alternative, as it divides that number by 64. One might argue, that it is still O(N), but
przemysaw2
NORMAL
2025-01-27T02:37:04.377940+00:00
2025-01-27T02:37:24.431645+00:00
243
false
# Intuition Use bitset. For algorithms requiring $O(N^3)$ bitset is a great alternative, as it divides that number by 64. One might argue, that it is still $O(N)$, but bitset has a fixed size, independent of $N$. # Approach Modify the topological sort algorithm from editorial, but merge the reachable states in bitset ...
2
0
['C++']
2
course-schedule-iv
✅ Course Schedule IV | JS🔥 | beats 99%🚀 | 🚀highly optimised & easy to understand ✅
course-schedule-iv-js-beats-99-highly-op-fdwj
Intuition The problem can be efficiently solved using the Floyd-Warshall algorithm or a Depth-First Search (DFS). The goal is to determine if there is a direct
Naveen_sachan
NORMAL
2025-01-27T02:35:51.377267+00:00
2025-01-27T03:30:44.519079+00:00
153
false
# Intuition - The problem can be efficiently solved using the Floyd-Warshall algorithm or a Depth-First Search (DFS). The goal is to determine if there is a direct or indirect prerequisite relationship between courses. - Below is an optimized solution using the Floyd-Warshall algorithm, which computes the transitive cl...
2
0
['JavaScript']
1
course-schedule-iv
Building is reachable matrix with Floyd-Warshall Algorithm ✅✅
building-is-reachable-matrix-with-floyd-oeovb
IntuitionCreate a boolean matrix isReachable[numCourses][numCourses] where isReachable[i][j] is true if course i is a prerequisite of course j. Populate this ma
PavanKumarMeesala
NORMAL
2025-01-27T02:30:14.324664+00:00
2025-01-27T02:30:14.324664+00:00
107
false
![image.png](https://assets.leetcode.com/users/images/fbb5217a-8388-47a6-8b7b-7ef9b64c9766_1737944856.238559.png) # Intuition <!-- Describe your first thoughts on how to solve this problem. --> Create a `boolean` matrix `isReachable[numCourses][numCourses]` where `isReachable[i][j]` is `true` if course `i` is a prere...
2
0
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'Java']
1
course-schedule-iv
Go solution with the explanation
go-solution-with-the-explanation-by-alek-o8cs
IntuitionWhen faced with the problem of determining whether a course is a prerequisite of another, the most natural approach is to represent the relationships a
alekseiapa
NORMAL
2025-01-27T01:39:20.308747+00:00
2025-01-27T01:39:20.308747+00:00
151
false
# Intuition When faced with the problem of determining whether a course is a prerequisite of another, the most natural approach is to represent the relationships as a **directed graph**. Each course is a node, and each prerequisite relationship is a directed edge from one node to another. The key insight is that prereq...
2
0
['Go']
0
course-schedule-iv
C++ | BFS
c-bfs-by-ahmedsayed1-a5zt
Code
AhmedSayed1
NORMAL
2025-01-27T00:37:54.411477+00:00
2025-01-27T00:37:54.411477+00:00
367
false
# Code ```cpp []const int N=1e3; vector<int>adj[N]; class Solution { public: vector<bool> checkIfPrerequisite(int n, vector<vector<int>>& prerequisites, vector<vector<int>>& queries) { fill(adj,adj+n,vector<int>()); for(auto i:prerequisites) adj[i[1]].push_back(i[0]); vector<...
2
0
['Breadth-First Search', 'C++']
0
course-schedule-iv
Topo Sort || DFS || Hah Map || graph || C++
topo-sort-dfs-hah-map-graph-c-by-oreocra-gsp1
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
oreocraz_273
NORMAL
2024-08-03T12:04:16.805043+00:00
2024-08-03T12:04:16.805076+00:00
699
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)$$ --...
2
0
['Depth-First Search', 'Graph', 'Topological Sort', 'C++']
1
course-schedule-iv
[Python3] Very Simple and Intuitive BFS
python3-very-simple-and-intuitive-bfs-by-ibft
Intuition\nWe construct a graph and go through each query, checking if we can reach the ending node in that query. This solution is NOT optimal, but very straig
jojofang
NORMAL
2024-07-24T16:56:22.407321+00:00
2024-07-24T16:56:22.407354+00:00
322
false
# Intuition\nWe construct a graph and go through each query, checking if we can reach the ending node in that query. This solution is NOT optimal, but very straightforward and easy to implement.\n\n\n# Code\n```\nclass Solution:\n def checkIfPrerequisite(self, numCourses: int, prerequisites: List[List[int]], queries...
2
0
['Python3']
0
course-schedule-iv
C++ Solution with Best Memorization
c-solution-with-best-memorization-by-coo-jc3q
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
coolvaibhavsingh2001
NORMAL
2023-08-21T12:51:01.800418+00:00
2023-08-21T12:51:01.800437+00:00
955
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)$$ --...
2
0
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'C++']
0
course-schedule-iv
python3 recursion + memoization
python3-recursion-memoization-by-0icy-5nd3
\n\n# Code\n\nfrom collections import defaultdict\nclass Solution:\n def checkIfPrerequisite(self, numCourses: int, prerequisites: List[List[int]], queries:
0icy
NORMAL
2023-08-02T18:14:24.703273+00:00
2023-08-02T18:14:24.703302+00:00
205
false
\n\n# Code\n```\nfrom collections import defaultdict\nclass Solution:\n def checkIfPrerequisite(self, numCourses: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n\n @cache\n def check(n,target):\n nonlocal d\n if n == target:\n return ...
2
0
['Python3']
0
course-schedule-iv
[JavaScript] 1462. Course Schedule IV
javascript-1462-course-schedule-iv-by-pg-p2jk
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n\n\nif\n prev is connected to mid\n and\n mid is connected to next\n
pgmreddy
NORMAL
2023-07-27T18:27:14.460485+00:00
2023-07-27T18:29:29.298624+00:00
350
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n\n```\nif\n prev is connected to mid\n and\n mid is connected to next\n prev -> mid -> next\nthen\n connect prev to next\n prev -> next\n\nfor all mids\n for all prevs\n for all nexts\n ...
2
0
['JavaScript']
0
course-schedule-iv
Simple Solution DFS ( finding Indirectly connected edges ) , in Python
simple-solution-dfs-finding-indirectly-c-nm22
Code\n\nclass Solution:\n def checkIfPrerequisite(self, numCourses: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n\n
Bala_1543
NORMAL
2023-06-28T10:02:31.034169+00:00
2023-06-28T10:02:31.034200+00:00
136
false
# Code\n```\nclass Solution:\n def checkIfPrerequisite(self, numCourses: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n\n graph = {}\n for i in range(numCourses): graph[i] = []\n\n for u , v in prerequisites: \n graph[u] += [v]\n\n d = {} ...
2
0
['Python3']
1
course-schedule-iv
SIMPLE PYTHON SOLUTION
simple-python-solution-by-beneath_ocean-tbhp
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nTOPOLOGICAL SORT\n Describe your approach to solving the problem. \n\n# C
beneath_ocean
NORMAL
2023-01-05T04:27:37.283881+00:00
2023-01-05T04:27:37.283930+00:00
1,113
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTOPOLOGICAL SORT\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:$$O(V*ElogE)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(V*E)$$\n<!-- Add yo...
2
0
['Python3']
0
course-schedule-iv
A logical Solution using DSU
a-logical-solution-using-dsu-by-tiwaribh-cdyx
Approach:\nMake the adjacency list and union all the given pre-requisites,run the queries and for each query find the parent for both the nodes .\nCase -1: if t
tiwaribhai5146
NORMAL
2022-10-01T12:10:20.091401+00:00
2022-10-01T12:10:20.091438+00:00
260
false
Approach:\nMake the adjacency list and union all the given pre-requisites,run the queries and for each query find the parent for both the nodes .\n**Case -1**: if the parent of both nodes comes different then it is guranteed that they are never being dependent on each other\n**Case-2**: If the parent of both comes same...
2
0
['Union Find']
0
course-schedule-iv
Python3 | Solved Using Ancestors of every DAG Graph Node approach(Kahn's Algo BFS)
python3-solved-using-ancestors-of-every-k024w
```\nclass Solution:\n def checkIfPrerequisite(self, numCourses: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n #Let
JOON1234
NORMAL
2022-07-26T17:41:44.898219+00:00
2022-07-26T17:41:44.898273+00:00
295
false
```\nclass Solution:\n def checkIfPrerequisite(self, numCourses: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:\n #Let m = len(prereqs) and z = len(queries)\n #Time: O(m + n + n*n + z) -> O(n^2)\n #Space: O(n*n + n + n*n + n + z) -> O(n^2)\n \n \n ...
2
0
['Topological Sort', 'Queue', 'Python3']
0
course-schedule-iv
[C++] Floyd–Warshall Algorithm - Clean code with comments - O(n^3)
c-floyd-warshall-algorithm-clean-code-wi-loxf
\n // we can solve this by using these topo sort , dfs/bfs , floyd warshall time:O(n^3) Space: O(n^2)\n \nclass Solution {\npublic:\n vector checkI
ssbbdd11_11
NORMAL
2022-07-06T05:51:54.313374+00:00
2022-07-06T05:51:54.313416+00:00
351
false
\n // we can solve this by using these topo sort , dfs/bfs , floyd warshall time:O(n^3) Space: O(n^2)\n \nclass Solution {\npublic:\n vector<bool> checkIfPrerequisite(int numCourses, vector<vector<int>>& prerequisites, vector<vector<int>>& queries) \n{\n vector<vector<int>>distance(numCourses,vector<int...
2
0
['C']
0
course-schedule-iv
Course Schedule IV | Java | Floyd Warshalls Algo
course-schedule-iv-java-floyd-warshalls-yx1v1
Course Schedule IV\n\nclass Solution {\n public List<Boolean> checkIfPrerequisite(int numCourses, int[][] prerequisites, int[][] queries) {\n boolean
yash4900
NORMAL
2022-06-23T18:23:12.472710+00:00
2022-06-23T18:23:12.472760+00:00
217
false
#### **Course Schedule IV**\n```\nclass Solution {\n public List<Boolean> checkIfPrerequisite(int numCourses, int[][] prerequisites, int[][] queries) {\n boolean [][] graph = new boolean[numCourses][numCourses];\n \n for (int i=0; i<prerequisites.length; i++) {\n graph[prerequisites[i...
2
0
['Java']
0
course-schedule-iv
C++ using 2D array to store final values | O(E*N)
c-using-2d-array-to-store-final-values-o-70ts
Used topological sort for traversing from 0 prerequisite courses.\n\nUsed a 2D array called dp, dp[i][j] = true means i is a prerequisite of j.\n\nwhen even we
hareeshghk
NORMAL
2022-05-01T12:48:22.110049+00:00
2022-05-01T12:58:59.745849+00:00
151
false
Used topological sort for traversing from 0 prerequisite courses.\n\nUsed a 2D array called dp, dp[i][j] = true means i is a prerequisite of j.\n\nwhen even we remove an edge in topological sort we can add (i.e removing edge src->dst) dp[src][dst] as true and also add prerequisites of src as prerequisites of dst. Gene...
2
0
[]
0
course-schedule-iv
C++ || DFS || easy to understand
c-dfs-easy-to-understand-by-datnguyen2k3-2zh4
Up vote if it\'s helpful!\n\t\n\tclass Solution {\n\tpublic:\n\t\tvector> graph;\n\t\tvector visited;\n\t\tvector> check;\n\t\tvector ans;\n \n\t\tvoid dfs(i
datnguyen2k3
NORMAL
2022-02-04T15:31:00.789408+00:00
2022-02-04T15:34:18.704725+00:00
161
false
Up vote if it\'s helpful!\n\t\n\tclass Solution {\n\tpublic:\n\t\tvector<vector<int>> graph;\n\t\tvector<int> visited;\n\t\tvector<vector<int>> check;\n\t\tvector<bool> ans;\n \n\t\tvoid dfs(int cur, int k) {\n\t\t\tif(check[cur][k] != -1) // check cur->k == -1 is cur->k isn\'t exist\n\t\t\t\treturn;\n \n\t\t...
2
1
['Depth-First Search', 'C']
0
course-schedule-iv
[C++] DFS + DP
c-dfs-dp-by-thegateway-ahgb
Logic: We have to check in query(u,v) whether path exisits from u -> v, if it exists, then u is prerequisite of v, else it not a prerequisite of v.\n\nNeed of D
theGateway
NORMAL
2022-01-27T06:53:22.831151+00:00
2022-01-27T06:53:50.054854+00:00
329
false
**Logic:** We have to check in query(u,v) whether path exisits from u -> v, if it exists, then u is prerequisite of v, else it not a prerequisite of v.\n\n**Need of DP:** Memoization saves time by storing paths that exist and that don\'t exist, else the logic is simple dfs for all queries and checking whether path exis...
2
0
['Depth-First Search', 'Memoization', 'C', 'C++']
0
count-the-number-of-vowel-strings-in-range
Python 3 || 2 lines, sets || T/S: 97% / 97%
python-3-2-lines-sets-ts-97-97-by-spauld-dy7x
\nclass Solution:\n def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n\n vowels = set(\'aeiou\')\n \n return sum(
Spaulding_
NORMAL
2023-03-12T04:53:05.842167+00:00
2024-06-18T00:43:00.779302+00:00
1,563
false
```\nclass Solution:\n def vowelStrings(self, words: List[str], left: int, right: int) -> int:\n\n vowels = set(\'aeiou\')\n \n return sum({w[0],w[-1]}.issubset(vowels) for w in words[left:right+1])\n```\n[https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range/submissions/12918...
27
0
['Python3']
3
count-the-number-of-vowel-strings-in-range
Simple Condition || Very simple & Easy to Understand Solution
simple-condition-very-simple-easy-to-und-ws71
\n# Code\n\nclass Solution {\npublic:\n int isVowel(char w){\n return (w == \'a\' || w == \'e\' || w == \'i\' || w == \'o\' || w == \'u\');\n }\n
kreakEmp
NORMAL
2023-03-12T04:14:14.284823+00:00
2023-03-12T04:14:14.284866+00:00
4,060
false
\n# Code\n```\nclass Solution {\npublic:\n int isVowel(char w){\n return (w == \'a\' || w == \'e\' || w == \'i\' || w == \'o\' || w == \'u\');\n }\n int vowelStrings(vector<string>& words, int left, int right) {\n int count = 0;\n for(int i = left; i <= right; ++i) {\n if(isVowe...
17
0
['C++']
2
count-the-number-of-vowel-strings-in-range
2586: Solution with step by step explanation
2586-solution-with-step-by-step-explanat-y77x
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. Define a function vowelStrings that takes a list of strings words and
Marlen09
NORMAL
2023-03-12T04:04:33.627009+00:00
2023-03-12T04:04:33.627039+00:00
2,095
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Define a function vowelStrings that takes a list of strings words and two integers left and right as input, and returns an integer.\n2. Initialize a variable vowels to the string \'aeiouAEIOU\', which contains all the vow...
12
0
['Python', 'Python3']
3
count-the-number-of-vowel-strings-in-range
Short || Clean || Java
short-clean-java-by-himanshubhoir-0a6o
\njava []\nclass Solution {\n public int vowelStrings(String[] words, int left, int right) {\n int count = 0;\n String v = "aeiou";\n fo
HimanshuBhoir
NORMAL
2023-03-12T04:02:03.523955+00:00
2023-03-12T04:02:03.524064+00:00
1,049
false
\n```java []\nclass Solution {\n public int vowelStrings(String[] words, int left, int right) {\n int count = 0;\n String v = "aeiou";\n for(int i=left; i<=right; i++){\n if(v.contains(words[i].charAt(0)+"") && v.contains(words[i].charAt(words[i].length()-1)+"")) count++;\n }...
12
0
['Java']
2
count-the-number-of-vowel-strings-in-range
Simple java solution
simple-java-solution-by-siddhant_1602-gpkt
Complexity\n- Time complexity: O(n) where left <= n <= right\n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\n public int vowelStrings(String[] wor
Siddhant_1602
NORMAL
2023-03-12T04:00:39.731088+00:00
2023-03-12T04:04:44.532474+00:00
1,883
false
# Complexity\n- Time complexity: $$O(n)$$ where left <= n <= right\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\n public int vowelStrings(String[] words, int left, int right) {\n int m=0;\n for(int i=left;i<=right;i++)\n {\n char c=words[i].charAt(0);\n ...
9
0
['Java']
1