Perfect Squares Dynamic Programming | Leetcode 279 Solution in JAVA

preview_player
Показать описание

NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. Here you will know about Perfect Square Problem. In this question :

1. You are given a number N.
2. You have to find the minimum number of squares that sum to N.
3. You can always represent a number as a sum of squares of other numbers.
For eg - In worst case N can be represented as (1*1) + (1*1) + (1*1)..... N times.

#dynamicprogramming #leetcode #perfectsquares

Рекомендации по теме
Комментарии
Автор

This is the best explanation for this question I have got till now. Thank you.

ujjwalgupta
Автор

I previously had a solution of T= O(n^2) thanks for this approach seems like T=O(nlogn) approach 🙏🙏

sudhanshukumar
Автор

Awesome explanation. Dynamic programming seems easier than Recursion for me

florakunjumon
Автор

Extraordinary explanation ❤️❤️❤️
🔥🔥🔥🔥🔥🔥

faizanali-gryx
Автор

thanku sir
your explanation is very easy

balramchoudhary
Автор

Sir, Thank you so much for this video. It is very easy to understand here.

overlordcoding
Автор

Sir aap ki video ka subah se wait krte h please sir no of video thoda badha dijiye sir🙏🙏

VishalSingh-gmqj
Автор

Please keep on going and keep up the good work sir!!!

ishanpatni
Автор

Amazing explanation👏. Took me an Entire day to debug the logic still didn't got it right

zaidshaikh
Автор

Ye 01 knapsack ka variation hai kya ?

live_study_with_me
Автор

As i always say "East or west, sumeet sir is the best"

factswithai
Автор

Sir if possible please discuss the recursive solution before getting on to the DP part...

alokesh
Автор

Sir, it can be solve by solution used in "Coin Change" problem also

Entertainment-byci
Автор

we can also handle 0, 1, 2 case explicitly to save time

utkarshsharma
Автор

i think i can now say, that tabulation makes things really easy.

ritiktwopointo
Автор

sir how we would get this tabulation insight, only brute force recusrion came to my mind

mickyman
Автор

Hello sir, Thank you for the videos..
I am facing some issues in pepcoding ide(c++) even though my logic is correct...sometimes it shows compilation error and sometimes compliation time limit exceeded...and sometimes gives correct output ..but when I submit, it doesn't fix this issue...it will be very beneficial ...thank you

gauravbhansali
Автор

I have a question,
Why are you checking for (line 16) dp[rem ]<min before adding 1 (for the step we currently took)? Why not check after adding 1 ?
Ex- int newCount = dp[rem]+1;
if(newCount<min){
min= newCount;
}

animatoristu
Автор

correct solution in c++
class Solution {
public:
int numSquares(int n)
{
if(n<=3)
{
return n;
}
int dp[n+1];
dp[0]=0;
dp[1]=1;
for(int i=2;i<=n;i++)
{
int mn=INT_MAX;
for(int j=1;j*j<=i;j++)
{
int rem=i-j*j;
if(dp[rem]<mn)
{
mn=dp[rem];
}
}
dp[i]=mn+1;
}
return dp[n];

}
};

wecan
Автор

sir is talking about LIS . will anybody tell me what is this LIS???

tanmaychaudhary
welcome to shbcf.ru