Count Primes | LeetCode 204 | Theory + Python code (Sieve of Eratosthenes explained)

  Рет қаралды 1,078

Sai Anish Malla

Sai Anish Malla

Күн бұрын

Пікірлер: 7
@ishayadav001
@ishayadav001 Жыл бұрын
Long time! Great video!!
@rhodabaruch4
@rhodabaruch4 Жыл бұрын
I would love a better explanation of num * 2 argument for the last for loop
@saianishmalla2646
@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
@rhodabaruch4 Жыл бұрын
@@saianishmalla2646 Thanks for making that clearer for me! I've appreciated your videos! They are helping me in my prep a lot!
@anirudh4946
@anirudh4946 10 ай бұрын
instead of num*2 you can take num*num
@classicmakersmusic6344
@classicmakersmusic6344 2 ай бұрын
This solution does not pass the time complexity test anymore in leetcode
@melbalesch
@melbalesch Жыл бұрын
Promo sm 🤦
Additive Number | LeetCode 306 | Theory + Python code
19:12
Sai Anish Malla
Рет қаралды 1,4 М.
L6. Sieve of Eratosthenes | Maths Playlist
18:27
take U forward
Рет қаралды 74 М.
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
Count Primes (Sieve of Eratosthenes) | Leetcode - 204
10:46
Algorithms Made Easy
Рет қаралды 26 М.
Count Primes | LeetCode 204 | Google Coding Interview Tutorial
13:34
Terrible Whiteboard
Рет қаралды 9 М.
Daily Temperatures| LeetCode 739 | Theory + Python code
17:45
Sai Anish Malla
Рет қаралды 698
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 244 М.
Generate Parentheses | LeetCode 22 | Theory + Python code
17:38
Sai Anish Malla
Рет қаралды 1 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
Sieve of eratosthenes
9:50
Techdose
Рет қаралды 58 М.