Problem Statement | |||||||||||||
Given two sequences X=(X[0], ..., X[N-1]) and Y=(Y[0], ..., Y[M-1]), their pairwise sum is the sequence: X@Y = (X[0]+Y[0], X[0]+Y[1], ..., X[0]+Y[M-1], X[1]+Y[0], X[1]+Y[1], ..., X[N-1]+Y[M-1]). For example, if X=(0,10) and Y=(0,2,1) then X@Y=(0,2,1,10,12,11). Formally, X@Y is a sequence of length NM, where for each i in {0,...,N-1} and for each j in {0,...,M-1} we have (X@Y)[i*M+j] = X[i]+Y[j]. Note that X@Y is not necessarily the same sequence as Y@X. You are given int[]s A, B, C, D, E, F, and a String[] Z. Concatenate the elements of Z to get a space-separated sequence of non-negative integers NEEDLE. Sequence HAYSTACK is defined as follows: HAYSTACK = ((((A @ B) @ C) @ D) @ E) @ F Write a method that will find and return the smallest non-negative integer X such that if we delete the first X elements of the sequence HAYSTACK, then the sequence HAYSTACK will start with the sequence NEEDLE. If there is no such X, return -1 instead. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | Each of A, B, C, D, E, and F will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | Each element in each of A, B, C, D, E, and F will be between 0 and 100,000,000, inclusive. | ||||||||||||
- | Z will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | Each element of Z will contain between 0 and 50 characters, inclusive. | ||||||||||||
- | The concatenation of the elements of Z will be a non-empty sequence of non-negative integers separated by single spaces. There will be no leading or trailing spaces, no integer will have unnecessary leading zeros, and each integer will be between 0 and 600,000,000, inclusive. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
|