LeetCode 220: Contains Duplicate III - Interview Prep Ep 47
LeetCode 220. Contains Duplicate III: https://leetcode.com/problems/contains-duplicate-iii/
⭐ Support my channel and connect with me:
https://www.youtube.com/channel/UCPL5uAbYQ40HwAdOe4ikI0w/join
Solution explained:
1. We'll need a data structure that could give us efficient access for operations like: get, insert, delete for a given size of k elements, we want it better than a linear time complexity - a self balancing binary search tree comes into picture;
2. We'll still use a set to find the duplicate, and the set size will be k as well, however, each time:
a. we'll quickly peek the maximum element in the set that is smaller than the current element that we are iterating on, check if their difference is smaller than or equal to t, if so, then we could happily return true, if not,
b. then we check the minimum element in this given set that is bigger than the current element that we are iterating on, check if their difference is smaller than or equal to t, if so, then we could happily return true, if not,
c. we'll add this element into the set;
d. then we'll do a check to make sure the size of the set is still within k, if not, we'll remove the oldest element from this set.
Time complexity: O(nlog(min(n, k)))
Space complexity: O(min(n, k))
// TOOLS THAT I USE:
○ Memory Foam Set Keyboard Wrist Rest Pad - https://amzn.to/3cOGOAj
○ Electric Height Adjustable Standing Desk - https://amzn.to/2S9YexJ
○ Apple Magic Keyboard (Wireless, Rechargable) - https://amzn.to/36gy5FJ
○ Apple Magic Trackpad 2 (Wireless, Rechargable) - https://amzn.to/36ltimu
○ Apple MacBook Pro - https://amzn.to/30iSvKE
○ All-In One Printer - https://amzn.to/34etmSi
○ Apple AirPods Pro - https://amzn.to/2GpVYQf
○ My new favorite Apple Watch - https://amzn.to/2EIIUFd
// MY FAVORITE BOOKS:
○ Introduction to Algorithms - https://amzn.to/36hxHXD
○ Designing Data-Intensive Applications - https://amzn.to/2S7snOg
○ Head First Java - https://amzn.to/2ScLDKa
○ Design Patterns - https://amzn.to/2SaGeU2
Follow me on Github for complete LeetCode solutions: https://github.com/fishercoder1534/Leetcode
Support me on Patreon: https://www.patreon.com/fishercoder
My ENTIRE Programming Equipment and Computer Science Bookshelf:
https://www.amazon.com/shop/fishercoder
And make sure you subscribe to my channel!
Your comments/thoughts/questions/advice will be greatly appreciated!
#softwareengineering #leetcode #algorithms #coding #interview #SDE #SWE #SiliconValley #programming #datastructures
Видео LeetCode 220: Contains Duplicate III - Interview Prep Ep 47 канала Fisher Coder
⭐ Support my channel and connect with me:
https://www.youtube.com/channel/UCPL5uAbYQ40HwAdOe4ikI0w/join
Solution explained:
1. We'll need a data structure that could give us efficient access for operations like: get, insert, delete for a given size of k elements, we want it better than a linear time complexity - a self balancing binary search tree comes into picture;
2. We'll still use a set to find the duplicate, and the set size will be k as well, however, each time:
a. we'll quickly peek the maximum element in the set that is smaller than the current element that we are iterating on, check if their difference is smaller than or equal to t, if so, then we could happily return true, if not,
b. then we check the minimum element in this given set that is bigger than the current element that we are iterating on, check if their difference is smaller than or equal to t, if so, then we could happily return true, if not,
c. we'll add this element into the set;
d. then we'll do a check to make sure the size of the set is still within k, if not, we'll remove the oldest element from this set.
Time complexity: O(nlog(min(n, k)))
Space complexity: O(min(n, k))
// TOOLS THAT I USE:
○ Memory Foam Set Keyboard Wrist Rest Pad - https://amzn.to/3cOGOAj
○ Electric Height Adjustable Standing Desk - https://amzn.to/2S9YexJ
○ Apple Magic Keyboard (Wireless, Rechargable) - https://amzn.to/36gy5FJ
○ Apple Magic Trackpad 2 (Wireless, Rechargable) - https://amzn.to/36ltimu
○ Apple MacBook Pro - https://amzn.to/30iSvKE
○ All-In One Printer - https://amzn.to/34etmSi
○ Apple AirPods Pro - https://amzn.to/2GpVYQf
○ My new favorite Apple Watch - https://amzn.to/2EIIUFd
// MY FAVORITE BOOKS:
○ Introduction to Algorithms - https://amzn.to/36hxHXD
○ Designing Data-Intensive Applications - https://amzn.to/2S7snOg
○ Head First Java - https://amzn.to/2ScLDKa
○ Design Patterns - https://amzn.to/2SaGeU2
Follow me on Github for complete LeetCode solutions: https://github.com/fishercoder1534/Leetcode
Support me on Patreon: https://www.patreon.com/fishercoder
My ENTIRE Programming Equipment and Computer Science Bookshelf:
https://www.amazon.com/shop/fishercoder
And make sure you subscribe to my channel!
Your comments/thoughts/questions/advice will be greatly appreciated!
#softwareengineering #leetcode #algorithms #coding #interview #SDE #SWE #SiliconValley #programming #datastructures
Видео LeetCode 220: Contains Duplicate III - Interview Prep Ep 47 канала Fisher Coder
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![LeetCode 217 & 219: Contains Duplicate I & II - Interview Prep Ep 46](https://i.ytimg.com/vi/SFMCxqSeM94/default.jpg)
![LeetCode 1663. Smallest String With A Given Numeric Value - Interview Prep Ep 111](https://i.ytimg.com/vi/o3MRJfsoUrw/default.jpg)
![What no one tells you about coding interviews (why leetcode doesn't work)](https://i.ytimg.com/vi/LQFsEwcCO1E/default.jpg)
![](https://i.ytimg.com/vi/JVeBwG7KRbM/default.jpg)
![Contains Duplicate iii | LeetCode 220 | C++, Python](https://i.ytimg.com/vi/jRKEp4IYY3E/default.jpg)
![LeetCode 234: Palindrome Linked List - Interview Prep Ep 63](https://i.ytimg.com/vi/bOGh_3MTrdE/default.jpg)
![LeetCode 1772. Sort Features by Popularity - Interview Prep Ep 118](https://i.ytimg.com/vi/5629LqqeLAM/default.jpg)
![Leetcode - Contains Duplicate III (Python)](https://i.ytimg.com/vi/klCY3k70A50/default.jpg)
![How I Passed Coding Interviews at Facebook, Google, Lyft, Bloomberg](https://i.ytimg.com/vi/lDTKnzrX6qU/default.jpg)
![LeetCode 56. Merge Intervals (Algorithm Explained)](https://i.ytimg.com/vi/qKczfGUrFY4/default.jpg)
![LeetCode 21: Merge Two Sorted Lists RECURSIVELY - Interview Prep Ep 62](https://i.ytimg.com/vi/bdWOmYL5d1g/default.jpg)
![Leetcode Solution | 217. Contains Duplicates | Javascript | 2/75](https://i.ytimg.com/vi/tVr0xWxnX14/default.jpg)
![LeetCode 153. Find Minimum in Rotated Sorted Array (Algorithm Explained)](https://i.ytimg.com/vi/IzHR_U8Ly6c/default.jpg)
![Number of Islands - LeetCode 200 Python](https://i.ytimg.com/vi/uDB5QXTqMn0/default.jpg)
![LeetCode Interview Problem - Merge Sorted Array](https://i.ytimg.com/vi/zp4huR7LN6M/default.jpg)
![Amazon Coding Interview Question - Rotate Image](https://i.ytimg.com/vi/IdZlsG6P17w/default.jpg)
![Contains Duplicate II | LeetCode 219 | Google Coding Interview Tutorial](https://i.ytimg.com/vi/Fmmzy5Jg-Mw/default.jpg)
![Letter Combinations of a Phone Number - Backtracking - Leetcode 17](https://i.ytimg.com/vi/0snEunUacZY/default.jpg)
![LeetCode 48: Rotate Image | Rotate N*N Matrix | Rotate a Square - Interview Prep Ep 54](https://i.ytimg.com/vi/gCciKhaK2v8/default.jpg)
![LeetCode 104. Maximum Depth of Binary Tree - Interview Prep Ep 65](https://i.ytimg.com/vi/dvmoHr5cN80/default.jpg)