Wednesday, November 19, 2008

Mighty "Arrays" of Questions -- Part I

1. Given an array containing both positive and negative integers, find the sub-array with the largest sum. Try in O(n).

2. Given an array of size N in which every number is between 1 and N-1 and appears only once except for one that appears twice. Find the duplicate number. (Multiple solutions exist).

3. Given an array of characters which form a sentence of words, reverse the order of words in O(n).

4. Write, efficient code for extracting unique elements from a sorted list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) -> (1, 3, 5, 9).

No comments: