Hey sean , Thank you for sharing this problem. I really like it. After seeing the problem des. , i came up with this solution. Is this a better approach?
The code is very readable, which is good, but indexOf() is an O(n) time function by itself, so the overall time complexity becomes O(n^2), and the space complexity becomes O(n) since you're creating a new array (original).
Hey sean , Thank you for sharing this problem. I really like it. After seeing the problem des. , i came up with this solution. Is this a better approach?
const findMissing = arr => {
const orginal = Array.from({length:arr.length+1} , (_,i) => i);
return orginal.filter(v => arr.indexOf(v) === -1)[0]
}
Thanks in advance :)
The code is very readable, which is good, but indexOf() is an O(n) time function by itself, so the overall time complexity becomes O(n^2), and the space complexity becomes O(n) since you're creating a new array (original).
Thank you for explaining... Even though I'm not good at Big O notation, I can understand ur explanation.