i dont know why i couldnt figure out qsn2,within one code, i calculated operations by multiple methods and took min of that,but somehow i missed this idea and didnt try it
Hi! It’s absolutely okay. It’s a first time for everything, and I’m sure you will now be able to easily score such problems. Takeaway - think backwards!
can anyone tell me why this fails coz we want to cover difference between b and a using subtraction and division while(t-- > 0) { int a = sc.nextInt(); int b = sc.nextInt(); int k = sc.nextInt(); int diff = b-a ; int operation = 0; // we want all gaps to be covered if(diff/k >=a) {operation = diff / k ; diff = diff%k; } operation += diff-a ; System.out.println(operation); }
I think you are confusing by dividing diff by k. In reality the number b is getting operated on which is way different than this. Try with some simple testcase.
in c let node value is 4 but is is at distance 6 from node 1 and let there is another node with value 6 but at distance of 3 and both value are greater than node 1 value so we should choose 6*3 rather than 4*6 and it contradicts your facts that we will choose a node with lesser value and which is at leftmost. please help!
Think even further to this. Let’s say now you want to reach the last node, because you took 6 which was greater than 4, your max will still remain 6 which gives you a bigger answer on reaching last node.
Yes, the idea of creating a decreasing/increasing node pattern from first node is monotonic stack question. Hence stack is used. You can look up monotonic stack on any resource, and you will find plenty of questions to practice.
@@Sheldor.The.Conqueror I have defined int as long long u can change 1e18 to 1e9 and see if it works? Or u can just change int to long long in ans ,a,b,k and f hope it helps
Your solution is based again on the fact that you are going from b to a and not a to b. I think recursion for a to b will not work, that is what I meant.
Please fill the feedback form : forms.gle/FA7EiUj68e1R3TAQ7
This man has got some real talent on explaining things!!Hats off
Please I want all post contest video from you great teaching style at all..
Your explanation and efforts are at another level
What an explanation bro,u just rocked!!
Very Good Explanation thanku bhaiya
I don't usually comment on videos but you sir great. Very well explained.@Priyansh give this man a raise xD
Heyyy u r awesome!!!!!!
i dont know why i couldnt figure out qsn2,within one code, i calculated operations by multiple methods and took min of that,but somehow i missed this idea and didnt try it
Hi! It’s absolutely okay. It’s a first time for everything, and I’m sure you will now be able to easily score such problems. Takeaway - think backwards!
@@VirajChandra not able to do this took me from 3* to 2* maybe that's why its hurting more than usual
can anyone tell me why this fails coz we want to cover difference between b and a using subtraction and division
while(t-- > 0)
{
int a = sc.nextInt();
int b = sc.nextInt();
int k = sc.nextInt();
int diff = b-a ;
int operation = 0;
// we want all gaps to be covered
if(diff/k >=a)
{operation = diff / k ;
diff = diff%k;
}
operation += diff-a ;
System.out.println(operation);
}
I think you are confusing by dividing diff by k. In reality the number b is getting operated on which is way different than this. Try with some simple testcase.
in c let node value is 4 but is is at distance 6 from node 1 and let there is another node with value 6 but at distance of 3 and both value are greater than node 1 value so we should choose 6*3 rather than 4*6 and it contradicts your facts that we will choose a node with lesser value and which is at leftmost. please help!
Think even further to this. Let’s say now you want to reach the last node, because you took 6 which was greater than 4, your max will still remain 6 which gives you a bigger answer on reaching last node.
Lot of people have done c through stack.... is it a standard question
Yes, the idea of creating a decreasing/increasing node pattern from first node is monotonic stack question. Hence stack is used. You can look up monotonic stack on any resource, and you will find plenty of questions to practice.
We can also do it by dijkstra but in this case we have to remove unwanted edges in the graph construction
Yes, as I mentioned during problem explaining that this can be solved with graph construction also by removing unwanted edges.
(graph cost ) greedy traversal
ll n;
cin>>n;
vin(temp , n);
ll ans2 = 0;
ll m1 = temp[0];
ll p1 = 1;
ll m2 = temp[n-1];
ll p2 = n;
fi(1 , n-1)
{
if(temp[i]
can you please give your submission link
Hey I also want to join discussion meeting ,Please tell how to join
Yeah mee too
you have to buy one of their courses
in A to B rec/dp solution works!!
Is that so? Please show some submission link.
@@VirajChandra sir we can do it like this -->
int f(int a,int b,int k){
if(b> t;
while(t--) {
int a,b,k;
cin>>a>>b>>k;
cout
@@SohailKhan-cx9gb This is not giving correct output on Codechef compiler. Output there is :
-2147483644
-2147483647
-2147483645
-2047483646
@@Sheldor.The.Conqueror I have defined int as long long u can change 1e18 to 1e9 and see if it works? Or u can just change int to long long in ans ,a,b,k and f hope it helps
Your solution is based again on the fact that you are going from b to a and not a to b. I think recursion for a to b will not work, that is what I meant.