# 122.

00

122.70 121.55 122.55 122.25

A non-empty zero-indexed array A consisting of N integers is given. The first co vering prefix of array A is the smallest integer P such that 0=P<N and such that every value that occurs in array A also occurs in sequence A[0], A[1], ..., A[P ]. For example, the first covering prefix of the following 5-element array A: A[0] = 2 A[1] = 2 A[2] = 1 A[3] = 0 A[4] = 1 is 3, because sequence [ A[0], A[1], A[2], A[3] ] equal to [2, 2, 1, 0], contain s all values that occur in array A. Write a function class Solution { int solution(int[] A); } that, given a zero-indexed non-empty array A consisting of N integers, returns t he first covering prefix of A. Assume that: N is an integer within the range [1..1,000,000]; each element of array A is an integer within the range [0..N-1]. For example, given array A such that A[0] = 2 A[1] = 2 A[2] = 1 A[3] = 0 A[4] = 1 the function should return 3, as explained above. Complexity: expected worst-case time complexity is O(N); expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments). Elements of input arrays can be modified. =========================================================== Given an array A of N integers, we draw N discs in a 2D plane such that the I-th disc is centered on (0,I) and has a radius of A[I]. We say that the J-th disc a nd K-th disc intersect if J ? K and J-th and K-th discs have at least one common point. Write a function: int solution(int A[], int N); that, given an array A describing N discs as explained above, returns the number of pairs of intersecting discs. For example, given N=6 and: A[0] = 1 A[1] = 5 A[2] = 2 A[3] = 1 A[4] = 4 A[5] = 0 intersecting discs appear in eleven pairs of elements: 0 and 1, 0 and 2, 0 and 4, 1 and 2, 1 and 3, 1 and 4, 1 and 5, 2 and 3, 2 and 4, 3 and 4, 4 and 5. so the function should return 11. The function should return -1 if the number of intersecting pairs exceeds 10,000 ,000. Assume that: N is an integer within the range [0..100,000]; each element of array A is an integer within the range [0..2147483647]. Complexity:

expected worst-case space complexity is O(N). Elements of input arrays can be modified. beyond input storage (not counting the storage required for input arguments). ================================================== .expected worst-case time complexity is O(N*log(N)).