ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

Smallest Number in Infinite Set

Автор: Deepti Talesra

Загружено: 2025-02-09

Просмотров: 2012

Описание: 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...

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
Smallest Number in Infinite Set

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

Remove Linked List Elements #leetcode

Remove Linked List Elements #leetcode

Successful Pairs of Spells and Potions - LeetCode 2300 - Python #leetcode #leetcode75

Successful Pairs of Spells and Potions - LeetCode 2300 - Python #leetcode #leetcode75

Delete Node in a BST - LeetCode 450 - Python #leetcode #leetcode75

Delete Node in a BST - LeetCode 450 - Python #leetcode #leetcode75

Total Cost to Hire K Workers #leetcode #leetcode75

Total Cost to Hire K Workers #leetcode #leetcode75

Наименьшее число в бесконечном множестве | Упорядоченное множество | Приоритетная очередь | Самый...

Наименьшее число в бесконечном множестве | Упорядоченное множество | Приоритетная очередь | Самый...

Number of Provinces #leetcode #leetcode75 #dfs

Number of Provinces #leetcode #leetcode75 #dfs

What IS a Number? As Explained by a Mathematician

What IS a Number? As Explained by a Mathematician

How I would learn Leetcode if I could start over

How I would learn Leetcode if I could start over

Неизбежная эволюция SQLite

Неизбежная эволюция SQLite

Измените порядок маршрутов, чтобы все пути вели в город Zero #leetcode #leetcode75

Измените порядок маршрутов, чтобы все пути вели в город Zero #leetcode #leetcode75

Гипердействительная система чисел (и упрощение предельных вычислений)

Гипердействительная система чисел (и упрощение предельных вычислений)

Нечестный способ, которым я добился успеха в Leetcode

Нечестный способ, которым я добился успеха в Leetcode

The Windows 11 Disaster That's Killing Microsoft

The Windows 11 Disaster That's Killing Microsoft

What is a Number? - Numberphile

What is a Number? - Numberphile

Reverse Linked List - LeetCode  206 - Python (Iterative and Recursive)

Reverse Linked List - LeetCode 206 - Python (Iterative and Recursive)

Уродливое число II — Leetcode 264 — Python

Уродливое число II — Leetcode 264 — Python

Минимальная стоимость подъёма по лестнице — динамическое программирование — Leetcode 746 — Python

Минимальная стоимость подъёма по лестнице — динамическое программирование — Leetcode 746 — Python

Find the Number of Distinct Colors Among the Balls | Leetcode 3160

Find the Number of Distinct Colors Among the Balls | Leetcode 3160

Microsoft begs for mercy

Microsoft begs for mercy

Rotting Oranges - LeetCode 994 - Python #bfs #leetcode #leetcode75

Rotting Oranges - LeetCode 994 - Python #bfs #leetcode #leetcode75

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]