Smallest Number in Infinite Set #leetcode #leetcode75
Explaining Smallest Number in Infinite Set from leetcode in Python! ahhhhh I accidentally deleted the part in which I do a walkthrough of the code with an example (like we do in every video!) so i'm writing it below in case you are interested:) Input example: ["SmallestInfiniteSet", "addBack", "popSmallest", "popSmallest", "addBack", "popSmallest", "popSmallest"] [[], [4], [], [], [1], [], []] Outputs after each operation: 1. Initialize for the call to SmallestInfiniteSet self.smallest = 1 self.removed = set() Now we call: 2. addBack with 4 However going in the first if condition we see the condition is false - 4 is not in self.removed as it is currently empty. So we don't go in the if and since there are no more lines of code in the function we exit. Current state: self.smallest = 1; self.removed = set() 3. popSmallest() Current state: self.smallest = 1; self.removed = set() Going in the function, we set ret to be 1 (line 9). Then we add 1 to the self.removed set (line 10). self.removed = set(1) Increase self.smallest to be 2 and go in the while loop (line 11). While self.smallest (2) in self.removed, that is false 2 is not in there, so we exit and return our ret variable of 1. Current state: self.smallest = 2; self.removed = set(1) 4. popSmallest() Going in the function, we set ret to be self.smallest so ret = 2 (line 9). Then we add 2 to the self.removed set (line 10). self.removed = set(1,2) Increase self.smallest by one - to be 3 and go in the while loop (line 11). While self.smallest (3) in self.removed, that is false 3 is not in there, so we exit and return our ret variable of 2. Current state: self.smallest = 3; self.removed = set(1,2) 5. addBack with 1 If num (1) in self.removed: (this is true), so we go into the if condition and remove 1 from the set of self.removed. *self.removed = set(2)*. We check if 1 is less than self.smallest (3) this is true, so we set self.smallest to be 1. Current state: self.smallest = 1; self.removed = set(2) 6. popSmallest() Going in the function, we set ret = 1 (line 9). Then we add 1 to the self.removed set (line 10). self.removed = set(1,2) Increase self.smallest to be 2 and go in the while loop (line 11). While self.smallest (2) in self.removed, that is true 2 is in there, so we increase self.smallest to be 3 and go back into the while loop. *self.smallest = 3*. We check: While self.smallest (3) in self.removed, that is not true 3 is not in there, so we exit and return our ret variable of 1. Current state: self.smallest = 3; self.removed = set(1,2) And that's it!! Lemme know if you have any questions:)))) LeetCode 2336 Code: https://github.com/deepti-talesra/Lee... @0:53 - Example + Explanation @3:33 - Code @6:01 - Space and Time Complexity Music: Bensound Lemme know if you have any comments or questions!:))) Socials: / deeptitalesra / deeptitalesra Playlists: • Graph • Binary • Matrix • Linked List • Dynamic Programming • String • Tree • Array's • BLIND 75 - Interview Questions • LeetCode Coding Interview Questions - Python • Top Interview 150 If you found this helpful, check out my channel for even **MORE VIDEOS**!!:)) https://www.youtube.com/c/DEEPTITALES... Give it a shot yourself - https://leetcode.com/problems/smalles...

Remove Linked List Elements #leetcode

How I would learn Leetcode if I could start over

Smallest Number in Infinite Set | Ordered Set | Priority Queue | Fastest Approach | Leetcode 2336

How do I choose the "best" coding strategy? | The Reality of Python Part 2

Construct Smallest Number From DI String - Leetcode 2375 - Python

What AI does to the minds of novice coders

Smallest Number in Infinite Set | 3 Approaches | (MICROSOFT) | Leetcode 2336 | Live Code 🧑🏻💻

Smooth-Maximum, the most useful function

Creator of C++: Bell Labs, Negative Overhead Abstraction, Mistakes | Bjarne Stroustrup

The Strange Math That Predicts (Almost) Anything

All 7 Dimensions Explained in Detail (From 0D to Infinity)

LeetCode was HARD until I Learned these 15 Patterns

Terence Tao: Nobody Understands Why AI Actually Works

Abstract Black and White wave pattern| Height Map Footage| 3 hours Topographic 4k Background

Math Every Programmer ACTUALLY Needs

Unbelievable Smart Worker & Hilarious Fails | Construction Compilation #8 #adamrose #smartworkers

She’s 12. She Sings Aretha Franklin… Until Simon TELLS Her to Do It Acapella! 😳
![PINK & ORANGE GRADIENT IN HD [3 HOURS]](https://i.ytimg.com/vi/6ih8zppfQSQ/hqdefault.jpg?sqp=-oaymwE9CNACELwBSFryq4qpAy8IARUAAAAAGAElAADIQj0AgKJDeAHwAQH4Af4JgALQBYoCDAgAEAEYfyAsKBMwDw==&rs=AOn4CLDvw6mQM98bfl572zfE7r4GdUG8dg)
PINK & ORANGE GRADIENT IN HD [3 HOURS]

Rotting Oranges - Leetcode 994 - Python

