id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n\n class Node{\n public:\n int cp;\n int cc;\n int cl;\n int n;\n Node(int cp_, int cc_, int cl_, int n_){\n cp = cp_;\n cc = cc_;\n cl = cl_;\n n = n_;\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<vector<int>> red(n, vector<int>()), blue(n, vector<int>());\n for (auto& edges: redEdges){\n red[edges[0]].push_back(edges[1]);\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<vector<int>> red(n, vector<int>()), blue(n, vector<int>());\n for (auto& edges: redEdges){\n red[edges[0]].push_back(edges[1]);\n ...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<vector<int>> redGraph(n), blueGraph(n);\n\n for(auto edge : redEdges){\n redGraph[edge[0]].push_back(edge[1]);\n }\n fo...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n unordered_map<int, vector<int>> red;\n unordered_map<int, vector<int>> blue;\n for (auto edge : redEdges) {\n red[edge[0]].push_back(...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n unordered_map<int, vector<int>> red;\n unordered_map<int, vector<int>> blue;\n for (auto edge : redEdges) {\n red[edge[0]].push_back(...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<vector<pair<int,int>>> adj(n);\n queue<pair<pair<int,int>,int>> q;\n vector<int> dist(n,1e9);\n vector<vector<vector<int>>> vis(n,...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& red, vector<vector<int>>& blue) {\n vector<pair<int,int>> g[n];\n for(auto ele : red){\n g[ele[0]].push_back({ele[1],0});\n }\n for(auto ele : blue){\n g[ele[0]]...
1,229
<p>You are given an integer <code>n</code>, the number of nodes in a directed graph where the nodes are labeled from <code>0</code> to <code>n - 1</code>. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.</p> <p>You are given two arrays <code>redEdges</code> and <code>blueEdges<...
3
{ "code": "class Solution {\npublic:\n vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {\n vector<vector<vector<int>>> adj(n);\n for(int i=0;i<redEdges.size();i++){\n adj[redEdges[i][0]].push_back({redEdges[i][1],0});\n }\n\...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
0
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n set<char> characters;\n for(auto i:original){\n characters.insert(i);\n }\n for(auto i:changed){\n chara...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
0
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n set<char> characters;\n for(auto i:original){\n characters.insert(i);\n }\n for(auto i:changed){\n chara...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
1
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<vector<int>>adjMatrix(26,vector<int>(26,1e9));\n for(int i=0;i<original.size();i++){\n adjMatrix[original[i]-'a'][changed[...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
1
{ "code": "class Solution {\n vector<vector<int>> floydWarshal(vector<char>& original, vector<char>& changed, vector<int>& cost){\n vector<vector<int>> dist(26, vector<int>(26, INT_MAX));\n for(int i = 0; i < 26; i++) dist[i][i] = 0;\n for (int i = 0; i < original.size(); i++) {\n i...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
1
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<int> v[26];\n vector<bool> checked(26,false);\n const int Inf = 0x3f3f3f3f;\n vector<vector<int>> edgeCost(26, vector<i...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
1
{ "code": "class Solution {\nprivate:\n // long long solve(int s, int t, int n, vector<vector<int>>& adjMat) {\n // priority_queue<pair<int, int>, vector<pair<int, int>>,\n // greater<pair<int, int>>>\n // pq;\n // vector<long long> dis(26, INT_MAX);\n\n // pq....
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
1
{ "code": "class Solution {\npublic:\n vector<vector<long long>> charmap(vector<char> &o, vector<char> &c, vector<int> &w){\n vector<vector<long long>> adj(26, vector<long long>(26, 1e16));\n for(int i=0; i<o.size(); i++){\n adj[o[i]-'a'][c[i]-'a'] = min(adj[o[i]-'a'][c[i]-'a'], (long long...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
1
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n long long ans = 0;\n int n = original.size();\n\n vector<vector<long long>> adj(26,vector<long long>(26,1e9));\n for(int i=0;i...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution\n{\n class FloydWarshall\n {\n private:\n vector<vector<int>> distance;\n vector<vector<int>> next;\n\n int nrVertex;\n\n public:\n FloydWarshall(int n)\n {\n nrVertex = n;\n\n distance.resize(n);\n next.resize(n...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n long long result(0);\n long long const INF = 1e13+7; \n vector<vector<long long>> distance(30,vector<long long>(30,INF));\n fo...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<vector<int>> mat(26);\n for(int i=0;i<26;i++){\n for(int j=0;j<26;j++){\n mat[i].push_back(INT_MAX);\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\n #define ll long long \npublic:\n void floydwarshall(vector<vector<ll>>& adj, string t, vector<char>& o, vector<char>& c, vector<int>& cost) {\n for (int i = 0; i < o.size(); i++) {\n int sour = o[i] - 'a';\n int tar = c[i] - 'a';\n adj[sour][...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n void printMatirx(vector<vector<int>> matrix){\n for(auto itr :matrix){\n for(int i :itr)\n cout<<i<<\" \";\n cout<<endl;\n }\n }\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& ch...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n unordered_map<char, int> c2n; // char to num\n/* for(char c : source) {\n if(c2n.count(c) == 0) {\n c2n[c] = c2n....
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n void applyFloyed(vector<vector<long long>>& minCost) {\n int n = 26;\n for (int k = 0; k < n; k++) {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (minCost[i][k] != 1e9 && minCost[k][j] != 1e9) ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n int dis[26][26];\n void dijkstra(int node,vector<pair<int,int>> adj[])\n {\n priority_queue<pair<int,int>,vector<pair<int,int>>, greater<pair<int,int>>> pq;\n pq.push({0,node});\n dis[node][node]=0;\n while(!pq.empty())\n {\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\n \n inline void updateCost(int &currCost,int &newCost){\n if(currCost == -1 || newCost < currCost) currCost = newCost;\n }\n \npublic:\n long long minimumCost(string source, string target, vector<char>& org, vector<char>& chg, vector<int>& cost) {\n \n int ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\n size_t toIndex(char ch) {\n return ch - 'a';\n }\n void fillMinCostsList(char sourceChar,\n const std::vector<std::vector<std::pair<char, int>>>& adjList,\n std::vector<int>& outMinCostsList) {\n std::priority_queue<std::pair<int, char>,\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n int m = original.size();\n vector<vector<int>> edges(m);\n for (int i=0; i<m; i++){\n edges[i] = {original[i] - 'a', chang...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n ll mindist(int src,int target,vector<vector<pair<int,int>>>&adj,vector<vector<int>>&dp){\n if(dp[src][target]!=1e9)return dp[src][target];\n vector<int>dist(26,1e9);\n dp[src][src]=0;\n priority_queue<pair<int,int>>pq;\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<pair<int,int>> adj[26];\n vector<vector<long long>> v(26,vector<long long>(26,1e18));\n for(int i=0;i<original.size();i++){\n...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n void Dijasktra(vector<vector<ll>> &adjMatrix,char source,unordered_map<char,vector<pair<char,int>>> &adj)\n {\n priority_queue<pair<int,char> , vector<pair<int,char>> , greater<pair<int,char>> > pq;// {distance , node}-->min_priority queue\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\nprivate:\n //very large value\n const long long inf = LONG_MAX;\n void dijstra(vector<vector<pair<long long, int>>>& graph, vector<long long> &shortestDistance, int source){\n //Travesal Varaibles\n long long currWeight;\n int currNode;\n int childNode...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n map<long long,vector<pair<long long,long long>>> adjacencyList;\n for(int i=0;i<original.size();i++)\n {\n long long origi...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& o, vector<char>& c, vector<int>& cost) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n vector<vector<int>>adj;\n for(int i=0;i<o.size();i++){\n adj.push_back({o[i]-'a',c[...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n int n = 26;\n\n vector<vector<int>> edges;\n\n for(int i = 0 ; i < original.size() ; i++){\n edges.push_back({original[i...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n vector<long long> dijktras(char src, unordered_map<char, list<pair<char, int>>> &adjList) {\n priority_queue<pair<int, char>> pq; // {dist, node}\n pq.push({0, src});\n vector<long long> distance(26, INT_MAX);\n\n distance[src - 97] = 0;\n\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n vector<long long> dijktras(char src, unordered_map<char, list<pair<char, int>>> &adjList) {\n priority_queue<pair<int, char>> pq; // {dist, node}\n pq.push({0, src});\n vector<long long> distance(26, INT_MAX);\n\n distance[src - 97] = 0;\n\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n vector<long long>dijkstra(int src,const vector<vector<pair<int,int>>>& adj){\n vector<long long>minCost(26,-1);\n priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>>pq;\n pq.push({0,src});\n while(!pq.empty(...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution\n{\npublic:\n vector<long long> solve(map<long long, vector<pair<long long, long long>>> &adjList, long long vertices, long long source)\n {\n priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n vector<pair<int, int>> adj[30];\n vector<long long> ans[30];\n\n vector<long long> solve(int i) {\n queue<pair<int, long long>> q;\n q.push({i, 0});\n vector<long long> vis(30, 1e13);\n vis[i]=0;\n\n while (q.size()) {\n for...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n int no = original.size(),n = source.size();\n vector<vector<int>> v(26,vector<int>(26,-1));\n for(int i=0;i<no;i++){\n int...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n #define ll long long \n #define P pair<ll, ll>\n\n vector<P> edges[26]; // Fix the size to 26 for lowercase alphabet indices\n ll inf = 1e13;\n\n vector<ll> dijstra(ll src, ll n) {\n vector<ll> dists(26, inf...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n unordered_map<char, vector<char>>edges;\n //unordered_map<pair<char,char>, int>lowest_cost;\n //unordered_map<pair<char, char>, bool>...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "auto init = []() { \n ios::sync_with_stdio(false); \n cin.tie(nullptr); \n cout.tie(nullptr); \n return 'c'; \n}();\nstruct pair_hash {\n template <class T1, class T2>\n std::size_t operator() (const std::pair<T1, T2>& p) const {\n auto hash1 = std::hash<T1>{}(p.first);...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "#define INF INT_MAX\n#define ll long long\n#define pp pair<ll,ll>\nclass Solution {\npublic:\n vector<list<pair<int,int>>> graph;\n unordered_map<ll,ll> dijkstra(int src){\n priority_queue<pp,vector<pp>, greater<pp>> pq;\n unordered_map<ll,ll> mp;\n set<int> vis;\n for(int...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<vector<long long>> dists(26, vector<long long>(26, INT_MAX));\n for (int i = 0; i < 26; i++) {\n dists[i][i] = 0;\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n vector<long long> dij(vector<vector<vector<int>>> &adj,int s)\n {\n int n=26;\n vector<long long> ans(n,INT_MAX);\n ans[s]=0;\n priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>> p;\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long d[27][27];\n vector<vector<long long>> a;\n void dijkstra(int start){\n for(int i = 0; i<26; i++) d[start][i] = -1;\n d[start][start] = 0;\n priority_queue<pair<long long,int>, vector<pair<long long,int>>, greater<pair<long long,int>>> q;\...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n void dijkstra(int start, vector<int> &visited, vector<int> &distance, vector<pair<int, int>> adj[])\n{\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; // min heap\n pq.push({0, start});\n\n while (!pq.empty())\n {\n pai...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<vector<long long>>vec(27, vector<long long>(27, -1));\n vector<vector<pair<long long,long long>>>g;\n g.resize(27);\n f...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n unordered_map<char, vector<pair<char, int>>>adj;\n\n for (int i = 0; i < original.size(); i++) {\n adj[original[i]].emplace_back(...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "// class Solution {\n// using Graph = unordered_map<char, vector<pair<int, char>>>;\n// public:\n// long long minimumCost(string source, string target, vector<char> &original,\n// vector<char> &changed, vector<int> &cost) {\n// Graph graph;\n// for (int i =...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution\n{\nprivate:\n const long long int INF = 1e12;\n // Dijkstra's algorithm to find the shortest path from 'start' to all other nodes\n void dijkstra(char start, unordered_map<char, vector<pair<char, long long int>>> &adj, unordered_map<char, unordered_map<char, long long int>> &helper...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n\n void floyd_warshall(vector<vector<long long>>& shortest_path_matrix){\n\n for(int k=0; k<26; k++){\n for(int i=0; i<26; i++){\n for(int j=0; j<26; j++){\n shortest_path_matrix[i][j] = min(shortest_path_matrix[i][j], shorte...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& orig, \n vector<char>& chan, vector<int>& cost) {\n map<int,vector<int>> v; //mappings of all starting and ending points\n int sz = target.size();\n for(int i=0; i<sz; i++){\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<vector<pair<int,int>>> graph(26);\n for(int i = 0; i < original.size(); i++){\n int src = original[i] - 'a';\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n void minCostDeikstra(char cValue, vector< vector<long long> >& pairs, vector<vector<long long>>& changeMap) {\n\t\tpriority_queue< pair<long long, char>, vector<pair<long long, char>>, greater<pair<long long, char>>> queue;\n\n\t\tqueue.push(pair<long long, char>(0, cValue));...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n vector<long long int> solve(vector<pair<int, int>> adj[], int src) {\n vector<long long int> dis(26, 1e12);\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;\n q.push({src, 0});\n dis[src] = 0;\n while(!q.e...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "#define mod 1000000007\nclass Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n //assume all characters as nodes; cost v given h ek node se dusre p jane ki; \n //ab dekho source m kis kisko badaln...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n vector<int> dij(vector<vector<int>>adj[],int src){\n vector<int>dist(26,1e9);\n priority_queue <vector<int>, vector<vector<int>>, greater<vector<int>> > pq; \n pq.push({0,src});\n dist[src]=0;\n while(!pq.empty()){\n auto vec=pq.t...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n vector<long long int> solve(vector<pair<int, int>> adj[], int src) {\n vector<long long int> dis(26, 1e12);\n queue<pair<int, int>> q;\n q.push({src, 0});\n dis[src] = 0;\n while(!q.empty()) {\n auto it = q.front();\n q...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "\nclass ele {\n public: \n int w, current;\n bool visited;\n ele() {\n current = -1;\n w = INT_MAX;\n visited = false;\n }\n};\n\nele find_min( vector<ele>& ans, int v )\n{\n ele x;\n for(int i=0; i<v; i++) {\n if( ans[i].visited ) \n continue;\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "#include <vector>\n#include <queue>\n#include <string>\n#include <climits>\n\nusing namespace std;\n\nclass Solution {\nprivate:\n void dfs(int node, vector<long long>& dist, vector<vector<vector<int>>>& adj) {\n priority_queue<vector<long long>, vector<vector<long long>>, greater<vector<long lon...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution\n{\n int n, nb;\n string source, target;\n map<char, int> ids;\n vector<map<int, long long>> graph;\n vector<long long> cache;\n long long solve(int pos)\n {\n if (pos == n)\n return 0;\n if (cache[pos] != -2)\n return cache[pos];\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n int n = original.size();\n\n map<char,map<char,long long>> adj;\n for(int i=0;i<n;i++) {\n if(adj[original[i]][changed[i]]...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\nprivate:\n int NO_EDGE = INT_MAX;\n\n void dijkstra(const int s, const vector<vector<long long>>& graph, vector<vector<long long>>& lookupTable) {\n auto myComp = [](pair<int, int> p1, pair<int, int> p2) {\n return p1.second > p2.second;\n };\n priori...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n \n long long costi(char source, vector<char>target, unordered_map<char, vector<pair<char, int>>>& graph){\n priority_queue<pair<int, char>, vector<pair<int, char>>, greater<pair<int, char>>> pq; \n pq.push({0, source});\n\n unordered_set<char> visited...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "const static auto speedup = [] () {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n \n return 0;\n} ();\n\nclass Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& c...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n \nlong long getCost(vector<vector<pair<char, int>>>& graph, int start, int end) {\n // Initialize distances with infinity\n vector<long long> dist(26, LLONG_MAX);\n dist[start] = 0;\n\n // Queue for BFS\n priority_queue<int> q;\n q.push(start);\n\n while ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "#include <vector>\n#include <string>\n#include <unordered_map>\n#include <algorithm>\n#include <climits>\n\nusing namespace std;\n\nclass Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n int n = origina...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n \n vector<vector<long long>> charMap(26,vector<long long>(26,LLONG_MAX));\n unordered_map<char,vector<pair<char,int>>> adjMap(26);\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "template<typename U, typename T>\nU to( const T& src )\n{\n\tconst U result = static_cast<const U>( src );\n\tassert( static_cast<const T>( result ) == src );\n\tassert( src * 2 == src * 2 );\n\treturn result;\n}\n\nclass SquareMatrix {\npublic:\n\tSquareMatrix( int size, int defaultValue = 0 );\n\n\tSquar...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\n vector<vector<int>> dis;\n unordered_map<int,vector<pair<int,int>>> mp;\npublic:\n long long minimumCost(string s, string tr, vector<char>& o, vector<char>& c, vector<int>& ct) {\n vector<vector<int>> temp(26,vector<int>(26,1e9));\n dis=temp;\n for(int i=0;i...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\ntypedef pair<int, int> eng;\n\nvoid dijkstra(int src,array<vector<eng>, 26> &adj, int (&alphaMap)[26][26]) {\n int *curMapping = alphaMap[src];\n\n priority_queue<eng, vector<eng>, greater<eng>> heap;\n heap.emplace(0,src);\n\n while(!heap.empty()) {\n auto [dist, node]...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n map<char, int> dijkstra(char& src, map<int, vector<pair<char, int>>>& adjList){\n priority_queue<pair<int, char>, vector<pair<int, char>>, greater<pair<int, char>>> pq;\n map<char, int> minCost;\n pq.push({0, src});\n\n while(!pq.empty()){\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\n int shortestPath(const vector<unordered_map<int, int>>& adj, int src, int dst,\n vector<unordered_map<int, int>>& shortestPaths) {\n if (src == dst) {\n return 0;\n }\n\n if (shortestPaths[src][dst] > 0) {\n return shortestPaths[src][dst];\n }\n\n...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n\n int dijkstra(vector<vector<int>> &paths, int source, int dest)\n {\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > pq;\n vector<int> dist(26,1e9);\n\n dist[source]=0;\n pq.push({0,source});\n\n while(!pq....
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n\n int dijkstra(vector<vector<int>> &paths, int source, int dest)\n {\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > pq;\n vector<int> dist(26,1e9);\n\n dist[source]=0;\n pq.push({0,source});\n\n while(!pq....
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n void dijkstra(unordered_map<int, vector<pair<int, int>>>& graph, int source, vector<int>& dist) \n {\n dist[source] = 0;\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n pq.push({0, source});\n while (!pq.e...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n\nvoid dijkstra(char start, unordered_map<char, vector<pair<char, int>>>& adj, unordered_map<char, int>& minCost) {\n // Priority queue to store the character and its current cost.\n priority_queue<pair<int, char>, vector<pair<int, char>>, greater<pair<int, char>>> pq;\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\nprivate:\n void dji(vector<vector<pair<int, int>>> &edges, vector<vector<int>> &dist, int node) {\n vector<bool> visited(26, false);\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;\n que.push({0, node});\n\n while(!que....
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "\nclass Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<vector<pair<int, int>>> graph(26);\n unordered_map<pair<char, char>, int, pair_hash> mp;\n unordered_map<pair<char, char>, i...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n unordered_map<char,vector<pair<char,int>>> m;\n unordered_map<char,unordered_map<char,long long>> dp;\n long long bfs(char s, char t){\n vector<int> vis(26,INT_MAX);\n priority_queue<pair<int,char>, vector<pair<int,char>>, greater<pair<int,char>>> pq;\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n struct cmp {\n bool operator()(pair<int, int> &x, pair<int, int> &y) {\n return x.second > y.second;\n } \n };\n \n unordered_map<int, int> getCost(int x, unordered_map<int,vector<pair<int, int>>> & data) {\n priority_queue<pair<int, ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\nprivate:\n vector<int> shortest_dist(const char s, const map<char, vector<pair<char,int>>>& adj) {\n vector<int> out(26, -1);\n priority_queue<pair<int, char>, vector<pair<int, char>>, greater<pair<int, char>>> unvisited {};\n unvisited.push({0,s});\n while ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\nprivate:\n vector<int> shortest_dist(const char s, const vector<vector<pair<char, int>>>& adj) {\n vector<int> out(26, -1);\n priority_queue<pair<int, char>, vector<pair<int, char>>, greater<pair<int, char>>> unvisited {};\n unvisited.push({0,s});\n while (!...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n unordered_map<int,int> dijsktras(int src, auto& graph) {\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;\n pq.push({0, src});\n \n unordered_set<int> visited;\n unordered_map<int, int> min_cost_map;\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<vector<pair<int, int>>> graph(26);\n int n = original.size();\n for (int i = 0; i < n; i++) {\n graph[original[i] -...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "ostream& operator<<(ostream& o, const pair<char, int>& neighbor) {\n o << \"{\" << neighbor.first << \", \" << neighbor.second << \"}\";\n return o;\n}\n\nostream& operator<<(ostream& o,\n const vector<vector<pair<char, int>>>& adjList) {\n for (const auto& l : adjList) {\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\n size_t toIndex(char ch) {\n return ch - 'a';\n }\n void fillMinCostsList(char sourceChar,\n const std::vector<std::vector<std::pair<char, int>>>& adjList,\n std::vector<int>& outMinCostsList) {\n std::priority_queue<std::pair<int, char>,\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\n size_t toIndex(char ch) {\n return ch - 'a';\n }\n void fillMinCostsList(char sourceChar,\n const std::vector<std::vector<std::pair<char, int>>>& adjList,\n std::vector<int>& outMinCostsList) {\n std::priority_queue<std::pair<int, char>,\n ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<vector<pair<char, long long>>> g(26);\n for (int i = 0; i < original.size(); i++) {\n g[original[i] - 'a'].emplace_back(ch...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<vector<pair<char, long long>>> g(26);\n for (int i = 0; i < original.size(); i++) {\n g[original[i] - 'a'].emplace_back(ch...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<vector<pair<int,int>>>graph(128);\n unordered_map<int,unordered_map<int,int>>memo;\n vector<int> dist(128);\n int n = o...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n unordered_map<char, vector<pair<char, int>>> mp;\n for (int i = 0; i < original.size(); i++) {\n mp[original[i]].push_back({chang...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n vector<vector<int>> e(26, vector<int>(26, INT_MAX));\n vector<vector<long long>> cache(26, vector<long long>(26, -1));\n for(int i = ...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution {\npublic:\n\n void dijsktra(int x, vector<vector<pair<int, int>>> adj, vector<vector<int>> &c)\n {\n multiset<pair<int, int>> st;\n st.insert({0, x});\n vector<int> vis(26), dist(26, 1e9+7);\n dist[x]=0;\n while(st.size()>0)\n {\n a...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution \n{\npublic:\n unordered_map<char, long long> djikstra(unordered_map<char, vector<pair<char, long long>>>& G, char start)\n {\n unordered_map<char, long long> D;\n unordered_map<char, char> P; \n for(char c ='a'; c <= 'z'; c++)\n {\n D[c] = numer...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "class Solution \n{\npublic:\n unordered_map<char, long long> djikstra(unordered_map<char, vector<pair<char, long long>>>& G, char start)\n {\n unordered_map<char, long long> D;\n unordered_map<char, char> P; \n for(char c ='a'; c <= 'z'; c++)\n {\n D[c] = numer...
3,235
<p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ...
3
{ "code": "typedef pair<int,int> pii;\n\nclass Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& O, vector<char>& C, vector<int>& cost) {\n vector<vector<pii>> adj(26);\n for (int i = 0; i < O.size(); i++) {\n adj[O[i]-'a'].push_back({C[i]-'a', cost[i]...