I have always appreciated this guy for daily solutions of Leetcode. He may continue to do it
@ayanpatel_983 ай бұрын
waiting for LC.664 Strange Printer
@jeremytsai69873 ай бұрын
I'm not sure why you haven't updated in a while, but I hope everything is going well for you.
@rishikantshukla47543 ай бұрын
Why are you not uploading the videos ?
@tranminhquang45413 ай бұрын
It's simply the sum of all prime factors of the number n . For example , n = 24 = 2 * 2 * 2 * 3 . So we need 2 + 2 + 2 + 3 = 9 steps.
@firezdog3 ай бұрын
blows your mind when you realize this
@Dyxuki3 ай бұрын
waiting for LC.664 :D
@user-tt3lb1yy6i3 ай бұрын
NEETCODE CHAAN!!!! SAVE ME!!!
@pratyushthakur84783 ай бұрын
I got till using dp but started overthinking after that and fumbled. leetcode L streak strong
@ParodyCSEDept3 ай бұрын
I am being honest.. Had I not known about DP, I might have solved this in O(sqrt(n)) time and O(1) space but here I am getting excited over solving this in O(n^2) time and O(n) space :)
@greatfate3 ай бұрын
always think of greedy before DP brother
@ParodyCSEDept3 ай бұрын
@@greatfate Yeah I'll keep that in mind
@alperkaya89193 ай бұрын
I just used recursion, not even dp or memoization. It gives you straight up answer without thinking much. And lesser you think it will be easier for you to implement in an interview.
@DeveshSoni-u6s3 ай бұрын
I did it by utilizing the sum of Prime Factors Imagine 12 12=2*2*3 so answer is 2+3+2=7 if n=2-->2 if n=5-->5 no dp needed
@АльбусДамблодр3 ай бұрын
come back solving leetcode daily problems pllls
@addiegupta3 ай бұрын
Todays (20th Augs) daily challenge so annoying even NeetCode skipped it
@DNKF3 ай бұрын
He has done it.
@addiegupta3 ай бұрын
@@DNKF ah i see he has done it earlier 1 year ago
@omega_sine3 ай бұрын
I managed to derive the prime factor solution by myself, pretty proud of that. But the dp solution is also good to know.
@Apeuda3 ай бұрын
wow nice! for me i did the dp solution myself. tho i still dont get how the prime factorization solution works. all i know is if n is a prime number, then the result is going to be n
@meetverma48123 ай бұрын
always remember wherever we can use memoization there's mostly (if not always ) a dp solution that can be computed with O(N) space...
@shahperzia11213 ай бұрын
@@Apeuda prime factorization solution is same as dp. For example 210 = 1 * 2 * 3 * 5 * 7 DP solution 1 -> 2 : 2 steps (prime) 2 -> 6: 3 steps (prime) 6 -> 30 : 5 steps (prime) 30 -> 210 : 7 steps (prime) answer = 2 + 3 + 5 + 7 = sum( prime factors of 210 ) = 17
@shreyasevelar85613 ай бұрын
Hey! Have you stopped this series where you solve the daily challenges?
@vayunjain92893 ай бұрын
We could find the largest factor(f) of n and add n/f to and the ans and then set n = f. Do this while n>1 and if n is prime then return ans+n. This got accepted in leetcode.
@FlexGC3 ай бұрын
What? Wouldn't the largest factor of n just be n×1 which means it's n?
@33galactus3 ай бұрын
Interesting. Please share your code.
@vayunjain92893 ай бұрын
@@FlexGCSorry I meant largest factor
@vayunjain92893 ай бұрын
@@33galactus class Solution { public: int minSteps(int n) { if(n == 1) return 0; int ans = 0; while(n>1){ int temp = n; int factor = -1; for(int i=2;i*i
@nihalbhandary1623 ай бұрын
yes I used the same approach. I find the largest factor starting from smaller one. def minSteps(self, n: int) -> int: def helper(n,g): if n==1: return 0 while n%g!=0: g+=1 div=n//g if div>1: return helper(div,g) + g return g return helper(n,2)
@guruprasath28623 ай бұрын
We need your help
@АльбусДамблодр3 ай бұрын
bro we really need yoouuu(((
@pastori26723 ай бұрын
wow really didnt expect you to skip the most optimal solution, especially one that involves math
@aizad786iqbal3 ай бұрын
please make a video on math approach too, if possible
@ShinAkuma3 ай бұрын
Just do this bro. public int minSteps(int n) { if (n == 1) { return 0; } int count = 0; int factor = 2; while (n > 1) { while (n % factor == 0) { n = n/factor; count += factor; } ++factor; } return count; }
@michaelroditis19523 ай бұрын
Just because I like shorter solutions I must say something, the first if statement is redundant. If n is equal to 1, then 0 will be returned nonetheless
@ShinAkuma3 ай бұрын
@@michaelroditis1952 true. I didn't care much after it got accepted.
@michaelroditis19523 ай бұрын
@@ShinAkuma yeah and it would work the same so no need
@krupakarreddy17583 ай бұрын
The DP solution just went over my head 🙃🤯 .How do you even come up with these DP solutions..sometimes they are very hard to understand and forget about even trying to think the approach😵💫
@sarmohanty3 ай бұрын
he doesn't always figure them out... he looks at the editorial
@firezdog3 ай бұрын
I have to admit i have a very spotty record solving DP problems I haven't already seen too haha
@krupakarreddy17583 ай бұрын
@@sarmohanty yeah maybe... I tried debugging the code... But didn't understand a little also🥲
@AJK-a2j00k43 ай бұрын
The second part was 🔥🔥🔥
@meetverma48123 ай бұрын
I came with the memoization solution and knew there must be a dp solution as well but could figure it out but you gave me the idea on the drawing board and eventually I solved it in linear space... Big thumbs up for ur explanation navneet 💚
@m.m.m.41983 ай бұрын
I really enjoy your video! I'm considering getting Neetcode Pro at the moment. Is there any discount code available at all right now? :)
@abdulamaan47843 ай бұрын
i brute forced the exponential soln without caching, and just tried to speed it up with compiler flags and other hacks, and leetcode actually accepted it XD i did go back and try memoisation, which my friend helped me out with
@stoppls17093 ай бұрын
lmao, worked for me without doing anything extra beats 5% too xD
@MP-ny3ep3 ай бұрын
Thank you so much ! I don't think the DP problem is that intuitive.
@heartout9757Ай бұрын
I am trying to understand the logic for dp[j]+i/j, I understood why we are considering dp[j], but when we are adding i/j this means we can paste i/j times to the original word. But what I am missing over here is we need to copy the word first so it would result in dp[j]+i/j+1. I dont know where am I missing since it works for dp[j]+i/j. Help me understand this
@_night_spring_3 ай бұрын
I wonder why you didn't give the simplest approach doing factorisation
@zweitekonto96543 ай бұрын
Simplest in coding. Not simplest to come up with and prove why it works too.
@CS_n00bАй бұрын
do we really need i to iterate over all items, cant we just stop at n//2
@mrvinyllad253 ай бұрын
I've managed to get close to the DP solution but i'm just not sure why we need to copy and paste as a single operation (and hence yielding +2 to the result when taking this path in the backtracking process. Is it to not allow double pasting? (at least following this path for me yielded 4 operations for when n = 5, like we start with 'A' and 'A': and 1 as the number of steps taken so far (first operation for n = 1 is copy): step 2: paste, now we have screen = 'AA' and copy_area = 'A' step 3: copy, now we have screen = 'AA' and copy_area = 'AAA' step 4: paste, now we have screen = 'AAAAA' and copy_area = 'AAA' - so, 5 AAAA in the screen. i think reading my explanation i misinterpreted the question. Copy gets overwritten with what is in the screen, not concatenating with what was there :p
@firezdog3 ай бұрын
it is to prevent going down useless paths where we copy and copy and copy again. If we apply copying as a single operation, we know it is never directly going to a node with a better answer. So we are just collapsing the sequence (current_node => copy_node => paste_node) into (current_node => copy_node). In essence, there's never a path that goes through a copy node that doesn't immediately visit a paste node afterwards (or not one that we're interested in).
@yang58433 ай бұрын
I feel like I've seen this problem before
@chuyi-crack62903 ай бұрын
feel likes the min num coins DP
@chickennoir6913 ай бұрын
Thank you so much
@sanooosaiАй бұрын
thank you
@faaeizkhan61343 ай бұрын
everywhere i go people are saying they were able to come up with the soln, and here i am struggling T_T.......................................
@FlexGC3 ай бұрын
Why would count be count * 2 and not count + 2 for copying abd pastkng? Oh the count represents the number of a's on the screen. Not the number of moves.
@Nischal.shetty023 ай бұрын
while pasting the number of 'A' gets doubled for example - first well have 'A' then after copy and paste well have 'AA' which is 2 times the initial number of A's(ie count*2 => 1*2) then next time we copy and paste well have 'AAAA' which is 2 times the previous count(ie count*2 => 2*2) so youre basically doubling the previous count each time
@gowthamtg48843 ай бұрын
did he figure out the second explanation himself ?
@alexandermelocco81403 ай бұрын
wth i was literally doin this problem for the first time
@mohammedfirasathussain23293 ай бұрын
congrats
@069_Souvik3 ай бұрын
Don't know why my memoized solution is taking more time than recursion
@elisey47703 ай бұрын
probably because you used a hashmap and on lower n’s, hashmap is pretty inefficient. When i changed hashmap to an array, my runtime became significantly better
@069_Souvik3 ай бұрын
@@elisey4770 I see
@chaitanyasharma62703 ай бұрын
c# code public class Solution { int n; public int MinSteps(int n) { if(n==1)return 0; this.n=n; return 1+minSteps(1,1); } public int minSteps(int currA, int copied){ if(currA == n){ return 0; } if(currA > n){ return 10000; } //copy and paste int newCopy = currA; int copy = 2 + minSteps(currA + newCopy, newCopy); //no copy keep pasting int noCopy = 1 + minSteps(currA + copied, copied); return Math.Min(copy, noCopy); } }
@DeathSugar3 ай бұрын
bruh. there's easy solution with pretty much log time and space 1. composite numbers takes count(n/d) + count(d) where d - is biggest divisor of n less then or equal to sqrt(n) 2. the rest take exactly n times class Solution: def minSteps(self, n: int) -> int: if n == 1: return 0 upper_bound = int(floor(sqrt(n))) for i in reversed(range(2, upper_bound+1)): # look from biggest to lowest if n % i == 0: return self.minSteps(n//i) + self.minSteps(i) return n