I would love a better explanation of num * 2 argument for the last for loop
@saianishmalla2646 Жыл бұрын
The basic idea is that when you get to a number where dp[num] = True that mean that the number itself IS a prime number. Since it is a prime number we would not want to set dp[current number] = False. Now by starting the loop from current number * 2 we skip the number itself and look at all its multiples Say number = 7 (we know 7 is prime but all of 7's multiples must be true) 7 * 1 --> Is prime (do not change DP) 7 * 2 --> Not prime (change to dp[7*2] = False) 7 * 23--> Not prime (change to dp[7*3] = False) ... and so on, but we just skip 7*1
@rhodabaruch4 Жыл бұрын
@@saianishmalla2646 Thanks for making that clearer for me! I've appreciated your videos! They are helping me in my prep a lot!
@anirudh494610 ай бұрын
instead of num*2 you can take num*num
@classicmakersmusic63442 ай бұрын
This solution does not pass the time complexity test anymore in leetcode