Missing Number | LeetCode 268 | Amazon Coding Interview Tutorial

Missing Number | LeetCode 268 | Amazon Coding Interview Tutorial

Terrible Whiteboard

4 года назад

4,904 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@TerribleWhiteboard
@TerribleWhiteboard - 10.05.2020 00:59

If there are any videos you'd like me to make or if you have any ideas on how to optimize this solution, let me know!

Ответить
@sharonb3850
@sharonb3850 - 28.07.2021 20:26

Your explanation is on another level entirely... very detailed..well done 👍

Ответить
@stepup8108
@stepup8108 - 27.06.2021 19:48

bro u can also do with xor of [0, 1, 3] ^ [0, 1 , 2, 3]

Ответить
@patrickchan2503
@patrickchan2503 - 04.06.2021 17:18

Hello, this is my alternative solution. Thought I'd share.


const missingNum = (nums) => {
nums = [...new Set(nums)].sort((a,b) => a-b);
const lengthWithMissingNum = nums.length + 1;

for (let i = 0; i <= lengthWithMissingNum; i++) {
if (nums[i] !== i) {
return i;
}
}
}

Ответить
@heyyyyyworld
@heyyyyyworld - 27.03.2021 15:03

var missingNumber = function(nums) {
let numsLen =nums.length
let missingSum =0
let actualSum =numsLen*(numsLen+1)/2
for(let i=0;i<numsLen;i++){
missingSum+=nums[i]
}
return actualSum-missingSum
};

Ответить
@ninjaturtle205
@ninjaturtle205 - 16.06.2020 05:43

how does one figure this trick out with the indices? that difference of the sums of the array, gives this correct output? I think in an interview setting i would only be able to do the solution on leetcode which uses extra space

Ответить
@aritralahiri8321
@aritralahiri8321 - 22.04.2020 10:59

Yet another very beautiful explanation

Ответить