2010年12月8日 星期三

Microsoft campus interview

1.a Given an int array with size 1001, and each element is an integer from 1 to 1000. There is only one duplicate number in the array. Design a function find such number as fast as possible.
Hint: Sum

1.b How about now the array can has any number of duplicates? How do you find all number has duplicates?
Guess: I use hash table. Not sure if there is better way

2. Suppose you are a tester, you want to design 10 test cases for a function:
    int my_atoi( char*) {}
Hint: your test cases need to include at least: positive/negative, decimal, comma( like '1,000'), illegal char or space, long string for memory leaking testing, a string represents a number larger than MAX_INT

1 則留言:

  1. 1.b 這裡用hash table聽起來跟開一個陣列去記錄出現次數是一樣的意思

    回覆刪除