Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts | Leetcode 1465 | Live coding

  Рет қаралды 6,457

Coding Decoded

Coding Decoded

Күн бұрын

Пікірлер: 36
@sushmitakumari8252
@sushmitakumari8252 Жыл бұрын
Best explanation 👌 👏👏
@SDE-wq4tl
@SDE-wq4tl 2 жыл бұрын
Most intuitive solutions exists here
@sravanicharugundla9619
@sravanicharugundla9619 2 жыл бұрын
1000000000 1000000000 [2] [2] this case isnt working for me:(
@yogeshyogesh2923
@yogeshyogesh2923 2 жыл бұрын
good explanation but my dumb mind is not understanding 😭😭
@yogeshyogesh2923
@yogeshyogesh2923 2 жыл бұрын
Yeh i just understand 😊 the solution
@Anonymous-ps8cv
@Anonymous-ps8cv 2 жыл бұрын
What if maxHeight*maxWidth is exceeding long limit too? Then how to return answer in % ?
@sixsided3825
@sixsided3825 2 жыл бұрын
Use maxHeight = maxHeight % (1e9+7); maxWIdth = maxWidth % (1e9+7); and then 1L * maxHeight * maxWidth is guaranteed to be within max value of long since 1e9+7 * 1e9+7 is less than max value of long.
@vaibhavvashist238
@vaibhavvashist238 2 жыл бұрын
if heights of one of the cuts is max then then width of that cut is also max
@tathagatnegi5923
@tathagatnegi5923 3 жыл бұрын
Thanks
@CodeWithSunchitDudeja
@CodeWithSunchitDudeja 3 жыл бұрын
Thnx
@devanshsrivastava9751
@devanshsrivastava9751 3 жыл бұрын
Great Explanation in a very cool way... Really liked and keep uploading
@CodeWithSunchitDudeja
@CodeWithSunchitDudeja 3 жыл бұрын
Thnx Devansh
@algorithmo134
@algorithmo134 3 жыл бұрын
Can you do a video where you code while explaning after the visual explanation instead of the code showing already? It would be much better
@CodeWithSunchitDudeja
@CodeWithSunchitDudeja 3 жыл бұрын
I previously used to do it, check my old videos. Later I thought it becomes boring for the viewers so switched to this mode
@algorithmo134
@algorithmo134 3 жыл бұрын
@@CodeWithSunchitDudeja it is not boring
@ojasvichaudhary8724
@ojasvichaudhary8724 3 жыл бұрын
can you please tell me what is 1L and why we multiply with that ?
@CodeWithSunchitDudeja
@CodeWithSunchitDudeja 3 жыл бұрын
Conversion to long from int
@ojasvichaudhary8724
@ojasvichaudhary8724 3 жыл бұрын
(long)maxHeight*maxWidth will also work ?
@CodeWithSunchitDudeja
@CodeWithSunchitDudeja 3 жыл бұрын
👍
@sayantaniguha8519
@sayantaniguha8519 3 жыл бұрын
@@ojasvichaudhary8724 *long ans = long(maxHeight * maxWidth);* doesn't work but *long ans = (long)maxHeight * (long)maxWidth;* works
@siddharthkumar2761
@siddharthkumar2761 3 жыл бұрын
Why converting to long and reverting back to int, can't we do modulo multiplication => (maxHeight%1000000007 * maxWidth%1000000007)%1000000007 ...?
@anshumangupta1001
@anshumangupta1001 3 жыл бұрын
Because maxHeight and maxWidth are given in int and also we have to return in int..!
@CodeWithSunchitDudeja
@CodeWithSunchitDudeja 3 жыл бұрын
It will work here 👍
@karanalang1573
@karanalang1573 3 жыл бұрын
one suggestion .. pls spend a minute explaining the problem (esp in this problem, the verbiage is a bit confusing), i thought you jumped to the solution immediately
@CodeWithSunchitDudeja
@CodeWithSunchitDudeja 3 жыл бұрын
Acknowledged
@shubhamkumbhare2725
@shubhamkumbhare2725 3 жыл бұрын
I dont understand the last part where you did the multiplication with the 1L and on retrun you divided with the 10000007 . Why we need to do this ?
@akshayalok7580
@akshayalok7580 3 жыл бұрын
This is a requirement by the question
@RitikSingh-bt3gp
@RitikSingh-bt3gp 3 жыл бұрын
it is multiplied by 1L so that the long ans can store the value , the limit of the long int is 10^12 , if we don't do this and simply store the value in int ans (which has limit of 10^7 only) the ans will not be able to accommodate.
@CodeWithSunchitDudeja
@CodeWithSunchitDudeja 3 жыл бұрын
+1 to what @Akshay and @Ritik said, in order to avoid overflow conditions we have to do it.
@resumeprojects782
@resumeprojects782 3 жыл бұрын
@@RitikSingh-bt3gp I understand the question says to do 10000007 , But why exactly that? why not 10000008? or 10000009?
@RitikSingh-bt3gp
@RitikSingh-bt3gp 3 жыл бұрын
@@resumeprojects782 The number taken for mod should just be large enough to fit in the largest integer data type i.e it makes sure that there is no overflow in the result. It should be a prime number because if we take mod of a number by Prime the result is generally spaced i.e. the results are very different results in comparison to mod the number by non-prime, that is why primes are generally used for mod. 10^9+7 fulfills both the criteria. It is the first 10-digit prime number and fits in int data type as well. In fact, any prime number less than 2^30 will be fine in order to prevent possible overflows.
@tanyagupta3846
@tanyagupta3846 3 жыл бұрын
Wow, awesome
@akshayalok7580
@akshayalok7580 3 жыл бұрын
Bro why do we need to sort the array? if we just need max dimension... and the max dimension = max gap between two elements of the array, can't we use pigeonhole to find max height and width and reduce further to Constant * O(n) complexity? PS: Btw I tried both approaches and the approach where I sort the array is getting lesser runtime (probably because leetcodes test cases have many arrays of small lengths in which case pigeonhole is comparable or worse than sorting and iterating)
@CodeWithSunchitDudeja
@CodeWithSunchitDudeja 3 жыл бұрын
We are not given the widths or the heights in the questions. We need to calculate it from the coordinates. Your solutions looks interesting, curious to know how it works, can you raise a PR in github.com/Sunchit/Coding-Decoded appending your solution to mine. I will be glad if you do it.
@akshayalok7580
@akshayalok7580 3 жыл бұрын
@@CodeWithSunchitDudeja Check it out, although the solution is in python and I am not so sure about readability :p
Interleaving String | Leetcode 97 | Live coding session | DP
21:52
Coding Decoded
Рет қаралды 2,9 М.
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 9 МЛН
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 15 МЛН
Noodles Eating Challenge, So Magical! So Much Fun#Funnyfamily #Partygames #Funny
00:33
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 5 МЛН
Sliding Window Technique - Algorithmic Mental Models
36:45
Ryan Schachte
Рет қаралды 363 М.
Winning Google Kickstart Round A 2020 + Facecam
17:10
William Lin (tmwilliamlin168)
Рет қаралды 10 МЛН
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 155 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН
What Professional Software Engineers ACTUALLY Do
14:28
ForrestKnight
Рет қаралды 1,6 МЛН
eBPF в Kubernetes: из огня не в полымя
50:20
Инфосистемы Джет
Рет қаралды 1,4 М.
Easy Google Coding Interview With Ben Awad
28:00
Clément Mihailescu
Рет қаралды 1 МЛН
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 9 МЛН