Comments on: Programming Interview Questions 4: Find Missing Element /2011/09/27/programming-interview-questions-4-find-missing-element/?utm_source=rss&utm_medium=rss&utm_campaign=programming-interview-questions-4-find-missing-element Information Retrieval and Machine Learning Mon, 23 Jan 2012 19:14:24 +0000 hourly 1 http://wordpress.org/?v=3.3 By: Arden /2011/09/27/programming-interview-questions-4-find-missing-element/#comment-1338 Arden Wed, 11 Jan 2012 09:52:20 +0000 /?p=521#comment-1338 Yes that's also a good one involving some math. I can write about that as well, thanks for the advice. Yes that’s also a good one involving some math. I can write about that as well, thanks for the advice.

]]>
By: ANONYMOUS /2011/09/27/programming-interview-questions-4-find-missing-element/#comment-1328 ANONYMOUS Tue, 10 Jan 2012 23:31:53 +0000 /?p=521#comment-1328 another interesting question: two numbers are missing. another interesting question: two numbers are missing.

]]>
By: Arden /2011/09/27/programming-interview-questions-4-find-missing-element/#comment-709 Arden Thu, 08 Dec 2011 17:34:01 +0000 /?p=521#comment-709 Thanks a lot for the comment. This is definitely a better solution than adding up, but it may also cause overflow. Imagine large numbers being in front of array1 and small numbers being in the end. And after shuffling array2 contains small numbers in front and large numbers move to the end. Then while subtracting and adding the sum will continually increase, which may lead to overflow. But this is the extreme worst case of course, and probably very unlikely to happen if we have a good shuffle function. Therefore, your approach is much better than simply adding up two arrays first and then subtracting. Because now the intermediate sum increases much slowly. Thanks for noticing. I hope you enjoy the blog.. Thanks a lot for the comment. This is definitely a better solution than adding up, but it may also cause overflow. Imagine large numbers being in front of array1 and small numbers being in the end. And after shuffling array2 contains small numbers in front and large numbers move to the end. Then while subtracting and adding the sum will continually increase, which may lead to overflow. But this is the extreme worst case of course, and probably very unlikely to happen if we have a good shuffle function. Therefore, your approach is much better than simply adding up two arrays first and then subtracting. Because now the intermediate sum increases much slowly. Thanks for noticing. I hope you enjoy the blog..

]]>
By: s /2011/09/27/programming-interview-questions-4-find-missing-element/#comment-708 s Thu, 08 Dec 2011 17:13:01 +0000 /?p=521#comment-708 Hi Arden, What about an alternative for the "adding up" solution as follows. Instead of summing the first and second array, then subtracting from each other, which can cause overflow, we can interleave between adding and subtracting. That is, -take the 1st element in the 1st array - subtract it from the 1st element in the 2nd, - add to the 2nd element in the 1st array, - subtract the result from the 2nd element in the 2nd array. - so on. We have an O(n) in time and O(1) in space. Let me know what you think. Thanks for your wonderful blog Ardan. Hi Arden,

What about an alternative for the “adding up” solution as follows. Instead of summing the first and second array, then subtracting from each other, which can cause overflow, we can interleave between adding and subtracting. That is,

-take the 1st element in the 1st array
- subtract it from the 1st element in the 2nd,
- add to the 2nd element in the 1st array,
- subtract the result from the 2nd element in the 2nd array.
- so on.

We have an O(n) in time and O(1) in space. Let me know what you think. Thanks for your wonderful blog Ardan.

]]>
By: vs /2011/09/27/programming-interview-questions-4-find-missing-element/#comment-228 vs Tue, 04 Oct 2011 02:57:56 +0000 /?p=521#comment-228 Hey Arden, Your solutions to the problem are brilliant! I like how you analyze various approaches and slowly lead the reader to the optimal solution (rather than presenting the reader with the best solution at the beginning). Keep up the good work and thanks so much for sharing! Hey Arden,

Your solutions to the problem are brilliant! I like how you analyze various approaches and slowly lead the reader to the optimal solution (rather than presenting the reader with the best solution at the beginning).

Keep up the good work and thanks so much for sharing!

]]>
By: Arden /2011/09/27/programming-interview-questions-4-find-missing-element/#comment-212 Arden Thu, 29 Sep 2011 23:28:09 +0000 /?p=521#comment-212 Python'da sorun olmayacaktir. Cunku "Python seamlessly converts a number that becomes too large for an integer to a long. And long integers have unlimited precision". Ama Python'da uzun listelerde XOR kisa listelerde sum daha hizli calisiyo. Python’da sorun olmayacaktir. Cunku “Python seamlessly converts a number that becomes too large for an integer to a long. And long integers have unlimited precision”. Ama Python’da uzun listelerde XOR kisa listelerde sum daha hizli calisiyo.

]]>
By: ahmet alp balkan /2011/09/27/programming-interview-questions-4-find-missing-element/#comment-211 ahmet alp balkan Thu, 29 Sep 2011 23:13:32 +0000 /?p=521#comment-211 Peki ya xor yerine sum kullanirsak herhangi bir drawback'i olur mu sence? Peki ya xor yerine sum kullanirsak herhangi bir drawback’i olur mu sence?

]]>
By: Arden /2011/09/27/programming-interview-questions-4-find-missing-element/#comment-210 Arden Thu, 29 Sep 2011 23:12:21 +0000 /?p=521#comment-210 Haklisin Ege okunabilirlik cok onemli tabi, ama interview'da asil amac en optimize sekilde cozmek. Hatta interviewer'in gormedigi orjinal guzel bir cozum uretirsen senden iyisi yok.. Haklisin Ege okunabilirlik cok onemli tabi, ama interview’da asil amac en optimize sekilde cozmek. Hatta interviewer’in gormedigi orjinal guzel bir cozum uretirsen senden iyisi yok..

]]>
By: ege /2011/09/27/programming-interview-questions-4-find-missing-element/#comment-205 ege Thu, 29 Sep 2011 08:18:34 +0000 /?p=521#comment-205 Arden güzel soru - güzel cevap ancak tüm elemanları toplama fikri daha sade bence kod yazarken senden sonra bakacak adamın anlayabilmesi de çok önemli bir proje için :) Arden güzel soru – güzel cevap ancak tüm elemanları toplama fikri daha sade bence
kod yazarken senden sonra bakacak adamın anlayabilmesi de çok önemli bir proje için :)

]]>
By: ahmet alp balkan /2011/09/27/programming-interview-questions-4-find-missing-element/#comment-200 ahmet alp balkan Wed, 28 Sep 2011 09:51:46 +0000 /?p=521#comment-200 Gercekten guzeldi :) Gercekten guzeldi :)

]]>