MENU

Fun & Interesting

Find the duplicate number (LeetCode 287) | Full solution with different methods | Study Algorithms

Nikhil Lohia 47,362 lượt xem 3 years ago
Video Not Working? Fix It Now

To see more videos like this, you can buy me a coffee: https://www.buymeacoffee.com/studyalgorithms

You are given an array of integers, that have all unique values except one integer that may be duplicated more than 2 times. You just need to return this value. Seems like a very easy problem but it offers you a lot of scope. There can be several different solutions possible based upon the requirements. This video explores a brute force method, a time efficient method and a space efficient method. All along with easy to understand visuals and animations.

Chapters:
00:00 - Intro
01:27 - Problem statement and description
03:26 - Brute Force approach to find the duplicate number
05:13 - Find the duplicate number using sorting
07:07 - Find the duplicate number using a HashSet
10:16 - Time and space efficient solution to find duplicate
14:14 - Dry-run of code
16:50 - Final Thoughts

Actual problem on LeetCode: https://leetcode.com/problems/find-the-duplicate-number/

📚 Links to topics I talk about in the video:
Detect Cycle Start in Linked List: https://youtu.be/95ZfuoSAUPI
Linked List Introduction: https://youtu.be/lrXpTVEAXCM
Brute Force Method: https://youtu.be/kdTpUjd71G8
Quick Sort: https://youtu.be/2SRzQEOaLYw
Time Complexity: https://youtu.be/-MJ7EIV57dI
Playlist on Linked Lists: https://www.youtube.com/playlist?list=PLFdAYMIVJQHN6J5-OCh7pbG0o8WHC9so3

📘 A text based explanation is available at: https://studyalgorithms.com

Code on Github: https://github.com/nikoo28/java-solutions/blob/master/src/main/java/leetcode/medium/FindTheDuplicateNumber.java
Test-cases on Github: https://github.com/nikoo28/java-solutions/blob/master/src/test/java/leetcode/medium/FindTheDuplicateNumberTest.java

📖 Reference Books:
Starting Learn to Code: https://amzn.to/36pU0JO
Favorite book to understand algorithms: https://amzn.to/39w3YLS
Favorite book for data structures: https://amzn.to/3oAVBTk
Get started for interview preparation: https://amzn.to/39ysbkJ

🎥 My Recording Gear:
Recording Light: https://amzn.to/3pAqh8O
Microphone: https://amzn.to/2MCX7qU
Recording Camera: https://amzn.to/3alg9Ky
Tablet to sketch and draw: https://amzn.to/3pM6Bi4
Surface Pen: https://amzn.to/3pv6tTs
Laptop to edit videos: https://amzn.to/2LYpMqn


💻 Get Social 💻
Follow on Facebook at: https://www.facebook.com/studyalgos
Follow on Twitter at: https://www.twitter.com/studyalgorithms
Follow on Tumblr at: https://studyalgos.tumblr.com/
Subscribe to RSS feeds: https://studyalgorithms.com/feed/
Join fan mail: http://eepurl.com/g9Dadv

#leetcode #programming #linkedlists

Comment