def numSquares(self, n): return self.num(n,{}) def num(self, n,dic): if(n in dic): return dic[n] arr = [] frequency = int(math.sqrt(n)) for i in range(frequency): i+=1 arr.append(i) maxCount = -1 for i in arr: count = self.num(n-(i*i),dic) # the argument is >=0 since i*i
bhai one question why did u declare the dp array outside the class , and yeah when i try to do the same thing inside the function i got a tle? is this related to memory allocation?
why am I getting TLE even after applying DP class Solution { static int dp[]=new int[10001]; public int numSquares(int n) { Arrays.fill(dp,-1); return numSquaresHelper(n); } public int numSquaresHelper(int n) { if(n
Best vid on RUclips
Great Explaination, Thanks alot🙂
Thanks a lot
def numSquares(self, n):
return self.num(n,{})
def num(self, n,dic):
if(n in dic):
return dic[n]
arr = []
frequency = int(math.sqrt(n))
for i in range(frequency):
i+=1
arr.append(i)
maxCount = -1
for i in arr:
count = self.num(n-(i*i),dic) # the argument is >=0 since i*i
4:17 it would be 8. kindly add a hovering comment on the video, so that others get help.
Bro, why didn't we use:
fill(dp.begin(),dp.end(),-1); in this question? how to know where to use this and where to not use this?
u can use everywhere but wherever u get wrong ans then try this
nice plz continue
Thanks a lot
Great vid!😀 #princebhai
Bhaiya appki puri Stack/Queue, Graphs, heap or DP playlist karlu, thats enough to crack and coding interview?
bhai one question why did u declare the dp array outside the class , and yeah when i try to do the same thing inside the function i got a tle? is this related to memory allocation?
Intialize dp vector in given function then it's work
why am I getting TLE even after applying DP
class Solution {
static int dp[]=new int[10001];
public int numSquares(int n) {
Arrays.fill(dp,-1);
return numSquaresHelper(n);
}
public int numSquaresHelper(int n) {
if(n
var numSquares = function(n) {
let ans = 0
let leastperfectSquares = 0
for(let i = 2;i