Evaluate Division | With INTUITION | META, AMAZON | Leetcode-399 | Live Code 🧑🏻💻👩🏻💻
Vložit
- čas přidán 19. 05. 2023
- This is the 27th Video on our Graphs Playlist.
In this video we will try to solve a very interesting Graph Problem "Evaluate Division" (Leetcode - 399)
I am promising you, this problem will become easy once you are done with this video.
If you have been following my "Graph Concepts & Qns" playlist , then these Qns will become very easy. Find the Link for that below.
We will do live coding after explanation and see if we are able to pass all the test cases.
Problem Name : Evaluate Division
Company Tags : META, AMAZON
My solutions on Github : github.com/MAZHARMIK/Intervie...
Leetcode Link : leetcode.com/problems/evaluat...
My Graph Concepts Playlist : • Graph Concepts & Qns -...
My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
Subscribe to my channel : / @codestorywithmik
Instagram : / codestorywithmik
Facebook : / 100090524295846
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish
Leetcode should publish this video in their official solution. ❤
You made my day Tauquir ❤️❤️❤️
It feels so good reading such comments
Thank you from the bottom of my heart
I think this is the speciality of this channel. He makes even a tough Qn look damn so easy. It literally becomes a piece of cake.
Beautiful solution to an insane Problem
Always Great 😊
❤❤❤
Thanks a lot bhaiya ❤❤
I have no words to praise you
Means a lot 🙏😇
Bhai your explanations are amazing. You cover everything from how to even think about the problem and go all the way to implementing it. Thanks and please try to cover as many leetcode problems as you can so it will help fellow aspiring developers like us to build up the thought process of solving interview questions.Thanks for your videos and hope your channel grows even more. All the best !
Means a lot. Thank you so much ❤️
salute to this explanation🖖
It was day before I was in search of this and here you are with very easy explanation. It would be really helpfull if you could also start discussing leetcode contests questions every sunday bcoz of you Iam trying every day questions thinking of back like you. thank you very much
So glad it is helping you.
Thank you so much.
And i will try soon to make contests solutions too.
Woooh.. When I saw this problem first time in mock interview series , I was scratching my head for 10-15 mins.. I wss getting some Vibes of graph but wasn't sure how exactly I will approach further specially the 1/ value part.. thanks for your Great explanation...
One thing I would like to add on this that you are passing prod*val in the DFS function call there's a reason for that. Just in case anyone is wondering whyy.. because we want to multiply exact from src to destination paths not the useless path which comes on the way to DFS call..
Commenting on every video I watch. There is more recognition that you deserve ❤
Really helpful. Thanks for the video
What an explanation, Great Intuition building. Every video gives the same adrenaline rush. Looking forward to learn a lot from you Bhaiya❤.
Wow. Thank you so much Arjun ❤️❤️❤️
sir please complete the playlist of dp interview q of leetcode@@codestorywithMIK
Fantastic explanation.
As always best explanation 👌🏻
Thank you so much Anup ❤️❤️❤️
Great Explanation
Thanks a lot ❤️
dude u r awesome 🔥🔥🔥
Make a playlist on recursion How solve recursion problem
coolest solution ever sir , amazin
Thanks a lot ❤️❤️
❤
awesome explanation as always...
Thanks a lot Manoj ❤️
Waiting for DSU approach.
Bro please if you can make greedy videos it would be really helpful.
Hi there
I already have a Greedy playlist you can find in my channel.
I will post more videos on that playlist
Yaar ye kis angle se graph ka ques Tha!! Its impossible to figure it out
Indeed.
Figuring out was the hardest part.
I was wondering if we can do some memoization using dp as well in this question???
Thank you bhai..Today again I knew why C++ is better for DSA than Java. Java Implementation:
class Pair {
String first;
double second;
Pair(String _first, double _second) {
this.first = _first;
this.second = _second;
}
}
class Solution {
private double ans = -1.0;
private void DFS(String src, String des, Set visited, Map adj, double product) {
if(visited.contains(src)) {
return;
}
visited.add(src);
if(src.equals(des)) {
ans = product;
return;
}
for(Pair pair : adj.get(src)) {
String v = pair.first;
double val = pair.second;
DFS(v,des,visited,adj,product*val);
}
}
public double[] calcEquation(List equations, double[] values, List queries) {
int n = equations.size();
Map adj = new HashMap();
//Make the graph
for(int i=0; inew ArrayList()).add(new Pair(v, value));
adj.computeIfAbsent(v, k->new ArrayList()).add(new Pair(u, 1.0/value));
}
int N = queries.size();
double[] result = new double[N];
int pos = 0;
for(int i=0 ; i
Thanks JJ ❤️❤️
Thanks for the Java code.
Yes C++ is better for DSA than Java but what if the interviewer wants you to code in Java since you have applied for the Java Developer role
I was checking src==dest instead src.equals(des)
This is a common mistake when you compare strings in Java
In Java, when you pass a primitive type (like double) to a method, it is passed by value
So your code helped me to declare ans variable as a global variable
why this man is so underrated. ???????
I can't wait to see what mind-blowing content you come up with next!
It means a lot to me Jay ❤️❤️❤️
That's what I keep thinking. What I have noticed is that this guy never asks us to like or subscribe to his channel like other CZcamsrs do in general.
I don't know the reason why.
Saw the question kind of got the logic after seeing the hints but then thought it cant be that complex, came to video saw till 7 minutes and went to LC and coded it , wasn't that hard, sometimes mind scares you when you trying to do something new or new way of implementations . CODE :
class Solution {
public:
vector calcEquation(vector& equations, vector& values, vector& queries) {
vector ans;
unordered_map m;
for(int i=0;i
Awesome ❤️
Bhai could you please name the topics that are left and jo ap graph concepts series me cover karenge? I think Floyd Warshall and articulation points h..aur v hain kya? now that DP series v start ho rhi.. Also as a suggestion, DP series ki introduction me batana dp me kya kya cover krenge like knapsack, dp with bit masking etc so that aur reach aaye ♥💙
Hi JJ,
Sure i will include the Roadmap and topics for DP in my first video.
And for Graphs,
We are also left with MST (minimum spanning tree) along with what you have mentioned.
But not much is left now. I think within next 2 weeks we should be done with all important ones.
Only thing left will be the Qns from then onwards.
@@codestorywithMIK thank youu ❤😻
DSU approach??
Yep. Will soon come
i am waiting for DP PlayList 😊😊
❤️❤️
This weekend coming. By tomorrow EOD
THANK YOUUU SO MUCH FOR TRUSTING MY CHANNEL
@@codestorywithMIK ❤
Can't wait already ❤❤❤
me toooo
As u said relation type questions he tho graph hi he..iske pehle equations ka ek question dekha apka... tho laga ki ye question graph hi he
Exactly Uday.
I am glad you were able to identify that ❤️❤️
Bro DSU union by rank aur size dono ka video banao na?
By Rank is already there - czcams.com/video/iH3XVIVzl7M/video.html
By size, i will create soon.
@@codestorywithMIK I already watched your video on rank. Waiting from so long for the other one....
Sure. Will try to cover that soon.
Currently a little occupied to start DP concepts playlist ❤️❤️
Atmost able to solve but I doubt in dfs for(auto &v : adj[source]){
//Why not check
if(set.find(v)!=set.end()){
//Then dfs
}
Like in dfs we check the node is already visited or not Sir, why we cannot check visited in for loop of adj 🤔
}
I think you can do that too. Can you please try and share
@@codestorywithMIK Yes is work's thanku for clearing the doubt:
//This is the code It's works perfectly
class Solution {
public:
void dfs(unordered_map &adj,string N,string D,double &cost,unordered_set &st,double product){
if(st.find(N)!=st.end()) return;
st.insert(N);
if(N==D){
cost = product;
return;
}
for(auto &v : adj[N]){
if(st.find(N)!=st.end()){ //check for visited:
string f = v.first;
double s = v.second;
dfs(adj,f,D,cost,st,product*s);
}
}
}
vector calcEquation(vector& equations, vector& values, vector& queries) {
unordered_map adj;
for(int i=0;i
Thanks for sharing your code ❤️❤️❤️💪💪
it will be more helpful if you teach it in English because every one don't know English right ,hope you understand
BFS solution:
/**
* @param {string[][]} equations
* @param {number[]} values
* @param {string[][]} queries
* @return {number[]}
*/
var calcEquation = function (equations, values, queries) {
const adj = new Map();
for (let i = 0; i < equations.length; i++) {
const [u, v] = equations[i];
const value = values[i];
if (!adj.has(u)) adj.set(u, []);
adj.get(u).push([v, value]);
if (!adj.has(v)) adj.set(v, []);
adj.get(v).push([u, 1 / value]);
}
const dfs = (src, dst) => {
if (!adj.has(src) || !adj.has(dst)) return -1;
const [q, visited] = [[], new Set()];
q.push([src, 1]);
visited.add(src);
while (q.length) {
const [node, weight] = q.shift();
if (node == dst) return weight;
for (const [nei, neiWeight] of adj.get(node)) {
if (!visited.has(nei)) {
q.push([nei, neiWeight * weight]);
visited.add(nei);
}
}
}
return -1;
}
return queries.map(([src, dst]) => dfs(src, dst));
};
❤️❤️