SailThru online test 面经


Online test, 45 minutes 2 problems at

1. Complete the function fibonacci to return an array containing the first N Fibonacci numbers.
2. Given N unique positive integers, we want to count the total pairs of numbers whose difference is K. The solution should minimize computational time complexity to the best of your ability.
Input Format:
1st line contains N and K, separated by a space
2nd line contains N integers that form the set.

Output Format:
One integer, the number of pairs of numbers that have difference K.

Sample input:
5 2
1 5 3 4 2

Sample output: