i ran into thos quesiton in a google search…. they look pretty common, but i couldn’t find a decent answer. any tips/links ?
1.Remove duplicates in array in O(n) without extra array
2.Write a program whose printed output is an exact copy of the source. Needless to say, merely echoing the actual source file is not allowed.
(1) isn’t possible unless the array is presorted. The basic answer is to keep two pointers into the array, one walking forward searching for unequal elements, and one trailing pointer. When the forward pointer encounters an unequal element, it copies it into the trailing pointer and increments the trailing pointer.
(2) I don’t have one handy. This sounds like a pretty terrible interview question. In most interpreted languages, a 0 byte (empty) source file is valid input, and prints out nothing.. that should count.