Core programming Questions-2

) Reverse a string. Optimize for speed. Optimize for space.
2) Reverse the words in a sentence, i.e. "I am Christina" becomes "Christina am I" Optimize for speed. Optimize for space.
3) Find a substring. Optimize for speed. Optimize for space.
4) Compare two strings using O(n) time with constant space.
5) Suppose you have an array of 1001 integers. The integers are in random order, but you know each of the integers is between 1 and 1000 (inclusive). In addition, each number appears only once in the array, except for one number, which occurs twice. Assume that you can access each element of the array only once. Describe an algorithm to find the repeated number. If you used auxiliary storage in your algorithm, can you find an algorithm that does not require it?
6) Count the number of set bits in a number. Now optimize for speed. Now optimize for size.

1 comment: