Leetcode Weekly contest 354 - Medium - Maximum Beauty of an Array After Applying Operation

  Рет қаралды 2,795

Prakhar Agrawal

Prakhar Agrawal

Күн бұрын

Пікірлер: 39
@atulbartwal2421
@atulbartwal2421 Жыл бұрын
The best thing I like about you is the way you explain a problem. Half of the time, because of that I kinda get the intuition of how to solve the problem. Hope your channel grows exponentially. Cheers.
@yashvardhanmalve7252
@yashvardhanmalve7252 Жыл бұрын
Your clear explanations and step-by-step approach made it so much easier. Thanks.
@i_love_api
@i_love_api Жыл бұрын
Case study approach from [non-optimal solution to optimal] solution ---> one of the best videos I watched.
@fgffgf9844
@fgffgf9844 Жыл бұрын
how can one explain such a complex question with such clarity? hatsoff to u man
@nkvs1248
@nkvs1248 Жыл бұрын
That's why I subscribed it, just after seeing a video from this channel :)
@prakhar3agrwal
@prakhar3agrwal Жыл бұрын
Thanks 🙏
@prakhar3agrwal
@prakhar3agrwal Жыл бұрын
Thanks 🙏
@dhruvsakariya3129
@dhruvsakariya3129 Жыл бұрын
Thank you finally i found some logical explanation instead of bunch of random solution 🙏🙏
@prakhar3agrwal
@prakhar3agrwal Жыл бұрын
Glad it helped!
@i_love_api
@i_love_api Жыл бұрын
I hope in the future we will get more such content.
@rsKayiira
@rsKayiira 8 ай бұрын
This is a very very tricky question but you explained it quite well. This is my second time watching your video on this solution. I needed to first take a break and relook at this problem because the edge cases are quite tricky but this is the best solution out there.
@loudcapricorn5513
@loudcapricorn5513 Жыл бұрын
Sir I was also able to solve this question with the exact same thinking/logic and my implementation was also same. I have been Solving past contests as virtual contest and after that I see your videos for the question which I was not able to solve. This particular type of question where there are ranges and we have to do operation on multiples ranges had appeared in multiple contests recently thus I was able to solve this too [Scanline algorithm is the name i guess]. Your videos are very helpful and provide great learnings , please continue doing so. Lastly Thank You for your efforts
@prakhar3agrwal
@prakhar3agrwal Жыл бұрын
Thanks. Totally my pleasure.
@dipanshugoyal491
@dipanshugoyal491 Жыл бұрын
Thank you for your nice explanation. I was close and going in same direction just couldn't think of that pre-sum trick.
@borse2982
@borse2982 Жыл бұрын
Great Explanation Dude...
@viveksuman9600
@viveksuman9600 Жыл бұрын
Very good explanations. Keep it up 👍
@prakhar3agrwal
@prakhar3agrwal Жыл бұрын
Glad you liked it
@rsKayiira
@rsKayiira 8 ай бұрын
Excellent explanation thank you
@Abhishek-fo3fc
@Abhishek-fo3fc Жыл бұрын
Nicely Explained❤
@prakhar3agrwal
@prakhar3agrwal Жыл бұрын
Glad you liked it!
@karapureddyjaswanthreddy6053
@karapureddyjaswanthreddy6053 Жыл бұрын
great explanation
@LogicArena01
@LogicArena01 Жыл бұрын
Thank you vaiya , pura clear ho geya ❤
@saivardhanpallerla9
@saivardhanpallerla9 Жыл бұрын
Hello sir , Thanks for amazing explanation , i have written in c++ , although it had passed all test cases but it didn't got accepted .[ 619 / 619 test cases passed, but took too long.] => We can optimze further for finding the maximum overlapped number instead of iterating from [ 0 , 300002] , we can reduce the iteration by finding the correct indices [ first , second ] . SOLUTION : C++ class Solution { public: int maximumBeauty(vector& nums, int k) { vector freq( 300005 , 0 ); int shift = 100000; int first = INT_MAX , second = INT_MIN; for( int i = 0 ; i < nums.size() ; i++ ) { int start_idx = nums[i] - k ; int end_idx = nums[i] + k; first = min( first , start_idx + shift ); second = max( second , end_idx + shift + 1 ); freq[start_idx + shift]++; freq[end_idx + shift + 1]--; } int ans = freq[first]; for( int i = first + 1 ; i < second + 2 ; i++ ) { freq[i] += freq[i-1]; ans = max( ans , freq[i] ); } return ans; } };
@suyashmishra6946
@suyashmishra6946 Жыл бұрын
nice
@shaamidrees6036
@shaamidrees6036 Жыл бұрын
Upload 4th also
@HarishSumant
@HarishSumant Жыл бұрын
Crystal clear solution as always!! I had a query: This is the C++ version of your solution. It gives TLE after passing 619/619 test cases (????) . Could you please help me with this? class Solution { public: int maximumBeauty(vector& nums, int k) { vectorarr(300005,0); int offset=100000; for(int i=0;i
@SohanKale-m4z
@SohanKale-m4z Жыл бұрын
mine C++ code got passed
@saivardhanpallerla9
@saivardhanpallerla9 Жыл бұрын
class Solution { public: int maximumBeauty(vector& nums, int k) { vector freq( 300005 , 0 ); int shift = 100000; int first = INT_MAX , second = INT_MIN; for( int i = 0 ; i < nums.size() ; i++ ) { int start_idx = nums[i] - k ; int end_idx = nums[i] + k; first = min( first , start_idx + shift ); second = max( second , end_idx + shift + 1 ); freq[start_idx + shift]++; freq[end_idx + shift + 1]--; } int ans = freq[first]; for( int i = first + 1 ; i < second + 2 ; i++ ) { freq[i] += freq[i-1]; ans = max( ans , freq[i] ); } return ans; } };
@Rajat_maurya
@Rajat_maurya Жыл бұрын
this is really crazy mine working ditto same class Solution { public: int maximumBeauty(vector& v, int k) { int n = v.size(); int offset = 100000; vector freq(300005, 0); for(int i=0;i
@siddhantdwivedi7024
@siddhantdwivedi7024 Жыл бұрын
We can also solve this using sliding window but before that we have to sort the array
@prakhar3agrwal
@prakhar3agrwal Жыл бұрын
Intresting.
@niteshkhanna690
@niteshkhanna690 Жыл бұрын
i solved by this during contest
@HI-wl9el
@HI-wl9el Жыл бұрын
Yeah done the same . I think it would be better if constraints would be more tougher to implement
@shaamidrees6036
@shaamidrees6036 Жыл бұрын
Thanks brother
@shubhamrohan3136
@shubhamrohan3136 Жыл бұрын
thankyou sir.
@tusharaherwar
@tusharaherwar Жыл бұрын
Is this line sweep algo
@divyanshuagarwal1912
@divyanshuagarwal1912 Жыл бұрын
@@tusharaherwar yes
@nikethdonthula2123
@nikethdonthula2123 Жыл бұрын
Very Well Explained Sir !! I was able to write the code just by the intuition provided : Code : class Solution { public int maximumBeauty(int[] nums, int k) { int min = nums[0]; int max = nums[0]; for(int item : nums) { min = Math.min(min,item); max = Math.max(max,item); } HashMap hmap = new HashMap(); for(int i = min-k;i
@prakhar3agrwal
@prakhar3agrwal Жыл бұрын
Awesome. Best of luck
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН
one year of studying (it was a mistake)
12:51
Jeffrey Codes
Рет қаралды 243 М.
Путин ответил на ультиматум Трампа
7:25
Diplomatrutube
Рет қаралды 1,9 МЛН
Maximum and Minimum Sums of at Most Size K Subarrays (Leetcode Weekly 433)
16:59
How I learned to code in 3 months (and got several offers)
12:54
Coding Jesus
Рет қаралды 217 М.
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 680 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 243 М.