Furthur space optimization is possible TC-O(n) SC-O(1) class Solution { public: vector<int> finalPrices(vector<int>& prices) { int n = prices.size(); vector<int> ans (n); ans[n-1]=n; for( int i = n-2 ; i>=0 ; i--){ int j=i+1; while(j<n&&prices[j]>prices[i]){ j=ans[j]; } ans[i]=j; } for(int i=0;i<n;i++){ if(ans[i]>=n){ ans[i]=prices[i]; }else{ ans[i]=prices[i]-prices[ans[i]]; } } return ans; } };
@piyushsingh455819 сағат бұрын
space optimization , Mind blown
@tuanhungphamcong1340Күн бұрын
no DSU :((
@SumitYadav-q4s2sКүн бұрын
can we use dp here?
@debyet017Күн бұрын
Amazing explanation! was able to implement it on my own, the breakdown of logic into steps really helps a lot.
@drugzgamerz7348Күн бұрын
Great explanation
@vaibhavmistry-v6hКүн бұрын
Thanks man .I was stuck on this but your one statement explained me the whole problem solution .
@KR_Technical-hj3bfКүн бұрын
nice video
@ahappyperson6530Күн бұрын
Please make a video on last LC weekly contests solutions. B was really interesting and code heavy
@study-yd6esКүн бұрын
Thanks Aryan for this tutorial <3 I wouldn't know that we can use map greater<char>. Thankyou again for this amazing tutorial.
@sankar6934Күн бұрын
Thank you for posting videos on a daily basis! Even though I often struggle with the daily challenges, watching your approach to problem-solving has helped me overcome my fear and start thinking about the best possible solutions. I have one request: could you please solve it in Java or at least provide an overview? Thanks, and keep coding 😄!
@RoniBadgujjarКүн бұрын
thanks bro for this amazing content please keep it we really need your kind of peoples and your explaining style is also very well i totally get the idea
@esseclues28732 күн бұрын
when i=s.length(); then It will give ArrayOutOfBoundIndex
@kshitijvarma25662 күн бұрын
loved the way of explanation..... crystal clear ....
@insofcury2 күн бұрын
Great Intuition
@floatingpoint76292 күн бұрын
great video with the dry run example. the deque diagram was a little confusing but good explanation overall
@palashdas72033 күн бұрын
Tell me one Thing ...... The hook is at (6,8) , Bishop is at (6,6) and the queen is at (6,3) Now Would you Please write just the moves here ....
@palashdas72033 күн бұрын
Thanks for your Concept .... Yes I got it
@princeprabhat93233 күн бұрын
for the last solution, we don't need two sets instead, we can have one set and run loop over the array. Once the element is found in the set we can push it to our answer array and delete that element from the set. So that, next time same elements comes which we have already inserted in our array, we will not push because it is not in the set.
@sanskarjain53943 күн бұрын
I recently started watching your video and I love how to explain things. Keep going BOSS 👌👌
@ShashikantPawar-g5u3 күн бұрын
@AryamMital Can you comeup with some c++ cour se
@kgjr.62243 күн бұрын
Love your Content bro. 👊 👊 😎 😎 Keep doing this,
@pruthvinarayana95683 күн бұрын
I am using Python 🤡
@abinash18783 күн бұрын
In the priority queue loop, why you are calculating the gain with adding 1 to pass and total?? You are adding it in the calculategain method right??
@syedanwar56473 күн бұрын
Who else has seen Aryan's id in today's leetcode solution section.😅
@Zomb-zj4ip3 күн бұрын
THE GOAT IS BACK TO CPP LETSGOOOOOOOOOOOOOOOOOO
@jitushekkumar70833 күн бұрын
please solve locked problems as well .
@chitrapandey72553 күн бұрын
has he started writing code in Cpp now?
@sarankumaar60093 күн бұрын
great explanation bro thanks for the video :)
@urdaddy85203 күн бұрын
bhaiya plz do leetcode 1595, I need ur explanation
@Anonymous____________A7213 күн бұрын
No need
@urdaddy85203 күн бұрын
@@Anonymous____________A721 if u don't need, don't comment unnecessarily
@urdaddy85203 күн бұрын
@@Anonymous____________A721 If u don't need just shut ur mouth
@leepakshiyadav16433 күн бұрын
amazing and detailed explanation 👏👏
@Nutrino2593 күн бұрын
I want to know what is/was your highest POTD streak on leetcode???
@Akash.B283 күн бұрын
Very good explanation!!!
@anandsingh-mp4zv4 күн бұрын
awesome, let me ping the entire code here struct FT{ vector<int> bit; int n; FT(int sz){ n = sz; bit.resize(sz + 1, 0); } void add(int indx, int val){ while(indx <= n){ bit[indx] = max(bit[indx], val); indx += indx & -indx; } } int get(int indx){ int mx_val = 0; while(indx > 0){ mx_val = max(mx_val, bit[indx]); indx -= indx & -indx; } return mx_val; } }; class Solution { public: vector<bool> getResults(vector<vector<int>>& queries) { ios_base::sync_with_stdio(false); int n = min(3 * (int)queries.size(), (int)5e4) + 1; set<int> obstacles; FT ft(n); obstacles.insert(0), obstacles.insert(n); for(const auto &q: queries){ if(q[0] == 1){ obstacles.insert(q[1]); } } for(auto it = obstacles.begin(); it != obstacles.end(); ++it){ if(it == obstacles.begin()) continue; ft.add(*it, *it - *prev(it)); } vector<bool> res; for(int i = queries.size() - 1; i >= 0; --i){ vector<int> &q = queries[i]; if(q[0] == 1){ int x = q[1]; auto it = obstacles.find(x); auto nxt = next(it); auto prv = prev(it); ft.add(*nxt, *nxt - *prv); obstacles.erase(it); } else{ int x = q[1], sz = q[2]; auto it = prev(obstacles.upper_bound(x)); int mx_sz = max(ft.get(*it), x - *it); res.emplace_back(mx_sz >= sz); } } reverse(res.begin(), res.end()); return res; } };
@mageshyt25504 күн бұрын
love the two pointer explanation 💝
@vaibhav82574 күн бұрын
Nice to see you Back
@Axel.Blazer4 күн бұрын
in your approach 5 i thought we could do better by storing just the last index of curmin and curmax..that'd speed it up a bit i guess but idk
@mandartule4 күн бұрын
@JitendraSingh-t7w9c4 күн бұрын
I think in deque approach shrinking the window by hop is same as shrinking it one by one. Please help if anyone have code of shrinking window one by one.