▲ | jonathanlydall 2 days ago | |||||||||||||||||||||||||||||||||||||
This was a go to interview question to be solved in C# at a place I worked at a while back which had developers allocated to projects working on pretty standard line of business systems. The XOR solution was a valid answer, but not the only answer we would have happily accepted. The interview question was chosen such that it's very easy to understand and quick to solve, meaning it would indicate the candidate knew at least the basics of programming in C#. Almost surprisingly, we actually had candidates applying for "senior" level positions who struggled with this. It could be solved in a multitude of ways, e.g: - XOR as above - Use of a HashSet<int> - Use for loop and List which contains a number and its count. - Use LINQ to group the numbers or something and then find the one with the count. As long as what they did worked, it was a "valid" answer, we could then often discuss the chosen solution with the candidate and see how they reacted when we let them know of other valid solutions. It was really great for not being a "one clever trick" question and could act as a springboard to slightly deeper discussions into their technical thought processes and understanding. | ||||||||||||||||||||||||||||||||||||||
▲ | dahcryn a day ago | parent | next [-] | |||||||||||||||||||||||||||||||||||||
you are missing the most obvious one, no? Sum both lists and take the difference, that's the missing number, since the items are guaranteed unique | ||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||
▲ | 2 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||
[deleted] | ||||||||||||||||||||||||||||||||||||||
▲ | TacticalCoder a day ago | parent | prev [-] | |||||||||||||||||||||||||||||||||||||
> "You are given an array A of n - 1 integers" It's an array of integers so it fits in memory (otherwise it wouldn't be called an array). As it fits in memory, n cannot be that big. I'd still ask for more requirements, TopCoder problem style: I want to know how big n can be that the array fits in memory. I didn't know that XOR trick. My solution would be a bit arrays with n bits and two for loops: one to light each bit corresponding to a number and one for loop to find the missing number. And if my bit array doesn't fit in memory, then neither does the array from the problem (and certainly not the HashSet etc.). | ||||||||||||||||||||||||||||||||||||||
|