Amazon Coding Interview Question - First Missing Positive (LeetCode)
Here is a step by step explanation of a hard array problem asked at Amazon!
►Support me on Patreon: https://www.patreon.com/michaelmuinos
Join the Discord channel by becoming a supporter on my Patreon!
In this Discord channel, you will be able to...
1. Contact me directly for interview prep advice, tech questions, project ideas, etc.
2. Discuss interview experiences with other members
3. Discuss technical questions with other members
4. Find mock interview partners & more!
►Follow me on Twitter: https://twitter.com/MichaelMuinos
►Follow me on Github: https://github.com/MichaelMuinos
In this video, I go over the problem "First Missing Positive". This is a hard problem asked at many tech companies including Amazon, Bloomberg, Google, and many more. This problem would be considered an easy/medium if there wasn't a restriction that we must have a solution with constant extra space.
In the brute force approach, we could add all of the numbers we have in our input to a set. Then, we perform a loop from 1 to N where N is the number of elements we have in our input and check if the number is present in the set. If the number we are on is not in the set, we found our first missing positive. The brute force approach involved a linear time AND space complexity.
Now, in the optimized approach, it takes 3 steps to solve this problem. For step 1, we must convert any negative numbers and numbers greater than N to a 1. This is done to restrict our range of numbers. For step 2, we use the range of numbers as indexes to our array and perform a lookup to swap the sign of the element at the index. This will signify we have seen the positive number without doing any sorting. In the final step, we look for the first non-negative number, if we find one, the index + 1 is the first missing positive; however, if we don't find it, we know the answer will be N + 1.
Видео Amazon Coding Interview Question - First Missing Positive (LeetCode) канала Michael Muinos
►Support me on Patreon: https://www.patreon.com/michaelmuinos
Join the Discord channel by becoming a supporter on my Patreon!
In this Discord channel, you will be able to...
1. Contact me directly for interview prep advice, tech questions, project ideas, etc.
2. Discuss interview experiences with other members
3. Discuss technical questions with other members
4. Find mock interview partners & more!
►Follow me on Twitter: https://twitter.com/MichaelMuinos
►Follow me on Github: https://github.com/MichaelMuinos
In this video, I go over the problem "First Missing Positive". This is a hard problem asked at many tech companies including Amazon, Bloomberg, Google, and many more. This problem would be considered an easy/medium if there wasn't a restriction that we must have a solution with constant extra space.
In the brute force approach, we could add all of the numbers we have in our input to a set. Then, we perform a loop from 1 to N where N is the number of elements we have in our input and check if the number is present in the set. If the number we are on is not in the set, we found our first missing positive. The brute force approach involved a linear time AND space complexity.
Now, in the optimized approach, it takes 3 steps to solve this problem. For step 1, we must convert any negative numbers and numbers greater than N to a 1. This is done to restrict our range of numbers. For step 2, we use the range of numbers as indexes to our array and perform a lookup to swap the sign of the element at the index. This will signify we have seen the positive number without doing any sorting. In the final step, we look for the first non-negative number, if we find one, the index + 1 is the first missing positive; however, if we don't find it, we know the answer will be N + 1.
Видео Amazon Coding Interview Question - First Missing Positive (LeetCode) канала Michael Muinos
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![🔴 Amazon Interview Question - Missing Smallest Positive Number | Free Giveaway 🎁](https://i.ytimg.com/vi/-lfHWWMmXXM/default.jpg)
![First Missing Positive | Leet code 41 | Theory explained + Python code](https://i.ytimg.com/vi/Znos3MyLOQI/default.jpg)
![Amazon Coding Interview Question - Clone Graph (LeetCode)](https://i.ytimg.com/vi/e5tNvT1iUXs/default.jpg)
![Binary Search : Median of two sorted arrays of different sizes.](https://i.ytimg.com/vi/LPFhl65R7ww/default.jpg)
![(Remade) First Missing Positive | Arrays | Leetcode 41](https://i.ytimg.com/vi/2QugZILS_Q8/default.jpg)
![First Missing Positive | LeetCode 41 | C++, Java, Python | BITWISE operation](https://i.ytimg.com/vi/L1u-R_s2Mok/default.jpg)
![AMAZON CODING INTERVIEW QUESTION - PARTITION LABELS (LeetCode)](https://i.ytimg.com/vi/ED4ateJu86I/default.jpg)
![FACEBOOK CODING INTERVIEW QUESTION - DECODE WAYS (LeetCode)](https://i.ytimg.com/vi/cQX3yHS0cLo/default.jpg)
![What no one tells you about coding interviews (why leetcode doesn't work)](https://i.ytimg.com/vi/LQFsEwcCO1E/default.jpg)
![AMAZON CODING INTERVIEW QUESTION - REORGANIZE STRING](https://i.ytimg.com/vi/zaM_GLLvysw/default.jpg)
![LeetCode 5. Longest Palindromic Substring (Algorithm Explained)](https://i.ytimg.com/vi/y2BD4MJqV20/default.jpg)
![LeetCode Find First and Last Position of Element in Sorted Array Solution Explained - Java](https://i.ytimg.com/vi/bU-q1OJ0KWw/default.jpg)
![Number of Islands - Breadth First Search (LeetCode)](https://i.ytimg.com/vi/HS7t2i9ldmE/default.jpg)
![Coding Interview Problem - Gas Station](https://i.ytimg.com/vi/wDgKaNrSOEI/default.jpg)
![Google Systems Design Interview With An Ex-Googler](https://i.ytimg.com/vi/q0KGYwNbf-0/default.jpg)
![Find missing and repeating number](https://i.ytimg.com/vi/OTkoJOP6m6w/default.jpg)
![GOOGLE CODING INTERVIEW QUESTION - LETTER COMBINATIONS OF A PHONE NUMBER (LeetCode)](https://i.ytimg.com/vi/21OuwqIC56E/default.jpg)
![Solving Amazon's 2020 Most Asked Interview Question](https://i.ytimg.com/vi/Nj2Bpw1KKds/default.jpg)
![FACEBOOK CODING INTERVIEW QUESTION - TASK SCHEDULER (LeetCode)](https://i.ytimg.com/vi/ySTQCRya6B0/default.jpg)
![Facebook Coding Interview Question - sortedSquaredArray](https://i.ytimg.com/vi/4eWKHLSRHPY/default.jpg)