id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\nprivate:\n vector<int> makeVecNodes(const int s, vector<vector<int>>& edges, const int exclude) {\n vector<int> children;\n\n if (exclude<=-1) {\n for (int iEdge=0; iEdge<=edges.size()-1; iEdge++) {\n vector<int> edge_uv = edges[iEdge];\n\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n if (source == destination) return true;\n vector<bool> seen(n);\n vector<vector<int>> data(n);\n stack<int> st({source});\n\n for (vector<int> i : edges) {\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
1
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n if (source == destination) return true;\n vector<bool> seen(n);\n vector<vector<int>> data(n);\n stack<int> st({source});\n\n for (vector<int> i : edges) {\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n bool bfs(vector<vector<int>>& adj, int start, int des){\n vector<int> vis(adj.size(), 0);\n queue<int> q;\n q.push(start); vis[start] =1; \n while(!q.empty()){\n int node = q.front(); q.pop();\n for(auto e : adj[node]){\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\n void dfs(int node , vector<int> adj[] , vector<int> &visited)\n {\n visited[node] = 1;\n\n for(auto neigh : adj[node])\n {\n if(visited[neigh] == 0)\n {\n dfs(neigh , adj , visited);\n }\n }\n }\npublic:...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "#include <vector>\n#include <queue>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> BFS(int n, vector<vector<int>>& adjList, int s) {\n vector<int> ans;\n vector<bool> visited(n, false);\n queue<int> q;\n q.push(s);\n visited[s] = true;\n \n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n if (n <= 1 || source == destination){\n return true;\n }\n\n vector<int> adj[n];\n int e = edges.size();\n for (int i=0;i<e;i++){\n adj[...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n ios::sync_with_stdio(0);\n cin.tie(0); cout.tie(0);\n queue<int> q;\n vector<int> bfs;\n vector<bool> vis(n,0);\n vis[source] = 1;\n vector<vect...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n vector<int> adjacency_list[1000000];\n bool visited[1000000];\n int level[1000000];\n void bfs(int src) {\n queue<int> q;\n q.push(src);\n visited[src] = true;\n level[src] = 0;\n while (!q.empty()) {\n int parent = q.fro...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "// dfs\n\nclass Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n std::vector<int> adj[n];\n std::vector<bool> visited(n);\n\n for (const std::vector<int>& edge: edges) {\n adj[edge[0]].push_back(edge[1]);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n vector<int> adj[n];\n for(int i=0;i<edges.size();i++){\n adj[edges[i][0]].push_back(edg...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\nvector<int>v[2000005];\nbool vis[2000005];\nvoid dfs(int s)\n{\n vis[s]=true;\n for(auto child:v[s])\n {\n if(!vis[child])\n {\n dfs(child);\n }\n }\n}\n bool validPath(int n, vector<vector<int>>& edges, int s, int d) {\n mems...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n vector<int>v[2000005];\n bool vist[2000005];\n\n void dfs(int src)\n {\n vist[src]=true;\n for(auto child:v[src])\n {\n if(!vist[child])\n {\n dfs(child);\n }\n }\n }\n bool validPath(i...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n ios::sync_with_stdio(0);\n cin.tie(0); cout.tie(0);\n unordered_map<int, vector<int>> mp;\n \n for(vector<int> &vec : edges) {\n int u = vec[0];\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "\n//Using BFS\nclass Solution {\npublic: \n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n ios::sync_with_stdio(0);\n cin.tie(0); cout.tie(0);\n unordered_map<int, vector<int>> mp;\n \n for(vector<int> &vec : edges) {\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n\n //optimized \n\nbool validPath(int n, vector<vector<int>>& edges, int source, int destination){\n\n unordered_map<int,vector<int>> graph;\n \n for(int i=0; i<edges.size(); i++)\n {\n graph[edges[i][0]].push_back(edges[i][1]);\n graph[edges[i][1]].p...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n\n //optimized \n\nbool validPath(int n, vector<vector<int>>& edges, int source, int destination){\n\n unordered_map<int,vector<int>> graph;\n \n for(int i=0; i<edges.size(); i++)\n {\n graph[edges[i][0]].push_back(edges[i][1]);\n graph[edges[i][1]].p...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n bool dfs(int root,int &n,vector<vector<int>>&graph,int &dest,vector<int>&vis){\n vis[root] = 1;\n if(root == dest)return true;\n\n for(int child : graph[root]){\n if(!vis[child]){\n bool ans = dfs(child,n,graph,dest,vis);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int st, int end) {\n if(st == end) return true;\n\n vector<vector<int>> adj(n);\n for(auto&& i: edges)\n {\n adj[i[0]].push_back(i[1]);\n adj[i[1]].push_back(i[0]);\n }\...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n unordered_map<int,vector<int>> graph;\n int numNodes = edges.size();\n unordered_map<int,bool> seen;\n stack<int> dfss;\n\n for (int i = 0; i < numNodes; i++)...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n if (source == destination) return true;\n unordered_map<int,vector<int>>graph;\n unordered_set<int>seen;\n for (vector<int>& edge: edges){\n int from = ed...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\n public:\n\tstruct Graph\n\t{\n\t\tGraph(int numVertices)\n\t\t\t: m_adjacencyList(numVertices)\n\t\t\t, m_parents(numVertices)\n\t\t{\n\t\t\tfor(int i=0; i < numVertices; ++i)\n\t\t\t{\n\t\t\t\tm_parents[i] = i;\n\t\t\t}\n\t\t}\n\n\t\tvoid AddEdge(int source, int destination, bool bidire...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\n public:\n\tstruct Graph\n\t{\n\t\tGraph(int numVertices)\n\t\t\t: m_adjacencyList(numVertices)\n\t\t\t, m_parents(numVertices)\n\t\t{\n\t\t\tfor(int i=0; i < numVertices; ++i)\n\t\t\t{\n\t\t\t\tm_parents[i] = i;\n\t\t\t}\n\t\t}\n\n\t\tvoid AddEdge(int source, int destination, bool bidire...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n void dfs(vector<vector<int>>& graph, vector<bool>& isVisited, int src, int dest){\n if(isVisited[src]) return;\n isVisited[src]= true;\n for(int child: graph[src]){\n dfs(graph, isVisited, child, dest);\n if(isVisited[dest]) return;\...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n bool dfs(vector<vector<int>> &adj,vector<bool> &vis,int src,int dst)\n {\n if(src == dst) return true;\n if(vis[src] == true) return false;\n vis[src] = true;\n for(auto ch : adj[src])\n {\n if(!vis[ch])\n {\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n if(source == destination)\n return true;\n stack<int> stack;\n unordered_set<int> seen;\n stack.push(source);\n seen.insert(source);\n unordered...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
2
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int start, int end) {\n unordered_map<int, vector<int>> graph; \n for (auto& edge : edges) {\n graph[edge[0]].push_back(edge[1]); \n graph[edge[1]].push_back(edge[0]); \n }\n s...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n void dfs( vector<int> adj[], int source,vector<bool>&visited){\n visited[source] = 1;\n for(auto i:adj[source]){\n if(visited[i] == 0){\n dfs(adj,i,visited);\n }\n }\n }\n bool validPath(int n, vector<vector<int>...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n vector<bool>visited(n, false);\n map<int, vector<int>> adjList;\n \n for(auto edge : edges){\n adjList[edge[0]].push_back(edge[1]);\n adjList[e...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n vector<vector<int>> graph;\n for (int i=0;i<400000;i++){\n vector<int> temp;\n graph.push_back(temp);\n }\n for(int i=0;i<edges.size();i++){\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int src, int dest) {\n vector<vector<int>> g (n, vector<int> ());\n\n for(auto &e : edges) {\n g[e[0]].push_back(e[1]);\n g[e[1]].push_back(e[0]);\n }\n\n vector<bool> visit (n...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int src, int dest) {\n vector<int> adj[n];\n makeList(edges, adj);\n set<int> visit;\n return dfs(adj, src, dest, visit);\n }\n\n bool dfs(vector<int> adj[], int src, int dest, set<int>& visit...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n if (source == destination) return true;\n if (edges.empty()) return false;\n\n unordered_map<int, vector<int>> graph;\n for (auto& edge : edges) {\n graph...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n vector<vector<int>> arr(n, vector<int> (0));\n for(auto v : edges) arr[v[0]].push_back(v[1]), arr[v[1]].push_back(v[0]);\n vector<int> v(n);\n queue<int> que;\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n \n vector<vector<int>> g(n);\n for(auto e: edges){\n g[e[0]].push_back(e[1]);\n g[e[1]].push_back(e[0]);\n }\n \n vector<int> vis...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\n\n bool bfs(int n, unordered_map<int,vector<int>> mp,vector<bool> visited, int source, int destination)\n {\n queue<int> q;\n q.push(source);\n visited[source] = true;\n while(!q.empty())\n {\n int temp = q.front();\n if(temp=...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int src, int dest) {\n if(src == dest) return true;\n unordered_map<int,vector<int>>umap;\n for(auto i:edges){\n umap[i[0]].push_back(i[1]);\n umap[i[1]].push_back(i[0]);\n }\n...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n\n void dfs(int source , vector<int> adj[] , vector<int> &ans , vector<bool> &visited){\n visited[source] = true;\n\n ans.push_back(source);\n\n for(auto i : adj[source]){\n if(!visited[i]){\n dfs(i , adj , ans , visited);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n unordered_map<int,vector<int>>adj;\n int size=edges.size();\n unordered_map<int,bool>visited;\n for(int i=0;i<size;i++){\n int u=edges[i][0];\n int v=edges...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n unordered_map<int, vector<int>> adj(int n, vector<vector<int>>& edges) {\n unordered_map<int, vector<int>> ans;\n for (const auto& edge : edges) {\n ans[edge[0]].push_back(edge[1]);\n ans[edge[1]].push_back(edge[0]);\n }\n r...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n if(edges.size() == 0){\n if(source == destination) return true;\n else return false;\n }\n unordered_map<int,vector<int>> graph;\n for(int i = ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n unordered_map <int, vector<int>>graph = make_graph(edges);\n if (source == destination) return true;\n unordered_set<int> visited;\n return search_dest(graph, source...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n unordered_set<int>visited;\n vector<vector<int>> adj;\n bool dfs(int node, int end){\n if (node == end) return true;\n visited.insert(node);\n for(auto neighbour : adj[node]){\n if(!visited.count(neighbour)){\n bool resul...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n unordered_map<int,vector<int>> adj;\n\n for(vector<int> vec: edges){\n adj[vec[0]].push_back(vec[1]);\n adj[vec[1]].push_back(vec[0]);\n }\n\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n unordered_map<int,vector<int>> adj;\n\n for(vector<int> vec: edges){\n adj[vec[0]].push_back(vec[1]);\n adj[vec[1]].push_back(vec[0]);\n }\n\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "\nclass Graph\n{\nprivate:\n map<int, vector<int>> graph;\npublic:\n void AddElement(int first, int second)\n {\n graph[first].push_back(second);\n graph[second].push_back(first);\n }\n bool BreadthFirstSearch(int source , int destination)\n {\n unordered_map<int, int...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n vector<vector<int>> adj(n, vector<int>());\n\n for (vector<int> edge : edges) {\n adj[edge[0]].push_back(edge[1]);\n adj[edge[1]].push_back(edge[0]);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int start, int end) {\n unordered_map<int,vector<int>> adj;\n\n for(auto x : edges) {\n int u = x[0];\n int v = x[1];\n\n adj[u].push_back(v);\n adj[v].push_back(u);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n unordered_map<int,list<int>> graph;\n for(auto edge : edges){\n graph[edge[0]].push_back(edge[1]);\n graph[edge[1]].push_back(edge[0]);\n } \n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n unordered_map<int ,vector<int>> umap;\n for(auto x: edges)\n {\n vector<int> temp=x;\n int u=temp[0];\n int v=temp[1];\n\n umap[...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n\n void dfs(vector<vector<int>> &adj, int n,int sv, vector<bool> &visited){\n if(sv >= n || visited[sv]) return;\n\n visited[sv] = true;\n\n vector<int> list = adj[sv];\n\n for(int i=0;i<list.size();i++){\n if(!visited[list[i]]){\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n int find(int x, vector<int> &parent) {\n if(x==parent[x])\n return x;\n return parent[x]=find(parent[x], parent);\n }\n\n void unionFind(int x, int y, vector<int>&parent, vector<int>&rank) {\n int px=find(x, parent);\n int py=find(...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int src, int dst) {\n\n if(src == dst) return true;\n \n unordered_map<int, vector<int>> mp;\n\n for(auto edge : edges){\n mp[edge[0]].push_back(edge[1]);\n mp[edge[1]].push_ba...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n void createGraph( const vector<vector<int>>& edges,\n vector<list<int>>& graph) {\n for( const auto& edge : edges ) {\n graph[ edge[ 0 ] ].push_back( edge[ 1 ] );\n graph[ edge[ 1 ] ].push_back( edge[ 0 ] );\n }\n }\...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool dfs(int u,int v,vector<list<int>>&adj,vector<bool>&vis)\n {\n if(u==v)\n return true;\n vis[u]=true;\n for(auto it:adj[u]){\n if(vis[it]!=true)\n {\n bool ans= dfs(it,v,adj,vis);\n if(ans)\n {\n return ans;\n }\n }\n }\...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\nbool checkPath(vector<list<int>> &adj , int node , vector<bool> &vis , int dest){\n vis[node] = true;\n if(node==dest){\n return true;\n }\n for(auto i : adj[node]){\n if(!vis[i]){\n bool check = checkPath(adj,i,vis,dest);\n if(chec...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\nbool checkPath(vector<list<int>> &adj , int node , vector<bool> &vis , int dest){\n vis[node] = true;\n if(node==dest){\n return true;\n }\n for(auto i : adj[node]){\n if(!vis[i]){\n bool check = checkPath(adj,i,vis,dest);\n if(chec...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n vector<list<int> >v;\n unordered_set<int> vis;\n void addedge(int src,int dst){\n v[src].push_back(dst);\n v[dst].push_back(src);\n }\n bool path(int src,int dst){\n if(src==dst){\n return true;\n }\n vis.insert(src);\...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n unordered_map<int, vector<int>> umap;\n vector<bool> visited;\n\n bool dfs(int node, int dest){\n\n if(visited[node]){\n return false;\n }\n\n visited[node] = true;\n\n bool result = false;\n if(node == dest){\n r...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "\nclass Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n // base case\n if(edges.size() == 0){\n return true;\n }\n \n // step 1 : creating the adjustant list from edges\n unordered_map<int,list<...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n void bfs(int node,unordered_map<int,bool> &vis,unordered_map<int,list<int>> &adj){\n queue<int> q;\n q.push(node);\n vis[node] = 1;\n while(!q.empty()){\n int front = q.front();\n q.pop();\n for(auto i:adj[front]){\...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool dfs(auto &egress, int s, int d) {\n if (s == d) {\n return true;\n }\n\n while (!egress[s].empty()) {\n int node = *egress[s].begin();\n egress[s].erase(node);\n egress[node].erase(s);\n\n if (dfs(eg...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool dfs(vector<set<int>> &egress, int s, int d) {\n if (s == d) {\n return true;\n }\n\n while (!egress[s].empty()) {\n int node = *egress[s].begin();\n egress[s].erase(node);\n egress[node].erase(s);\n\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n void bfs(vector<vector<int>>adjList, vector<bool>&visited, int s, int d) {\n visited[s]=true;\n queue<int>q;\n q.push(s);\n while(!q.empty()) {\n int curr = q.front();\n q.pop();\n for(auto t: adjList[curr]) {\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n unordered_map<int,list<int>> adj(n);\n for(int i=0; i<edges.size(); i++){\n int u=edges[i][0];\n int v=edges[i][1];\n\n adj[u].push_back(v);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\n void dfs(int src, int dest, vector<bool>& visited, vector<list<int>>& graph) {\n if (src == dest) {\n return;\n }\n\n for (auto i = graph[src].begin(); i != graph[src].end(); ++i) {\n if (!visited[*i]) {\n visited[*i] = true;\n...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n\n map<int, list<int>>adj;\n\n for(auto edge: edges){\n int u=edge[0];\n int v=edge[1];\n adj[u].push_back(v);\n adj[v].push_back(u);\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution\n{\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int src, int dst) \n { \n unordered_map<int,vector<int>> adj;\n for(auto edge:edges)\n {\n adj[edge[0]].push_back(edge[1]);\n adj[edge[1]].push_back(edge[0]);\n }\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution\n{\npublic:\n bool validPath(int n, vector<vector<int>>& edges, int src, int dst) \n { \n unordered_map<int,vector<int>> adj;\n for(auto edge:edges)\n {\n adj[edge[0]].push_back(edge[1]);\n adj[edge[1]].push_back(edge[0]);\n }\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n bool dfs(unordered_map<int, vector<int>>& adjList, int source, int destination, unordered_set<int>& visited){\n if(source == destination) return true;\n visited.insert(source);\n\n for(auto& itr : adjList[source]){\n if(visited.find(itr) == visited.end()...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <unordered_map>\n#include <unordered_set>\nusing namespace std;\nclass Solution {\npublic:\n // Edges: n = 6, edges = [[0,1],[0,2],[3,5],[5,4],[4,3]], source = 0, destination = 5\n bool validPath(int n, vector<vector<int>>& edges,...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n int flag = 0;\n unordered_map<int, vector<int>> mp;\n void findpath(int s, int dest, vector<int>& visited) {\n visited[s] = 1;\n if (flag == 1) {\n return;\n }\n if (s == dest) {\n flag = 1;\n return;\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n int flag = 0;\n unordered_map<int, vector<int>> mp;\n void findpath(int s, int dest, vector<int>& visited) {\n visited[s] = 1;\n if (flag == 1) {\n return;\n }\n if (s == dest) {\n flag = 1;\n return;\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "class Solution {\npublic:\n unordered_map<int, vector<int>> adj;\n unordered_set<int> visited;\n \n bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {\n for (const auto& edge : edges) {\n int from = edge[0];\n int to = edge[1];\n ...
2,121
<p>There is a <strong>bi-directional</strong> graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub...
3
{ "code": "void fastInpOut(){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n}\nclass Solution {\npublic:\n bool dfs(int source,int dest,unordered_map<int,vector<int>>&graph,vector<bool>&vis){\n if(source == dest){\n return true;\n }\n i...
81
<p>There is an integer array <code>nums</code> sorted in non-decreasing order (not necessarily with <strong>distinct</strong> values).</p> <p>Before being passed to your function, <code>nums</code> is <strong>rotated</strong> at an unknown pivot index <code>k</code> (<code>0 &lt;= k &lt; nums.length</code>) such that ...
0
{ "code": "class Solution {\npublic:\n bool search(vector<int>& nums, int target) \n {\n int size = nums.size();\n int start = 0;\n int end = size - 1;\n\n while (start <= end)\n {\n int mid = start + (end - start) / 2;\n \n if (nums[mid] == ta...
81
<p>There is an integer array <code>nums</code> sorted in non-decreasing order (not necessarily with <strong>distinct</strong> values).</p> <p>Before being passed to your function, <code>nums</code> is <strong>rotated</strong> at an unknown pivot index <code>k</code> (<code>0 &lt;= k &lt; nums.length</code>) such that ...
0
{ "code": "class Solution {\npublic:\n bool bs(vector<int>& nums, int target,int low,int high){\n if(low>high) return false;\n while(low<=high){\n int mid=low + (high-low)/2;\n if(nums[mid]==target) return true;\n if(nums[mid]==nums[low] && nums[mid]==nums[high]){\n lo...
81
<p>There is an integer array <code>nums</code> sorted in non-decreasing order (not necessarily with <strong>distinct</strong> values).</p> <p>Before being passed to your function, <code>nums</code> is <strong>rotated</strong> at an unknown pivot index <code>k</code> (<code>0 &lt;= k &lt; nums.length</code>) such that ...
0
{ "code": "class Solution {\npublic:\n bool search(vector<int>& nums, int target) {\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]==target)\n return true;\n }\n return false;\n }\n};", "memory": "16400" }
81
<p>There is an integer array <code>nums</code> sorted in non-decreasing order (not necessarily with <strong>distinct</strong> values).</p> <p>Before being passed to your function, <code>nums</code> is <strong>rotated</strong> at an unknown pivot index <code>k</code> (<code>0 &lt;= k &lt; nums.length</code>) such that ...
0
{ "code": " class Solution {\npublic:\n bool search(vector<int>& nums, int target) {\n int low=0,high=nums.size()-1;\n while(low<=high){\n int mid=low+(high-low)/2;\n if(nums[mid]==target){\n return true;\n }\n if(nums[low]==nums[mid] && num...
81
<p>There is an integer array <code>nums</code> sorted in non-decreasing order (not necessarily with <strong>distinct</strong> values).</p> <p>Before being passed to your function, <code>nums</code> is <strong>rotated</strong> at an unknown pivot index <code>k</code> (<code>0 &lt;= k &lt; nums.length</code>) such that ...
0
{ "code": "class Solution {\npublic:\n bool search(vector<int>& nums, int target) {\n int n=nums.size();\n int low=0, high=n-1;\n while(low<=high){\n int mid=(low+high)/2;\n if(nums[mid]==target)\n return 1;\n else if(nums[low]==nums[mid] && nums...
81
<p>There is an integer array <code>nums</code> sorted in non-decreasing order (not necessarily with <strong>distinct</strong> values).</p> <p>Before being passed to your function, <code>nums</code> is <strong>rotated</strong> at an unknown pivot index <code>k</code> (<code>0 &lt;= k &lt; nums.length</code>) such that ...
0
{ "code": "class Solution {\npublic:\n bool search(vector<int>& nums, int target) {\n int start = 0;\n int end = nums.size() - 1;\n while(start <= end)\n {\n int mid = (start + end) /2;\n if(nums[mid] == target)\n {\n return true;\n ...
81
<p>There is an integer array <code>nums</code> sorted in non-decreasing order (not necessarily with <strong>distinct</strong> values).</p> <p>Before being passed to your function, <code>nums</code> is <strong>rotated</strong> at an unknown pivot index <code>k</code> (<code>0 &lt;= k &lt; nums.length</code>) such that ...
0
{ "code": "\nclass Solution {\npublic:\n int search(vector<int>& nums, int target) {\n long long int low=0;\n long long int high=nums.size()-1;\n int mid;\n while(low<=high)\n {\n mid=(low+high)/2;\n if(nums[mid]==target)\n return true;\n ...
81
<p>There is an integer array <code>nums</code> sorted in non-decreasing order (not necessarily with <strong>distinct</strong> values).</p> <p>Before being passed to your function, <code>nums</code> is <strong>rotated</strong> at an unknown pivot index <code>k</code> (<code>0 &lt;= k &lt; nums.length</code>) such that ...
0
{ "code": "class Solution {\npublic:\n bool search(vector<int>& nums, int target) {\n int low=0;\n int high=nums.size()-1;\n while(low<=high){\n int mid=(low+high)>>1;\n if(nums[mid]==target){\n return true;\n }\n while(low<high && num...
81
<p>There is an integer array <code>nums</code> sorted in non-decreasing order (not necessarily with <strong>distinct</strong> values).</p> <p>Before being passed to your function, <code>nums</code> is <strong>rotated</strong> at an unknown pivot index <code>k</code> (<code>0 &lt;= k &lt; nums.length</code>) such that ...
0
{ "code": "class Solution {\npublic:\n bool search(vector<int>& arr, int target) {\n int low = 0;\n int high = arr.size()-1;\n\n while(low <= high) {\n int mid = low+(high-low)/2;\n if(arr[mid] == target) return true;\n if((arr[mid] == arr[low]) && (arr[mid] ==...
81
<p>There is an integer array <code>nums</code> sorted in non-decreasing order (not necessarily with <strong>distinct</strong> values).</p> <p>Before being passed to your function, <code>nums</code> is <strong>rotated</strong> at an unknown pivot index <code>k</code> (<code>0 &lt;= k &lt; nums.length</code>) such that ...
0
{ "code": "class Solution {\npublic:\n int findPivotElement(vector<int> nums) {\n int l = 0;\n int r = nums.size()-1;\n int n = nums.size();\n while(l<=r) {\n int mid = l + (r-l)/2;\n if (nums[mid]>nums[n-1]) {\n l = mid+1;\n } else {\n ...
81
<p>There is an integer array <code>nums</code> sorted in non-decreasing order (not necessarily with <strong>distinct</strong> values).</p> <p>Before being passed to your function, <code>nums</code> is <strong>rotated</strong> at an unknown pivot index <code>k</code> (<code>0 &lt;= k &lt; nums.length</code>) such that ...
0
{ "code": "class Solution {\npublic:\n bool search(vector<int>& nums, int target) {\n int l = 0;\n int r = nums.size() - 1;\n \n while (l <= r) {\n int mid = l + (r - l) / 2; // Safe calculation of mid\n \n if (nums[mid] == target) {\n re...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
0
{ "code": "class Solution {\npublic:\n ListNode* deleteDuplicates(ListNode* head) {\n if (!head || !head->next) return head;\n \n ListNode* dummy = new ListNode(0, head);\n ListNode* prev = dummy;\n ListNode* curr = head;\n\n while (curr) {\n while (curr->next &...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
0
{ "code": "class Solution {\npublic:\n ListNode* deleteDuplicates(ListNode* head) {\n if (!head || !head->next) return head;\n \n ListNode* dummy = new ListNode(0, head);\n ListNode* prev = dummy;\n ListNode* curr = head;\n\n while (curr) {\n while (curr->next &...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
1
{ "code": "class Solution {\npublic:\n ListNode* deleteDuplicates(ListNode* head) {\n // Handle edge cases where the list is empty or has only one node\n if (head == NULL || head->next == NULL) {\n return head; // No duplicates to remove, return the list as is\n }\n\n // Cre...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
1
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
2
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
2
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\nprivate:\...
82
<p>Given the <code>head</code> of a sorted linked list, <em>delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list</em>. Return <em>the linked list <strong>sorted</strong> as well</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="htt...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...