Twitter也没说不能透题,就直接贴题目吧,两道题60min,都不难。Codility提供的demo做完会生成一个score report,但twitter的最后好像直接提交就完了,也没啥feedback。
. .и
Problem 1:
The first one is to detect the a number in an int array which is not paired with other numbers.
For example, [1,1,3,4,3], the function should return 4.
.google и
Problem 2:
A non-empty zero-indexed array A consisting of N integers is given.
A pair of integers (P, Q) is calledK-complementary in array A if 0 ≤ P, Q < N and A[P] + A[Q] = K.
..
For example, consider array A such that:
The following pairs are 6-complementary in array A: (0,8), (1,6), (4,8), (5,5), (6,1), (8,0), (8,4).
For instance, the pair (4,8) is 6-complementary because A[4] + A[8] = 1 + 5 = 6.. 1point3acres
Write a function:. From 1point 3acres bbs
class Solution { public int solution(int K, int[] A); }
that, given an integer K and a non-empty zero-indexed array A consisting of N integers,
returns the number of K-complementary pairs in array A.. 1point3acres
For example, given K = 6 and array A such that:. .и
Assume that:
N is an integer within the range [1..50,000];.
K is an integer within the range [−2,147,483,648..2,147,483,647];
each element of array A is an integer within the range [−2,147,483,648..2,147,483,647].-baidu 1point3acres
Complexity:
expected worst-case time complexity is O(N*log(N));
expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).