News for hackers. Stuff that matters.
Re:The World Excel Championship is being broadcast on ESPN by vitiral on Thursday August 11, 2022 @09:14AM (#32425108)
That problem is a terrible interview question, mainly because it's completely trivial with O(n) memory (just use a Set), but requires a different branch of comp sci at O(1).

Personally I also feel that any question that needs an O(1) memory when you _start with an array_ is disingenuous. O(1) memory was used for things like tape storage, where N was some huge external storage. If you already have an array, then the chance you don't have double that memory are dibcus.

Re:The World Excel Championship is being broadcast on ESPN by sanedigital on Thursday August 11, 2022 @10:13AM (#32425898)
Not sure I agree. It's very simple if you look at what's "wrong" with the input: it has a duplicated number, which means there's a "right" version of it without. That right version is just the count from 1->n. Once you see that, you can see that all you have to do is sum each list and calculate the difference.
Re:The World Excel Championship is being broadcast on ESPN by kd5bjo on Thursday August 11, 2022 @10:18AM (#32426005)
This algorithm fails in the case that the duplicated number appears more than twice in the list, which is explicitly allowed by the problem statement.
Re:The World Excel Championship is being broadcast on ESPN by sanedigital on Thursday August 11, 2022 @01:11PM (#32428819)
It’s not, on Leetcode. I submitted it as an answer and it worked. In the case where the number is repeated more than once (m times), you have an array of n+m elements. Divide the sum by m, subtract, problem solved.
Re:The World Excel Championship is being broadcast on ESPN by kd5bjo on Thursday August 11, 2022 @02:10PM (#32429618)
In that case, their test suite doesn’t cover all relevant cases. Consider nums = [1,1,1,1,4]: There are 5 elements, so n=4, and all elements are within the range [1,4]; only the 1 is duplicated. This fulfills all of the listed requirements.

The actual sum is 8, and the 4th triangular number is 10, so the duplicated number according to your algorithm must be -2 (or some fraction thereof, depending on how you calculate m).

Re:The World Excel Championship is being broadcast on ESPN by kd5bjo on Thursday August 11, 2022 @10:16AM (#32425963)
The LeetCode version doesn't require linear time, and caps the number of elements to 10^5, so the brute-force O(n^2) time solution seems perfectly acceptable.
Re:The World Excel Championship is being broadcast on ESPN by dullcrisp on Thursday August 11, 2022 @10:30AM (#32426231)
Tried it with a simple loop, got time limit exceeded unfortunately.